Skip to content

Instantly share code, notes, and snippets.

View andergmartins's full-sized avatar

Anderson Grüdtner Martins andergmartins

View GitHub Profile
@andergmartins
andergmartins / resize.scpt
Created November 17, 2016 00:57
Resize files to multiple sizes and move to folders with the same name of the source file
set image_ext_list to {"jpg", "jpeg", "png"}
set size_list to {"64", "48", "32", "24", "16"}
set source_path to (choose folder "Select the folder with the base images" without invisbles) as text
set dest_path to (choose folder "Select the destination folder" without invisbles) as text
with timeout of 86400 seconds
tell application "Finder"
set image_files to (files of entire contents of (source_path as alias) whose name extension is in image_ext_list) as alias list
end tell
end timeout
@andergmartins
andergmartins / stringIsBoolean.js
Created April 29, 2016 03:04 — forked from deenison/stringIsBoolean.js
Gist that proposes have some fun with values (strings) that may or may not be a boolean.
/**
* Method that tests a string to check if it's value can be assumed as a (bool), regardless of being true/false.
* Note: If the string is empty, this function will return false since there's "no value" to be tested.
* @examples:
* "1".isBool() // returns true
* "yEs".isBool() // returns true
* "off".isBool() // returns true
* "".isBool() // returns false
* " ".isBool() // returns false
*
@andergmartins
andergmartins / helpscout-webhook.lua
Created April 6, 2016 19:36
LUA script to use in https://www.webscript.io to redirect webhook calls to different endpoints, according to the mailbox
-- Mirror the request to multiple endpoints
-- Used to propagate HelpScout webhooks
if request.method == 'POST' then
-- List here the url for each Mailbox's webhook listener
local urlMailbox = {
Mailbox1 = 'https://www.endpoin1.test/endpoint',
Mailbox2 = 'https://www.endpoin2.test/endpoint',
}
@andergmartins
andergmartins / docker-virtual-host
Created March 29, 2016 14:13
How to use nginx as proxy to set virtual hosts for docker containers
# From: http://stackoverflow.com/questions/18497564/assigning-vhosts-to-docker-ports
# start the reverse proxy
docker run -d -p 80:80 -v /var/run/docker.sock:/tmp/docker.sock jwilder/nginx-proxy
# start a first container for http://tutum.test.local
docker run -d -e "VIRTUAL_HOST=tutum.test.local" tutum/hello-world
# start a second container for http://deis.test.local
docker run -d -e "VIRTUAL_HOST=deis.test.local" deis/helloworld
@andergmartins
andergmartins / docker-virtual-host
Created March 29, 2016 14:13
How to use nginx as proxy to set virtual hosts for docker containers
# From: http://stackoverflow.com/questions/18497564/assigning-vhosts-to-docker-ports
# start the reverse proxy
docker run -d -p 80:80 -v /var/run/docker.sock:/tmp/docker.sock jwilder/nginx-proxy
# start a first container for http://tutum.test.local
docker run -d -e "VIRTUAL_HOST=tutum.test.local" tutum/hello-world
# start a second container for http://deis.test.local
docker run -d -e "VIRTUAL_HOST=deis.test.local" deis/helloworld
@andergmartins
andergmartins / blockips.conf
Last active March 15, 2016 13:32
Nginx list of bad IPs - Blockips
deny 178.238.234.1;
deny 76.90.254.19;
deny 85.17.26.68; # spammy comments - Leaseweb
deny 85.17.230.23; # spammy comments - Leaseweb
deny 173.234.11.105; # junk referrers
deny 173.234.31.9; # junk referrers - Ubiquityservers
deny 173.234.38.25; # spammy comments
deny 173.234.153.30; # junk referrers
deny 173.234.153.106; # spammy comments - Ubiquityservers
deny 173.234.175.68; # spammy comments
@andergmartins
andergmartins / plugin.js
Last active March 2, 2016 00:29
Wistia Player Custom Plugin
/**
* @package MyPlugin
* @license http://www.gnu.org/licenses/gpl.html GNU/GPL
*/
/* global Wistia */
Wistia.plugin('myplugin', function(video) {
// Wait for the video element to be fully loaded
interval = setInterval(function() {
// Your magic goes here
@andergmartins
andergmartins / json-debug
Created March 25, 2015 19:03
JSON debug
$json_errors = array(
JSON_ERROR_NONE => 'No error has occurred',
JSON_ERROR_DEPTH => 'The maximum stack depth has been exceeded',
JSON_ERROR_STATE_MISMATCH => 'Invalid or malformed JSON',
JSON_ERROR_CTRL_CHAR => 'Control character error, possibly incorrectly encoded',
JSON_ERROR_SYNTAX => 'Syntax error',
JSON_ERROR_UTF8 => 'Malformed UTF-8 characters, possibly incorrectly encoded (PHP 5.3.3)',
JSON_ERROR_RECURSION => 'One or more recursive references in the value to be encoded (PHP 5.5.0)',
JSON_ERROR_INF_OR_NAN => 'One or more NAN or INF values in the value to be encoded (PHP 5.5.0)',
JSON_ERROR_UNSUPPORTED_TYPE => 'A value of a type that cannot be encoded was given (PHP 5.5.0)'
@andergmartins
andergmartins / extract-string.sql
Created January 8, 2015 15:11
Extract data from JSON string inside a MySQL field. In this case, extract metadesc and page title from the menu params
SELECT m.id, m.title,
@tmp_search := '"menu-meta_description":"' AS tmp_search,
@tmp_search_len := LENGTH(@tmp_search) AS tmp_search_len,
@start := LOCATE(@tmp_search, m.params) AS tmp_start,
@end := LOCATE('"', m.params, @start + @tmp_search_len) AS tmp_end,
SUBSTRING(m.params, @start + @tmp_search_len, @end - @start - @tmp_search_len) AS metadesc,
@tmp_search := '"page_title":"' AS tmp_search,
@tmp_search_len := LENGTH(@tmp_search) AS tmp_search_len,
@start := LOCATE(@tmp_search, m.params) AS tmp_start,
@andergmartins
andergmartins / update-site.sh
Created September 30, 2014 23:20
Code to synchronize your copy of a site
#!/bin/sh
################################################################################
# DEFAULT VARIABLES
################################################################################
LOCAL_PATH=/var/www
LOCAL_DOMAIN=mylocaltest.dev
LOCAL_DB_NAME=myuser
LOCAL_DB_USER=root
LOCAL_DB_PASSWORD=myrootpassword