Skip to content

Instantly share code, notes, and snippets.

View avioli's full-sized avatar

Evo Stamatov avioli

View GitHub Profile
// A Handlebars hepler that saves processes the content and saves it into a local variable - capturedBody.
(function(undefined) {
module.exports.register = function(Handlebars, options) {
Handlebars.registerHelper('captureBody', function(opts) {
this.capturedBody = opts.fn(this)
return ''
})
@avioli
avioli / more.md
Created May 2, 2012 00:08 — forked from vasilisvg/more.md
This is my backup script which syncs my server to my dropbox every day.

The script below is triggered every day from my Mac. I use Hazel to move the tar.gz to an external hard disk once it's finished. This happens every day without me noticing.

You should have a similar script.

@avioli
avioli / error-reporting.php
Created October 9, 2015 01:04
A simple wrapper for wp_mail() to send errors if an error email is defined
<?php
function are_email_errors_enabled() {
return (defined('EMAIL_ERRORS_TO_EMAIL') && false !== EMAIL_ERRORS_TO_EMAIL && 0 !== EMAIL_ERRORS_TO_EMAIL);
}
function wp_mail_error($subject, $message, $headers = '', $attachments = array()) {
if (! are_email_errors_enabled()) {
return;
}
@avioli
avioli / valid-html5-markup.html
Created October 11, 2012 23:09
Valid HTML5 markup
<!DOCTYPE html>
<title>Saving money, saving bytes</title>
<meta charset="utf-8">
<table>
<thead>
<tr>
<th scope="col">Income
<th scope="col">Taxes
<tbody>
<tr>
@avioli
avioli / mkvtoolnix-10.8.2.txt
Created December 7, 2012 10:46
brew install -vd mkvtoolnix # on OS X 10.8.2
$ brew install -vd mkvtoolnix
/usr/local/bin/brew: loading /usr/local/Library/Formula/mkvtoolnix.rb
/usr/local/bin/brew: loading /usr/local/Library/Formula/boost149.rb
/usr/local/bin/brew: loading /usr/local/Library/Formula/libvorbis.rb
/usr/local/bin/brew: loading /usr/local/Library/Formula/xz.rb
/usr/local/bin/brew: loading /usr/local/Library/Formula/pkg-config.rb
/usr/local/bin/brew: loading /usr/local/Library/Formula/libogg.rb
/usr/local/bin/brew: loading /usr/local/Library/Formula/libmatroska.rb
/usr/local/bin/brew: loading /usr/local/Library/Formula/libebml.rb
/usr/local/bin/brew: loading /usr/local/Library/Formula/flac.rb
tmp=${TMPDIR:-/tmp}/xx.$$ # Consider mktemp or something
trap "rm -f $tmp.1; exit 1" 0 1 2 3 13 15 # Exit, HUP, INT, QUIT, PIPE, TERM
tee $tmp.1 |
while read -a linA
do
...
done
...reprocess $tmp.1 here...
@avioli
avioli / rotate_logs.sh
Created October 18, 2015 23:54
Rotate logs in pure bash
# Meant for Mac OS X env
# Requires $LOG_FILE to point to the log file in question
# [ -z "$LOG_NAME" ] && LOG_NAME=`basename $0`
# TMPDIR=${TMPDIR:-/tmp}
# [ -z "$LOG_PATH" ] && LOG_PATH=$TMPDIR
# [ -z "$LOG_FILE" ] && LOG_FILE="$LOG_PATH/$LOG_NAME.log"
# Set rotate log size
[ -z "$LOG_ROT_SIZE" ] && LOG_ROT_SIZE=5000000
@avioli
avioli / autolayout_trace
Created March 26, 2013 15:45
A debugger trace command for XCode's Auto Layout
po [[UIWindow keyWindow] _autolayoutTrace]
avioli:chef-repo(master) $ knife bootstrap localhost --ssh-user vagrant --ssh-password vagrant --ssh-port 2222 --run-list "recipe[apt],recipe[aliases],recipe[apache2],recipe[networking_basic]" --sudo
Bootstrapping Chef on localhost
localhost Starting Chef Client, version 11.4.4
localhost resolving cookbooks for run list: ["apt", "aliases", "apache2", "networking_basic"]
localhost Synchronizing Cookbooks:
localhost - networking_basic
localhost - apt
localhost - aliases
localhost - apache2
localhost - magic_shell
@avioli
avioli / plot-a-dot-on-map.m
Created September 12, 2013 00:21
When you've got a CLLocationCoordinate2D coordinate and want to plot a dot on a image of a map that you know its NW and SE coordinates. In my case the image is 100x100px.
CLLocationCoordinate2D sightingLocation = CLLocationCoordinate2DMake([self.sighting.locationLat floatValue], [self.sighting.locationLng floatValue]);
// Australia's map coordinates
CLLocationCoordinate2D nw, se;
nw = CLLocationCoordinate2DMake(-7.410849283839832, 112.41210912499992);
se = CLLocationCoordinate2DMake(-44.248667520681586, 154.07226537499992);
MKMapPoint topLeftPoint = MKMapPointForCoordinate(nw);
MKMapPoint bottomRightPoint = MKMapPointForCoordinate(se);
MKMapRect mapRect = MKMapRectMake(topLeftPoint.x, topLeftPoint.y, bottomRightPoint.x - topLeftPoint.x, bottomRightPoint.y - topLeftPoint.y);