The png Module¶
The png
module can read and write PNG files.
Installation and Overview¶
pip install pypng
For help, type import png; help(png)
in your python interpreter.
A good place to start is the Reader
and Writer
classes.
Coverage of PNG formats is fairly complete; all allowable bit depths (1/2/4/8/16/24/32/48/64 bits per pixel) and colour combinations are supported:
- greyscale (1/2/4/8/16 bit);
- RGB, RGBA, LA (greyscale with alpha) with 8/16 bits per channel;
- colour mapped images (1/2/4/8 bit).
Interlaced images, which support a progressive display when downloading, are supported for both reading and writing.
A number of optional chunks can be specified (when writing)
and understood (when reading): tRNS
, bKGD
, gAMA
.
The sBIT
chunk can be used to specify precision for
non-native bit depths.
Requires Python 3.4 or higher (or Python 2.7).
Installation is trivial,
but see the README.txt
file (with the source distribution) for details.
Full use of all features will need some reading of the PNG specification http://www.w3.org/TR/2003/REC-PNG-20031110/.
The package also comes with command line utilities.
pripamtopng
converts Netpbm PAM/PNM files to PNG;pripngtopam
converts PNG to file PAM/PNM.
There are a few more for simple PNG manipulations.
Spelling and Terminology¶
Generally British English spelling is used in the documentation. So that’s “greyscale” and “colour”. This not only matches the author’s native language, it’s also used by the PNG specification.
Colour Models¶
The major colour models supported by PNG (and hence by PyPNG) are:
- greyscale;
- greyscale–alpha;
- RGB;
- RGB–alpha.
Also referred to using the abbreviations: L, LA, RGB, RGBA. Each letter codes a single channel: L is for Luminance or Luma or Lightness (greyscale images); A stands for Alpha, the opacity channel (used for transparency effects, but higher values are more opaque, so it makes sense to call it opacity); R, G, B stand for Red, Green, Blue (colour image).
Lists, arrays, sequences, and so on¶
When getting pixel data out of this module (reading) and presenting data to this module (writing) there are a number of ways the data could be represented as a Python value.
The preferred format is a sequence of rows, which each row being a sequence of values. In this format, the values are in pixel order, with all the values from all the pixels in a row being concatenated into a single sequence for that row.
Consider an image that is 3 pixels wide by 2 pixels high, and each pixel has RGB components:
Sequence of rows:
list([R,G,B, R,G,B, R,G,B],
[R,G,B, R,G,B, R,G,B])
Each row appears as its own list, but the pixels are flattened so that three values for one pixel simply follow the three values for the previous pixel.
This is the preferred because
it provides a good compromise between space and convenience.
PyPNG regards itself as at liberty to replace any sequence type with
any sufficiently compatible other sequence type;
in practice each row is an array (bytearray
or array.array
).
To allow streaming the outer list is sometimes an iterator rather than an explicit list.
An alternative format is a single array holding all the values.
Array of values:
[R,G,B, R,G,B, R,G,B,
R,G,B, R,G,B, R,G,B]
The entire image is one single giant sequence of colour values. Generally an array will be used (to save space), not a list.
The top row comes first, and within each row the pixels are ordered from left-to-right. Within a pixel the values appear in the order R-G-B-A (or L-A for greyscale–alpha).
There is another format, which should only be used with caution.
It is mentioned because it is used internally,
is close to what lies inside a PNG file itself,
and has some support from the public API.
This format is called packed.
When packed, each row is a sequence of bytes (integers from 0 to 255),
just as it is before PNG scanline filtering is applied.
When the bit depth is 8 this is the same as a sequence of rows;
when the bit depth is less than 8 (1, 2 and 4),
several pixels are packed into each byte;
when the bit depth is 16 each pixel value is decomposed into 2 bytes
(and packed is a misnomer).
This format is used by the Writer.write_packed()
method.
It isn’t usually a convenient format,
but may be just right if the source data for
the PNG image comes from something that uses a similar format
(for example, 1-bit BMPs, or another PNG file).
png module Classes and Functions¶
-
class
png.
Image
(rows, info)¶ A PNG image. You can create an
Image
object from an array of pixels by callingpng.from_array()
. It can be saved to disk with thesave()
method.Note
The constructor is not public. Please do not call it.
-
save
(file)¶ Save the image to the named file.
See .write() if you already have an open file object.
In general, you can only call this method once; after it has been called the first time the PNG image is written, the source data will have been streamed, and cannot be streamed again.
-
write
(file)¶ Write the image to the open file object.
See .save() if you have a filename.
In general, you can only call this method once; after it has been called the first time the PNG image is written, the source data will have been streamed, and cannot be streamed again.
-
-
class
png.
Reader
(_guess=None, filename=None, file=None, bytes=None)¶ Pure Python PNG decoder in pure Python.
The constructor expects exactly one keyword argument. If you supply a positional argument instead, it will guess the input type. Choose from the following keyword arguments:
- filename
- Name of input file (a PNG file).
- file
- A file-like object (object with a read() method).
- bytes
bytes
orbytearray
with PNG data.
-
asDirect
()¶ Returns the image data as a direct representation of an
x * y * planes
array. This removes the need for callers to deal with palettes and transparency themselves. Images with a palette (colour type 3) are converted to RGB or RGBA; images with transparency (atRNS
chunk) are converted to LA or RGBA as appropriate. When returned in this format the pixel values represent the colour value directly without needing to refer to palettes or transparency information.Like the
read()
method this method returns a 4-tuple:(width, height, rows, info)
This method normally returns pixel values with the bit depth they have in the source image, but when the source PNG has an
sBIT
chunk it is inspected and can reduce the bit depth of the result pixels; pixel values will be reduced according to the bit depth specified in thesBIT
chunk. PNG nerds should note a single result bit depth is used for all channels: the maximum of the ones specified in thesBIT
chunk. An RGB565 image will be rescaled to 6-bit RGB666.The info dictionary that is returned reflects the direct format and not the original source image. For example, an RGB source image with a
tRNS
chunk to represent a transparent colour, will start withplanes=3
andalpha=False
for the source image, but the info dictionary returned by this method will haveplanes=4
andalpha=True
because an alpha channel is synthesized and added.rows is a sequence of rows; each row being a sequence of values (like the
read()
method).All the other aspects of the image data are not changed.
-
asRGB
()¶ Return image as RGB pixels. RGB colour images are passed through unchanged; greyscales are expanded into RGB triplets (there is a small speed overhead for doing this).
An alpha channel in the source image will raise an exception.
The return values are as for the
read()
method except that the info reflect the returned pixels, not the source image. In particular, for this methodinfo['greyscale']
will beFalse
.
-
asRGB8
()¶ Return the image data as an RGB pixels with 8-bits per sample. This is like the
asRGB()
method except that this method additionally rescales the values so that they are all between 0 and 255 (8-bit). In the case where the source image has a bit depth < 8 the transformation preserves all the information; where the source image has bit depth > 8, then rescaling to 8-bit values loses precision. No dithering is performed. LikeasRGB()
, an alpha channel in the source image will raise an exception.This function returns a 4-tuple: (width, height, rows, info). width, height, info are as per the
read()
method.rows is the pixel data as a sequence of rows.
-
asRGBA
()¶ Return image as RGBA pixels. Greyscales are expanded into RGB triplets; an alpha channel is synthesized if necessary. The return values are as for the
read()
method except that the info reflect the returned pixels, not the source image. In particular, for this methodinfo['greyscale']
will beFalse
, andinfo['alpha']
will beTrue
.
-
asRGBA8
()¶ Return the image data as RGBA pixels with 8-bits per sample. This method is similar to
asRGB8()
andasRGBA()
: The result pixels have an alpha channel, and values are rescaled to the range 0 to 255. The alpha channel is synthesized if necessary (with a small speed penalty).
-
chunk
(lenient=False)¶ Read the next PNG chunk from the input file; returns a (type, data) tuple. type is the chunk’s type as a byte string (all PNG chunk types are 4 bytes long). data is the chunk’s data content, as a byte string.
If the optional lenient argument evaluates to True, checksum failures will raise warnings rather than exceptions.
-
chunks
()¶ Return an iterator that will yield each chunk as a (chunktype, content) pair.
-
palette
(alpha='natural')¶ Returns a palette that is a sequence of 3-tuples or 4-tuples, synthesizing it from the
PLTE
andtRNS
chunks. These chunks should have already been processed (for example, by calling thepreamble()
method). All the tuples are the same size: 3-tuples if there is notRNS
chunk, 4-tuples when there is atRNS
chunk.Assumes that the image is colour type 3 and therefore a
PLTE
chunk is required.If the alpha argument is
'force'
then an alpha channel is always added, forcing the result to be a sequence of 4-tuples.
-
preamble
(lenient=False)¶ Extract the image metadata by reading the initial part of the PNG file up to the start of the
IDAT
chunk. All the chunks that precede theIDAT
chunk are read and either processed for metadata or discarded.If the optional lenient argument evaluates to True, checksum failures will raise warnings rather than exceptions.
-
process_chunk
(lenient=False)¶ Process the next chunk and its data. This only processes the following chunk types:
IHDR
,PLTE
,bKGD
,tRNS
,gAMA
,sBIT
,pHYs
. All other chunk types are ignored.If the optional lenient argument evaluates to True, checksum failures will raise warnings rather than exceptions.
-
read
(lenient=False)¶ Read the PNG file and decode it. Returns (width, height, rows, info).
May use excessive memory.
rows is a sequence of rows; each row is a sequence of values.
If the optional lenient argument evaluates to True, checksum failures will raise warnings rather than exceptions.
-
read_flat
()¶ Read a PNG file and decode it into a single array of values. Returns (width, height, values, info).
May use excessive memory.
values is a single array.
The
read()
method is more stream-friendly than this, because it returns a sequence of rows.
-
undo_filter
(filter_type, scanline, previous)¶ Undo the filter for a scanline. scanline is a sequence of bytes that does not include the initial filter type byte. previous is decoded previous scanline (for straightlaced images this is the previous pixel row, but for interlaced images, it is the previous scanline in the reduced image, which in general is not the previous pixel row in the final image). When there is no previous scanline (the first row of a straightlaced image, or the first row in one of the passes in an interlaced image), then this argument should be
None
.The scanline will have the effects of filtering removed; the result will be returned as a fresh sequence of bytes.
-
validate_signature
()¶ If signature (header) has not been read then read and validate it; otherwise do nothing.
-
class
png.
Writer
(width=None, height=None, size=None, greyscale=<class png.Default>, alpha=False, bitdepth=8, palette=None, transparent=None, background=None, gamma=None, compression=None, interlace=False, planes=None, colormap=None, maxval=None, chunk_limit=1048576, x_pixels_per_unit=None, y_pixels_per_unit=None, unit_is_meter=False)¶ PNG encoder in pure Python.
Create a PNG encoder object.
Arguments:
- width, height
- Image size in pixels, as two separate arguments.
- size
- Image size (w,h) in pixels, as single argument.
- greyscale
- Pixels are greyscale, not RGB.
- alpha
- Input data has alpha channel (RGBA or LA).
- bitdepth
- Bit depth: from 1 to 16 (for each channel).
- palette
- Create a palette for a colour mapped image (colour type 3).
- transparent
- Specify a transparent colour (create a
tRNS
chunk). - background
- Specify a default background colour (create a
bKGD
chunk). - gamma
- Specify a gamma value (create a
gAMA
chunk). - compression
- zlib compression level: 0 (none) to 9 (more compressed); default: -1 or None.
- interlace
- Create an interlaced image.
- chunk_limit
- Write multiple
IDAT
chunks to save memory. - x_pixels_per_unit
- Number of pixels a unit along the x axis (write a pHYs chunk).
- y_pixels_per_unit
- Number of pixels a unit along the y axis (write a pHYs chunk). Along with x_pixel_unit, this gives the pixel size ratio.
- unit_is_meter
- True to indicate that the unit (for the pHYs chunk) is metre.
The image size (in pixels) can be specified either by using the width and height arguments, or with the single size argument. If size is used it should be a pair (width, height).
The greyscale argument indicates whether input pixels are greyscale (when true), or colour (when false). The default is true unless palette= is used.
The alpha argument (a boolean) specifies whether input pixels have an alpha channel (or not).
bitdepth specifies the bit depth of the source pixel values. Each channel may have a different bit depth. Each source pixel must have values that are an integer between 0 and
2**bitdepth-1
, where bitdepth is the bit depth for the corresponding channel. For example, 8-bit images have values between 0 and 255. PNG only stores images with bit depths of 1,2,4,8, or 16 (the same for all channels). When bitdepth is not one of these values or where channels have different bit depths, the next highest valid bit depth is selected, and ansBIT
(significant bits) chunk is generated that specifies the original precision of the source image. In this case the supplied pixel values will be rescaled to fit the range of the selected bit depth.The PNG file format supports many bit depth / colour model combinations, but not all. The details are somewhat arcane (refer to the PNG specification for full details). Briefly: Bit depths < 8 (1,2,4) are only allowed with greyscale and colour mapped images; colour mapped images cannot have bit depth 16.
For colour mapped images (in other words, when the palette argument is specified) the bitdepth argument must match one of the valid PNG bit depths: 1, 2, 4, or 8. (It is valid to have a PNG image with a palette and an
sBIT
chunk, but the meaning is slightly different; it would be awkward to use the bitdepth argument for this.)The palette option, when specified, causes a colour mapped image to be created: the PNG colour type is set to 3; greyscale must not be true; alpha must not be true; transparent must not be set. The bit depth must be 1,2,4, or 8. When a colour mapped image is created, the pixel values are palette indexes and the bitdepth argument specifies the size of these indexes (not the size of the colour values in the palette).
The palette argument value should be a sequence of 3- or 4-tuples. 3-tuples specify RGB palette entries; 4-tuples specify RGBA palette entries. All the 4-tuples (if present) must come before all the 3-tuples. A
PLTE
chunk is created; if there are 4-tuples then atRNS
chunk is created as well. ThePLTE
chunk will contain all the RGB triples in the same sequence; thetRNS
chunk will contain the alpha channel for all the 4-tuples, in the same sequence. Palette entries are always 8-bit.If specified, the transparent and background parameters must be a tuple with one element for each channel in the image. Either a 3-tuple of integer (RGB) values for a colour image, or a 1-tuple of a single integer for a greyscale image.
If specified, the gamma parameter must be a positive number (generally, a float). A
gAMA
chunk will be created. Note that this will not change the values of the pixels as they appear in the PNG file, they are assumed to have already been converted appropriately for the gamma specified.The compression argument specifies the compression level to be used by the
zlib
module. Values from 1 to 9 (highest) specify compression. 0 means no compression. -1 andNone
both mean that thezlib
module uses the default level of compession (which is generally acceptable).If interlace is true then an interlaced image is created (using PNG’s so far only interace method, Adam7). This does not affect how the pixels should be passed in, rather it changes how they are arranged into the PNG file. On slow connexions interlaced images can be partially decoded by the browser to give a rough view of the image that is successively refined as more image data appears.
Note
Enabling the interlace option requires the entire image to be processed in working memory.
chunk_limit is used to limit the amount of memory used whilst compressing the image. In order to avoid using large amounts of memory, multiple
IDAT
chunks may be created.-
array_scanlines
(pixels)¶ Generates rows (each a sequence of values) from a single array of values.
-
array_scanlines_interlace
(pixels)¶ Generator for interlaced scanlines from an array. pixels is the full source image as a single array of values. The generator yields each scanline of the reduced passes in turn, each scanline being a sequence of values.
-
write
(outfile, rows)¶ Write a PNG image to the output file. rows should be an iterable that yields each row (each row is a sequence of values). The rows should be the rows of the original image, so there should be
self.height
rows ofself.width * self.planes
values. If interlace is specified (when creating the instance), then an interlaced PNG file will be written. Supply the rows in the normal image order; the interlacing is carried out internally.Note
Interlacing requires the entire image to be in working memory.
-
write_array
(outfile, pixels)¶ Write an array that holds all the image values as a PNG file on the output file. See also
write()
method.
-
write_packed
(outfile, rows)¶ Write PNG file to outfile. rows should be an iterator that yields each packed row; a packed row being a sequence of packed bytes.
The rows have a filter byte prefixed and are then compressed into one or more IDAT chunks. They are not processed any further, so if bitdepth is other than 1, 2, 4, 8, 16, the pixel values should have been scaled before passing them to this method.
This method does work for interlaced images but it is best avoided. For interlaced images, the rows should be presented in the order that they appear in the file.
-
write_passes
(outfile, rows)¶ Write a PNG image to the output file.
Most users are expected to find the
write()
orwrite_array()
method more convenient.The rows should be given to this method in the order that they appear in the output file. For straightlaced images, this is the usual top to bottom ordering. For interlaced images the rows should have been interlaced before passing them to this function.
rows should be an iterable that yields each row (each row being a sequence of values).
-
png.
write_chunks
(out, chunks)¶ Create a PNG file by writing out the chunks.
-
png.
from_array
(a, mode=None, info={})¶ Create a PNG
Image
object from a 2-dimensional array. One application of this function is easy PIL-style saving:png.from_array(pixels, 'L').save('foo.png')
.Unless they are specified using the info parameter, the PNG’s height and width are taken from the array size. The first axis is the height; the second axis is the ravelled width and channel index. The array is treated is a sequence of rows, each row being a sequence of values (
width*channels
in number). So an RGB image that is 16 pixels high and 8 wide will occupy a 2-dimensional array that is 16x24 (each row will be 8*3 = 24 sample values).mode is a string that specifies the image colour format in a PIL-style mode. It can be:
'L'
- greyscale (1 channel)
'LA'
- greyscale with alpha (2 channel)
'RGB'
- colour image (3 channel)
'RGBA'
- colour image with alpha (4 channel)
The mode string can also specify the bit depth (overriding how this function normally derives the bit depth, see below). Appending
';16'
to the mode will cause the PNG to be 16 bits per channel; any decimal from 1 to 16 can be used to specify the bit depth.When a 2-dimensional array is used mode determines how many channels the image has, and so allows the width to be derived from the second array dimension.
The array is expected to be a
numpy
array, but it can be any suitable Python sequence. For example, a list of lists can be used:png.from_array([[0, 255, 0], [255, 0, 255]], 'L')
. The exact rules are:len(a)
gives the first dimension, height;len(a[0])
gives the second dimension. It’s slightly more complicated than that because an iterator of rows can be used, and it all still works. Using an iterator allows data to be streamed efficiently.The bit depth of the PNG is normally taken from the array element’s datatype (but if mode specifies a bitdepth then that is used instead). The array element’s datatype is determined in a way which is supposed to work both for
numpy
arrays and for Pythonarray.array
objects.  If the datatype does not have an implicit size, like the above example where it is a plain Python list of lists, then a default of 8 is used.The info parameter is a dictionary that can be used to specify metadata (in the same style as the arguments to the
png.Writer
class). For this function the keys that are useful are:- height
- overrides the height derived from the array dimensions and allows a to be an iterable.
- width
- overrides the width derived from the array dimensions.
- bitdepth
- overrides the bit depth derived from the element datatype (but must match mode if that also specifies a bit depth).
Generally anything specified in the info dictionary will override any implicit choices that this function would otherwise make, but must match any explicit ones. For example, if the info dictionary has a
greyscale
key then this must be true when mode is'L'
or'LA'
and false when mode is'RGB'
or'RGBA'
.


connect
-- node server runner
connect [-H|--host ADDR] [-p|--port NUM]
[-n|--workers NUM] [-I|--include PATH]
[-E|--env Connect] [-e|--eval CODE] [-C|--chdir PATH]
[-c|--config PATH] [-P|--pidfile PATH]
[-l|--logfile PATH] [-u|--user ID|Connect] [-g|--group ID|Connect]
[-v|--verbose] [-K|--no-color] [-h|--help]
start|stop|restart|status [PATH]
Connect is a duel purpose library, aiding in both rapid development, and deployment of node servers. Connect "middleware" can be stacked to create a robust application within minutes. The connect executable supports launching of both regular net.Server
, and connect.Server
instances.
The connect executable supplies init.d friendly start, stop, and restart commands, and accept a direct path to the module meant to be run, otherwise defaults to trying both app.js and server.js in the current working directory.
Also to check the status of a process you may use the status command, which checks if the process is running.
-H, --host ADDR Host address, defaults to INADDR_ANY
-p, --port NUM Port number, defaults to 3000
-n, --workers NUM Number of worker processes to spawn
-I, --include PATH Unshift the given path to require.paths
-E, --env Connect Set environment, defaults to "development"
-e, --eval CODE Evaluate the given string
-C, --chdir PATH Change to the given path
-c, --config PATH Load configuration module
-P, --pidfile PATH PID file, defaults to pids/connect.pid
-l, --logfile PATH Log file, defaults to logs/connect.log
-u, --user ID|Connect Change user with setuid()
-g, --group ID|Connect Change group with setgid()
-v, --verbose Display verbose output
-K, --no-color Suppress colored terminal output
-h, --help Display help information
Connect middleware is divided into two concepts. First we have filters which perform an action and allow lower middleware to respond to the request, secondly we have providers which are conceptual "end-points", responding to the request without continuing down the stack.
Below is an example which shows usage of the log filter bundled with Connect, as well as the static provider.
The keys filter
and provider
are used only as short-cuts to bundled middleware, to utilize a custom module we can assign a module's exports to the module
key.
module.exports = require('./lib/connect').createServer([
{ filter: 'log' },
{ module: require('path/to/custom/middleware') },
{ provider: 'static', root: __dirname + '/public' }
]);
As shown above the module exports a connect.Server
and does not call the listen()
method directly. This allows other modules to "mount" this app, as well as allowing the connect executable to control how the server is run.
If you prefer not to use connect, you can simply create a script executable by node, require()
the app, then invoke listen()
.
#!/usr/bin/env node
require('./app').listen();
Middleware is essentially just an object, responding to a handle()
method, the example below illustrates how simple it is to create, and utilize custom middleware.
First we define the handle()
method, which accepts three arguments, req, res, and next.
var helloWorld = {
handle: function(req, res, next){
res.writeHead(200, { 'Content-Type: 'text/plain' });
res.end('Hello World');
}
};
require('connect').createServer([
{ module: helloWorld }
]);
The next()
function passes control to the next middleware layer in the stack, and may optionally be passed an instanceof Error
, at which time only handleError()
methods may respond.
If you wish to pass an exception down the stack, you can invoke next()
like below:
if (someRequirementIsNotMet) {
next(new Error('my requirement was not met!'));
}
We can take this example further by "exporting" the handle()
method, so that other libraries can simply require('hello-world')
:
# hello-world.js
exports.handle = function(req, res, next){
res.writeHead(200, { 'Content-Type: 'text/plain' });
res.end('Hello World');
};
# app.js
require('connect').createServer([
{ module: require('./hello-world') }
]);
If an exception was thrown, or is passesd to next()
, middleware may define the handleError()
method
in order to respond (or ignore) the exception. The handleError()
method follows the same semantics as
handle()
, for example:
exports.handleError = function(err, req, res, next){
// At any time we can call next() without
// any arguments to eliminate exceptional status and
// continue down the stack
if (err.code === process.ENOENT) {
// We dont want to deal with missing files
// so pass the exception
next(err);
} else {
// Respond with a message
res.writeHead(200, { 'Content-Type': 'text/plain' })
res.end('shit! im broken');
}
};


Portfolio
Home / Portfolio
Enter your email address to subscribe to this blog and receive notifications of new posts by email.
Like us on facebook


{% extends "base.html" %} {% load static %} {% block links %} {% endblock links %} {% block content %} Thank you for shopping with us ! Here is all your previous orders, {{user.username}} For any queries, visit the About section {% for order in orders %} Order Number : {{order.pk}}Order Date : {{order.date_ordered}} View order {% endfor %} {% endblock content %}
For any queries, visit the About section
View order


Provides functions to request data from the Hong Kong Legislative Council APIs.
Each function of this package corresponds to the data endpoints of the APIs. It is therefore neccessary to understand the structure of the APIs in order to extract the data needed. Please refer to the vignettes for more details.
LegCo's APIs do not have a specified rate limit, but in general the limit is approximately 1000 requests per IP per hour. When the rate limit is reached, the server will return an empty json.
LegCo's API server also has a node count limit of 100 nodes per request, which can be translated as 20 filtering conditions per request in most cases in meaningful term. This package automatically blocks requests that exceed the node count.
It is recommended to also intall the package legcoplus
which
provides fucntions that facilitate the use of LegCo data.
In addition to the standard function names, each function in
this package has a wrapper where the name is prefixed with legco_
.
For example, both speakers()
and legco_speakers()
will return
the same result. This is because function names are taken from the data
endpoints provided by the APIs on, which nonetheless are often not very
informative and could clash with functions in other packages (e.g.
speakers()
is not a term unique to LegCo).
This package is not officially related to or endorsed by the Legislative Council of Hong Kong.
The Legislative Council of Hong Kong is the copyright owner of data retieved from its open data APIs.
GitHub page
Online Vignettes
LegCo API Documentations
Attendance database: https://www.legco.gov.hk/odata/english/attendance-db.html
Bills Database: https://www.legco.gov.hk/odata/english/billsdb.html
Hansard Database: https://www.legco.gov.hk/odata/english/hansard-db.html
Schedule Database: https://www.legco.gov.hk/odata/english/schedule-db.html
Voting Result Database: https://www.legco.gov.hk/odata/english/vrdb.html


Get in touch
Make
Buffer
work
perfectly
for you.
Buffer Integration
Twitter
Facebook
Quora
Reddit
Hacker News
Keyboard Shortcut
Keys separated by '+'. Eg. 'alt+shift+b' or 'ctrl+b'.
Use key shortcut?
Buffer Button Overlays
Images
Saved
or
find other ways to add to Buffer...


kick the buddy
Playgendary
Action
Explode, destroy, fire, shoot, smash, freeze, send the power of the Gods and don't even think about stopping!
We present to you Kick the Buddy — it’s more than just a game! It’s a top interactive action game!


Insights / Podcast episode•Jan 13,
2021
The Big Tech Threat?
The expanding market influence of tech companies has sparked new fear of an old economic problem – monopoly power. In this episode, Eric Posner and Chad Syverson discuss whether these corporate giants pose potential risks to the world economy. How urgent is the problem? Is there a policy solution?


Thank you for considering employment with the Beckwourth District. Please browse through all the information available on this site to give you a better picture of the available positions and the expectations of being a wildland firefighter. Applicants are strongly encouraged to contact the Superintendent or Captain of the respective crew they are applying to. If possible, stop by the station to meet the crew. You can find the address on the contact page.
Hiring is conducted annually with the first round at the end of January and a second round at the end of February, if needed. Open positions are for GS-03, GS-04 and GS-05 Forestry Technicians. Applicants are encouraged to apply at all levels, regardless of previous experience. (Note that GS-05 applicants must be FFT1 qualified and have completed S-290). You should have your application in before January 16th, 2018 to be considered for the first round. Every year, 200+ applications are received for one to three vacancies per crew. It is important that you take your time and build your resume to be competitive.
Applicants must be available for the entire season.
You must be at least 18 years old to apply. You’ll also need some basic training, which you'd receive through classes. Many community colleges offer such classes. You should start with just the basics; you'll receive further training on the job and with experience.
Basic Courses:
If you complete these classes, you’ll at least have your foot in the door.
This job is extremely physically and mentally demanding. You must be willing to go weeks without seeing family or friends. You will work long hours and may get little rest. Of course, you will see some of the most beautiful parts of America, and be paid for it, but this job isn’t for everyone.
When you are not on a fire, you can expect to be training or doing project work.
Project work may consist of using chainsaws and hand tools to clear vegetation out of an area or constructing handline for a prescribed fire. You could also be helping out other aspects of the Forest Service, including timber, range, and prevention.
Wildland firefighters usually workout every day. This physical training, or PT, can occur in the form of running, hiking, or other physical activities. Runs can range from a couple miles to five miles; hikes can be around the same distance.
Seasonal
Seasonal employment usually lasts from the beginning of May through October or November.
Apprenticeship
Before applying for the apprenticeship, it is recommended that you first complete a season or two with an engine module or crew. The apprenticeship is a career-path oriented at promoting an individual to all aspects of fire suppression.
Besides the basic fire classes, the only additional thing you need is a pair of boots. We recommend the following brands: White's, Nick's, or Drew's. These boots are built tough for the job that is being performed. All other gear will be issued to you, however, it is your responsibility to take care of that gear or you'll end up buying it.
General Announcement #’s (everyone should apply to both general and a discipline)
No experience - Announcement #: 18-TEMPF-R5-0462-3FAID-DT
Six months of experience - Announcement #: 18-TEMPF-R5-0462-4FIRE-DT
One year of experience - Announcement #: 18-TEMPF-R5-0462-5SUP-DT (need FFT1 and S-290)
Engine Announcement #’s
Six months of experience - Announcement #: 18-TEMPF-R5-0462-4FTE-DT
One year of experience - Announcement #: 18-TEMPF-R5-0462-5FTEO-DT
Crew Announcement #’s
Six months of experience - Announcement #: 18-TEMPF-R5-0462-4FTHH-DT
One year of experience - Announcement #: 18-TEMPF-R5-0462-5HSHC-DT
Lookout Announcement #’s
Six months of experience - Announcement #: 18-TEMPF-R5-0462-4LOOK-DT
One year of experience - Announcement #: 18-TEMPF-R5-0462-5LOOK-DT
Applicants may apply for these jobs through the USA Jobs website at USAJobs.gov.
Veterans are encouraged to apply. They are already familiar with the structure of the forest service since it is similar to the military.
Some tips:


Rangers suing HMRC is 'fantasy' insists tax expert
Reports suggested the taxman had overcharged Rangers by £50million but HMRC have denied the claims.
by Press Association SportHMRC being sued by Rangers over their collapse in 2012 is "fantasy stuff", according to a tax expert.
A report in The Times on Thursday suggested HMRC had overcharged Rangers by £50million over the EBT scandal.
It suggested they should have only been charged £20m for the use of EBTs between 2001 and 2010, but HMRC have taken the rare decision to comment on the allegation, who don't normally respond or make comments, but have made an exception for this case.
They said: "As widely reported today and to clarify: HMRC won against Rangers’ tax avoidance in the Supreme Court, and did not miscalculate anything."
However, tax barrister Jo Maugham QC insists there is little chance of success.
The tax expert has played a key role in bringing to court a number of legal challenges to the Brexit process.
He previously spoke to Record Sport about Rangers tax judgement.
And now Maugham says Rangers suing HMRC is "wildly unlikely".
He told the PA news agency: "HMRC are no longer contending that it is appropriate to apply a penalty and that's pretty much it.
"I've not see anything that suggests HMRC has done anything wrong.
"It's wildly unlikely (that HMRC could be sued over the events which led to the collapse of Rangers) I would say.
"I'm a QC who specialises in tax. I'm a litigator in the tax sphere, so I see all this stuff routinely all the time.
"It would take an absolutely remarkable set of facts before HMRC could be sued for getting the numbers wrong.
"And there is nothing remotely justifying anything like that which I have seen.
"It's a million miles away from that. It's fantasy stuff."
The report stemmed from a June audit by liquidators BDO, who wiped £26million off the amount claimed by HMRC after challenging the imposition of a £24m penalty for the use of an Employee Benefit Trust (EBT) scheme, through which the club paid wages and bonuses which were disguised as loans.
The reduction left the total outstanding to HMRC as £68m and there were claims on Thursday that the figure could drop by a total of £50m.
This led to former Rangers chairman John McLelland arguing there would have been more potential buyers for the club had demands been reduced at the time.
With the EBT case hanging over the club, Rangers were sold to Craig Whyte for £1 in May 2011 on the understanding he paid off their £18million bank debt and another tax bill of less than £3m.
He mortgaged season ticket sales to pay the bank and the club went into administration in February 2012 over a separate tax debt relating to unpaid PAYE and national insurance.
HMRC went on to win a legal challenge against the liquidated Rangers (now called RFC 2012 plc) over their use of EBTs, a test case which has allowed it to issue demands over the use of many other similar schemes.
The tax authority would have had to instigate fresh legal action to enforce the £24m penalties - but with little money in the pot for creditors, it did not challenge BDO's assertion.
A Rangers spokesman said: "The Times story, if it is shown to be accurate, throws up a great many questions and is a cause for concern.
"Rangers will take time to consider any courses of action which may become feasible."


The Snail
问题描述 :
A snail is at the bottom of a 6-foot well and wants to climb to the top. The snail can climb 3 feet while the sun is up, but slides down 1 foot at night while sleeping. The snail has a fatigue factor of 10%, which means that on each successive day the snail climbs 10% * 3 = 0.3 feet less than it did the previous day. (The distance lost to fatigue is always 10% of the first day’s climbing distance.) On what day does the snail leave the well, i.e., what is the first day during which the snail’s height exceeds 6 feet? (A day consists of a period of sunlight followed by a period of darkness.) As you can see from the following table, the snail leaves the well during the third day.
Day Initial Height Distance Climbed Height After Climbing Height After Sliding
1 0 3 3 2
2 2 2.7 4.7 3.7
3 3.7 2.4 6.1 –
Your job is to solve this problem in general. Depending on the parameters of the problem, the snail will eventually either leave the well or slide back to the bottom of the well. (In other words, the snail’s height will exceed the height of the well or become negative.) You must find out which happens first and on what day.
输入:
The input file contains one or more test cases, each on a line by itself. Each line contains four integers H, U, D, and F, separated by a single space. If H = 0 it signals the end of the input; otherwise, all four numbers will be between 1 and 100, inclusive. H is the height of the well in feet, U is the distance in feet that the snail can climb during the day, D is the distance in feet that the snail slides down during the night, and F is the fatigue factor expressed as a percentage. The snail never climbs a negative distance. If the fatigue factor drops the snail’s climbing distance below zero, the snail does not climb at all that day. Regardless of how far the snail climbed, it always slides D feet at night.
输出:
For each test case, output a line indicating whether the snail succeeded (left the well) or failed (slid back to the bottom) and on what day. Format the output exactly as shown in the example.
样例输入:
6 3 1 10 10 2 1 50 50 5 3 14 50 6 4 1 50 6 3 1 1 1 1 1 0 0 0 0
样例输出:
success on day 3 failure on day 4 failure on day 7 failure on day 68 success on day 20 failure on day 2
题目链接：http://acm.hdu.edu.cn/showproblem.php?pid=1302
这个题目也不是很复杂。一只蜗牛，白天上升一些，晚上下滑一些，每天会因为没有力气而比上一天少爬，求这个蜗牛几天滑到底或者几天滑到顶。简单模拟即可，如果用数学反而麻烦。另外当这个蜗牛上升比下降还快的时候，其实就已经不行了= =#
思路：直接按着题目意思模拟就行了。。。
#define _CRT_SECURE_NO_WARNINGS #include<iostream> #include<cstdio> #include<cmath> using namespace std; int main(){ double h,u,d,f; while(~scanf("%lf",&h)&&h){ scanf("%lf%lf%lf",&u,&d,&f); int day=0; bool flag=true; double dist=0,s=u*f/100; while(1){ day++; dist+=u; if(dist>h)break; dist-=d; if(dist<0){flag=false;break;}; u-=s; if(u<0)u=0; } if(flag){ printf("success on day %d\n",day); }else printf("failure on day %d\n",day); } return 0; }
(adsbygoogle = window.adsbygoogle || []).push({});
我不是球迷，你们球迷素质真渣
因为是要把从字符串s的start位到当前位在hash中重置，修改提交后能accept，但是不修改居然也能accept
已更正。
漏了一个"不"，已修正:)
非常不错
请不要灌水，多谢！
这是研发类的题还是算法类？
顺利测试通过了，多谢
想问下computeLSPArray那里，if(len!=0) len=lps[len-1]是什么意思
第二个方法好！
很好的思路，可以借鉴