Skip to content

Instantly share code, notes, and snippets.

View slav123's full-sized avatar

Slawomir Jasinski slav123

View GitHub Profile
@slav123
slav123 / policy.json
Created August 31, 2017 06:38
S3 public read bucket policy
{
"Version": "2008-10-17",
"Statement": [
{
"Sid": "PublicReadGetObject",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": "s3:GetObject",
@slav123
slav123 / caddyfile
Created September 2, 2017 06:10
caddy expire headers for css
expires {
match .css$ 1d # expires
match .js$ 1d # expires
match .png$ 7d # expires
match .jpg$ 7d #expires # expires
match .webp$ 7d
}
go run build.go -goos=linux -goarch=amd64
@slav123
slav123 / picture.html
Last active May 30, 2018 07:56
webp picture
<picture>
<source srcset="bourbon@2x 2x" media="(max-width: 768px)">
<source srcset="bourbon.webp" type="image/webp"/>
<img src="bourbon.png" alt="logo" width="223" height="78">
</picture>
@slav123
slav123 / .htaccess
Last active October 13, 2017 12:52
htaccess optimization
AddType image/webp .webp
## expires
<IfModule mod_expires.c>
# Turn on the module.
ExpiresActive on
# Set the default expiry times.
ExpiresDefault "access plus 2 days"
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/gif "access plus 1 month"
@slav123
slav123 / cert.sh
Created September 29, 2017 07:49
lets's encrypt AMI Linux
yum install python26-pip
pip install virtualenv
wget https://dl.eff.org/certbot-auto
chmod a+x certbot-auto
/usr/local/bin//certbot-auto --debug -v --server https://acme-v01.api.letsencrypt.org/directory certonly -d poppin.com.au -d www.poppin.com.au
repoquery --list repo-name
@slav123
slav123 / get_jpeg_size.c
Created December 13, 2017 07:34
Decoding Function C++ source code in 31 lines
//Gets the JPEG size from the array of data passed to the function, file reference: http://www.obrador.com/essentialjpeg/headerinfo.htm
static char get_jpeg_size(unsigned char* data, unsigned int data_size, unsigned short *width, unsigned short *height) {
//Check for valid JPEG image
int i=0; // Keeps track of the position within the file
if(data[i] == 0xFF && data[i+1] == 0xD8 && data[i+2] == 0xFF && data[i+3] == 0xE0) {
i += 4;
// Check for valid JPEG header (null terminated JFIF)
if(data[i+2] == 'J' && data[i+3] == 'F' && data[i+4] == 'I' && data[i+5] == 'F' && data[i+6] == 0x00) {
//Retrieve the block length of the first block since the first block will not contain the size of file
unsigned short block_length = data[i] * 256 + data[i+1];
@slav123
slav123 / jpegDimensions.go
Created December 13, 2017 07:36
Gets the JPEG size from the array of data passed to the function
func jpegDimensions(data []byte) (int32, int32) {
var width, height, i int
data_size := cap(data)
if data[i] == 0xFF && data[i+1] == 0xD8 && data[i+2] == 0xFF && data[i+3] == 0xE0 {
i += 4
if data[i+2] == 'J' && data[i+3] == 'F' && data[i+4] == 'I' && data[i+5] == 'F' && data[i+6] == 0x00 {
block_length := int(data[i])*256 + int(data[i+1])
for i < data_size {
@slav123
slav123 / readcloser.go
Created December 15, 2017 09:06
read again from io.reader
// Read the content
var bodyBytes []byte
if c.Request.Body != nil {
bodyBytes, _ = ioutil.ReadAll(c.Request.Body)
}
// Restore the io.ReadCloser to its original state
c.Request.Body = ioutil.NopCloser(bytes.NewBuffer(bodyBytes))
// Use the content