Skip to content

Instantly share code, notes, and snippets.

@krusynth
krusynth / site.py
Created October 13, 2012 22:06
Builds site directory, database, db user, virtualhost file, and /etc/hosts entry
#!/usr/bin/python
# Base config
basedir = '/Users/YOURUSERNAME/'
user = 'YOURUSERNAME'
# Setup User
import pwd
@krusynth
krusynth / .inputrc
Created November 20, 2012 14:08
Readline hacks
set input-meta on
set output-meta on
set convert-meta off
set completion-query-items 10000
set completion-ignore-case On
# these allow you to use shift+left/right arrow keys
# to jump the cursor over words
"\e[1;2C": forward-word
@krusynth
krusynth / hostname.conf
Created December 6, 2012 21:20
Apache log format that shows the hostname
LogFormat "%h %l %u %t \"%m http://%{Host}i%U %H\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" hostnames
CustomLog "/private/var/log/apache2/access_log" hostnames
@krusynth
krusynth / grid.py
Created December 12, 2012 22:43
Make custom fluid CSS grids based on whatever madness you want.
from decimal import *
getcontext().prec = 6
cols = Decimal(24)
col_size = Decimal(6) # columns should be this many units
gutter = Decimal(1) # with a 1 unit gutter on either side
total_width = Decimal(100)
units = '%'
@krusynth
krusynth / ModelHelper.php
Created April 26, 2013 01:59
Fix for Laravel 3 Administrator when using database table prefixes
<?php
namespace Admin\Libraries;
use \Config;
use \DateTime;
use \DB;
use \Exception;
use Admin\Libraries\Fields\Field;
class ModelHelper {
@krusynth
krusynth / friday.js
Last active December 16, 2015 17:00
function friday(e) {
if(e) {
// Not doin' nothin', it's Friday.
e.preventDefault();
}
/************$~I**************************Z*********************************
***********O,7.++O$+********************O,..ZI******************************
***********$..$.78.$******************$...7+. ~Z*******************+********
***********.Z.~.7D.O****************O,...,+. ....+Z*************7O+77I*+****
@krusynth
krusynth / handlebars_comparison.js
Created April 28, 2013 15:17
Handlerbars.js doesn't have proper comparison operators. Also, accessing array indexes is weird.
In your init:
/* Handlebars doesn't have the basics. */
Handlebars.registerHelper('ifEq', function(v1, v2, options) {
if(v1 == v2) {
return options.fn(this);
}
return options.inverse(this);
});
@krusynth
krusynth / merge_kvstore.psql
Created July 23, 2013 12:50
Function to emulate ON DUPLICATE KEY UPDATE functionality in Postgresql
CREATE FUNCTION merge_kvstore(dkey character varying, ddata BYTEA) RETURNS VOID AS
$$
BEGIN
LOOP
-- first try to update the key
UPDATE kvstore SET value = ddata WHERE key = dkey;
IF found THEN
RETURN;
END IF;
-- not there, so try to insert the key
@krusynth
krusynth / functions.php
Created September 4, 2013 14:53
Wordpress theme addition to add the page's slug, and the page's oldest ancestor's slug to the body class. Very useful for hierarchies.
function get_top_level_page() {
global $top_level_page;
global $post;
// Get global page heading
if( is_page() && !$top_level_page) {
/* Get an array of Ancestors and Parents if they exist */
$parents = get_post_ancestors( $post->ID );
/* Get the top Level page->ID count base 1, array base 0 so -1 */
if($parents) {
$id = $parents[count($parents)-1];
@krusynth
krusynth / simpleXML_to_object.php
Created September 6, 2013 13:33
Translates a simpleXML object into a standard PHP object.
<?php
/*
* Translate a non-standard object into an associative array object.
* Super-useful for dealing with simplexml objects.
*/
function simpleXML_to_object($obj)
{
$data = new StdClass();
if(
(is_object($obj) && get_class($obj) == 'SimpleXMLElement')