Skip to content

Instantly share code, notes, and snippets.

@lyoshenka
lyoshenka / router.php
Created February 22, 2014 20:24 — forked from michalpipa/router.php
Router script to make Symfony2 work with the PHP built-in server
<?php
if (isset($_SERVER['SCRIPT_FILENAME'])) {
return false;
} else {
$_SERVER['SCRIPT_FILENAME'] = $_SERVER['DOCUMENT_ROOT']
. DIRECTORY_SEPARATOR
. 'app.php'
;
@lyoshenka
lyoshenka / autosubmit.js
Created February 28, 2014 21:51
How to autosave a form field as it's being edited. This will fire the ajax request 400ms after the person stops typing.
// inspired by http://stackoverflow.com/questions/2006870/submit-form-with-delay-while-entering-data-into-input-field
/*
var timerid;
jQuery("#searchForm").keyup(function() {
var form = this;
clearTimeout(timerid);
timerid = setTimeout(function() { form.submit(); }, 500);
});
*/
@lyoshenka
lyoshenka / chef-solo.sh
Created March 23, 2014 18:26
Chef Solo bootstrap. Quickly set up chef solo (and liquidprompt) on a new machine
#!/usr/bin/env bash
sudo apt-get update
sudo apt-get install git-core curl
git clone https://github.com/nojhan/liquidprompt.git
source ~/liquidprompt/liquidprompt
echo 'source ~/liquidprompt/liquidprompt' >> ~/.bashrc
\curl -sSL https://get.rvm.io | bash -s stable --ruby
source /usr/local/rvm/scripts/rvm
sudo apt-get install libxslt-dev libxml2-dev
@lyoshenka
lyoshenka / disk_space.sh
Created March 24, 2014 13:37
Send yourself an email when your root disk fills up
#!/bin/bash
disk_space=`df -h | grep -oP "[0-9]+(?=% /$)"`
[[ "$disk_space" -ge 90 ]] && { echo "Root disk is $disk_space% full" | mail [email protected] -s "SERVERNAME Root Disk $disk_space% full" ; }
<?php
function append_error_handler($handler) {
set_error_handlers(array(set_error_handler($handler), $handler));
}
function prepend_error_handler($handler) {
set_error_handlers(array($handler, set_error_handler($handler)));
}
#!/usr/bin/env python2
# Quick and dirty demonstration of CVE-2014-0160 by Jared Stafford ([email protected])
# The author disclaims copyright to this source code.
import sys
import struct
import socket
import time
import select
@lyoshenka
lyoshenka / print-table-ascii.php
Last active August 29, 2015 13:58
Print data from an array as an ASCII table. Pad all the data so it lines up nicely. WARNING: assumes that each datum (table row) has the same exact keys.
<?php
function printTable($data, $columnNames = [])
{
if (!$data || !is_array($data))
{
return;
}
$columns = getColumnsAndMaxLengths($columnNames ? array_merge($data, [$columnNames]) : $data);

Keybase proof

I hereby claim:

  • I am lyoshenka on github.
  • I am lyoshenka (https://keybase.io/lyoshenka) on keybase.
  • I have a public key whose fingerprint is DC91 BD1E 06C4 01D7 AA36 8ADF E78F F016 2B0D 303D

To claim this, I am signing this object:

@lyoshenka
lyoshenka / .gitconfig
Last active August 29, 2015 13:59
my current git config
[user]
name = Alex Grintsvayg
email = [email protected]
[color]
diff = auto
status = auto
branch = auto
ui = auto
[core]
autocrlf = input
#!/usr/bin/env bash
if [ $EUID -ne 0 ]; then
echo "You must be root: \"sudo ngxvhost\""
exit 1
fi
# May need to run this as sudo!
# I have it in /usr/local/bin and run command 'ngxvhost' from anywhere, using sudo.