Skip to content

Instantly share code, notes, and snippets.

View kvz's full-sized avatar

Kevin van Zonneveld kvz

View GitHub Profile
#!/usr/bin/env bash
#
# A Git pre-commit hook that checks for syntax errors
# for: Ruby, JavaScript, Python, Bash, and (Cake)PHP
# based on the extensions of staged files in Git.
# Can be 'installed globally' as of Git 1.7.1 using init.templatedir
#
# Copyright 2013, kvz (http://twitter.com/kvz)
#
# Some common caveats have been taken care of:
ubuntu@beth:/tmp$ time dig @4.2.2.2 +time=3 +tries=1 +short tmp.transloadit.com.s3.amazonaws.com
s3-1-w.amazonaws.com.
205.251.243.73
real 0m0.079s
user 0m0.004s
sys 0m0.000s
ubuntu@beth:/tmp$ time dig @8.8.8.8 +time=3 +tries=1 +short tmp.transloadit.com.s3.amazonaws.com
;; connection timed out; no servers could be reached
@kvz
kvz / elasticsearch.init.erb
Last active December 22, 2015 00:19
Please god no chef
# Executing ruby in a template in ruby
version=$(curl -s 'http://localhost:9200' | ruby -rubygems -e 'require "json"; print JSON.parse(STDIN.read)["version"]["number"]')
echo -e "\033[1;37;46melasticsearch $version running with PID $pid\033[0m"
<?php
// In PHP 5.4 you can pass JSON_UNESCAPED_UNICODE and JSON_UNESCAPED_SLASHES to json_encode:
$input = array('file' => '/\intro_cropsic – .m4v');
$paramsString = json_encode($input, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
// And that will encode arrays with unicode characters more compatible with JavaScript.
// (e.g. it will produce the same sha1 if you phpjs.utf8_encode paramString in JavaScript )
// On PHP 5.3 and lower, you may want to try
function json_encode_noescape_slashes_unicode ($arr) {
@kvz
kvz / exponential_backoff.php
Last active December 20, 2015 06:58
Tries your function several times with a bigger & bigger interval, until it does not throw an exception. Useful if you want to gracefully handle external services not being available, without actually building retries into your code. Works via Hollywood principle: Don't call us, we'll call you.
<?php
Class SomeClass() {
public function retry ($cb, $intervals = array(2, 4, 8, 16)) {
while ($intervals) {
if (!is_a($results = $cb(), 'Exception')) {
// good results, return them
return $results;
}
// failed, sleep for a larger & larger interval
$backoff = array_shift($intervals);
@kvz
kvz / cake-2.x-nginx-vhost
Last active December 16, 2015 21:49
First swing at public cake 2.0 nginx vhost. please improve
# Be sure to checkout the official docs for a smaller example
# http://book.cakephp.org/2.0/en/installation/url-rewriting.html#pretty-urls-on-nginx
http {
# With this trick, you can pass per-environment variables and
# PHP settings to FastCGI depending on the host header value.
map $http_host $environment {
example.local development;
example.com production;
@kvz
kvz / compile-galore.sh
Last active December 14, 2015 20:09
What we need to compile to have decent encoding over at Transloadit
$ ls deps/packets |sed 's#\.sh##g'
aws
curl
exiftool
ffmpeg
ghostscript
go_cmds
gpac
haproxy
imagemagick
@kvz
kvz / gist:4110519
Created November 19, 2012 13:01
meta
# exiftool api2/test/fixture/file* \
> |awk -F: '{print $1}' \
> |sed 's/ *$//g' \
> |grep -v === \
> |sort -u \
> |tr [A-Z' '\'\&\(\)] [a-z_____] > /tmp/meta.txt
# cat /tmp/meta.txt
about
add_original_decision_data
@kvz
kvz / gist:3889202
Created October 14, 2012 17:08 — forked from DanielNill/gist:3824266
composer example
{
"name": "My-New-Project",
"require-prod": {
"doctrine/orm": "2.2.1"
},
"require-dev": {
"doctrine/orm": "2.*"
},
"require":{
@kvz
kvz / navbar.less
Created March 13, 2012 16:17
First few lines from navbar.less from Twitter Bootstrap http://twitter.github.com/bootstrap/
.navbar {
// Fix for IE7's bad z-indexing so dropdowns don't appear below content that follows the navbar
*position: relative;
*z-index: 2;
overflow: visible;
margin-bottom: @baseLineHeight;
}
// Gradient is applied to it's own element because overflow visible is not honored by IE when filter is present