Skip to content

Instantly share code, notes, and snippets.

View gabrielef's full-sized avatar

Gabriele Formenti gabrielef

  • Cutowl Srl
  • Milan, Italy
View GitHub Profile
@mzaradzki
mzaradzki / docSearcher_snippet1.js
Created May 29, 2017 16:16
AWS Lambda function to class Cloud Search API with javascript SDK
exports.handler = (event, context, callback) => {
var csd = new AWS.CloudSearchDomain({
endpoint: CS_NAME+'.'+SERVICES_REGION+'.cloudsearch.amazonaws.com',
apiVersion: '2013-01-01'
});
var params = {
query: event.query,
sort: '_score desc',
@alanwill
alanwill / api-gateway-mapping-template.json
Created April 3, 2016 06:34
AWS API Gateway Mapping Template
{
"body" : $input.json('$'),
"headers": {
#foreach($header in $input.params().header.keySet())
"$header": "$util.escapeJavaScript($input.params().header.get($header))" #if($foreach.hasNext),#end
#end
},
"method": "$context.httpMethod",
"params": {
@joseluisq
joseluisq / terminal-git-branch-name.md
Last active November 4, 2024 04:14
Add Git Branch Name to Terminal Prompt (Linux/Mac)

Add Git Branch Name to Terminal Prompt (Linux/Mac)

image

Open ~/.bash_profile in your favorite editor and add the following content to the bottom.

# Git branch in prompt.

parse_git_branch() {
anonymous
anonymous / config.json
Created March 12, 2015 15:13
Bootstrap Customizer Config
{
"vars": {
"@gray-base": "#363b42",
"@gray-darker": "lighten(@gray-base, 13.5%)",
"@gray-dark": "lighten(@gray-base, 19.4%)",
"@gray": "lighten(@gray-base, 33.5%)",
"@gray-light": "lighten(@gray-base, 40%)",
"@gray-lighter": "lighten(@gray-base, 69.9%)",
"@brand-primary": "#359ce8",
"@brand-success": "#00aeef",
@zburgermeiszter
zburgermeiszter / Base64.php
Last active August 9, 2022 19:04
TWIG Base64 extension for Symfony
<?php
namespace Vendor\Bundle\Twig;
/*
services.yml:
twig.base64:
class: Vendor\Bundle\Twig\Base64
tags :
- { name: twig.extension }
@madhums
madhums / base64-image-upload.js
Created September 14, 2014 17:37
save base64 encoded image
/*
* Taken from http://stackoverflow.com/questions/5867534/how-to-save-canvas-data-to-file/5971674#5971674
*/
var fs = require('fs');
// string generated by canvas.toDataURL()
var img = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0"
+ "NAAAAKElEQVQ4jWNgYGD4Twzu6FhFFGYYNXDUwGFpIAk2E4dHDRw1cDgaCAASFOffhEIO"
+ "3gAAAABJRU5ErkJggg==";
// strip off the data: url prefix to get just the base64-encoded bytes
@kelvinn
kelvinn / cmd.sh
Created July 24, 2014 02:55
Example of using Apache Bench (ab) to POST JSON to an API
# post_loc.txt contains the json you want to post
# -p means to POST it
# -H adds an Auth header (could be Basic or Token)
# -T sets the Content-Type
# -c is concurrent clients
# -n is the number of requests to run in the test
ab -p post_loc.txt -T application/json -H 'Authorization: Token abcd1234' -c 10 -n 2000 http://example.com/api/v1/locations/
@thewinterwind
thewinterwind / gzip-ajax-response.php
Last active July 26, 2019 09:50
How to gzip AJAX response with PHP (Laravel 4 flavor)
<?php
public function all()
{
if (Request::ajax()) {
$encoded_html = gzencode(Model::all(), 9);
header('Content-Length: ' . strlen($encoded_html));
header('Content-Encoding: gzip');
return $encoded_html;
}
@rojan
rojan / node_crypto.js
Last active March 19, 2023 15:14
Encrypt in nodejs and decrypt in php or vice versa
var crypto = require('crypto');
var key = 'MySecretKey12345';
var iv = '1234567890123456';
var cipher = crypto.createCipheriv('aes-128-cbc', key, iv);
var decipher = crypto.createDecipheriv('aes-128-cbc', key, iv);
var text = 'plain text';
var encrypted = cipher.update(text, 'utf8', 'binary');
encrypted += cipher.final('binary');
hexVal = new Buffer(encrypted, 'binary');
@JCotton1123
JCotton1123 / parse-slow-log.sh
Last active August 24, 2024 06:55
Parse php-fpm slow log
## Slow requests grouped by function call
cat /var/log/php-fpm/www-slow.log | grep -A 1 script_filename | \
grep -v script_filename | grep -v -e "--" | cut -c 22- | sort | uniq -c | sort -nr
## Slow requests grouped by minute
cat /var/log/php-fpm/www-slow.log | grep 'pool www' | \
cut -d' ' -f2 | sort | cut -d: -f1,2 | uniq -c
## Top 25 1 minute groups of slow requests
cat /var/log/php-fpm/www-slow.log | grep 'pool www' | cut -d' ' -f2 | \