Skip to content

Instantly share code, notes, and snippets.

@goliatone
goliatone / README.md
Created November 21, 2013 19:12 — forked from dergachev/README.md

Vagrant Setup

This tutorial guides you through creating your first Vagrant project.

We start with a generic Ubuntu VM, and use the Chef provisioning tool to:

  • install packages for vim, git
  • create user accounts, as specified in included JSON config files
  • install specified user dotfiles (.bashrc, .vimrc, etc) from a git repository

Afterwards, we'll see how easy it is to package our newly provisioned VM

@goliatone
goliatone / keyhandler.js
Created November 22, 2013 04:09
keydown wrapper
(function($) {
$.fn.enterKey = function(key, handler) {
return this.keydown(function(ev) {
if (ev.which == key)
return handler.call(this, ev);
});
};
})(jQuery);
$('#test').enterKey(13, function(ev) {
# Global registry for instance registration
resource_registry = {}
def provides(name):
"""Class decorator for an instance provider.
The name passed in is what the attribute is called.
The instance will be auto registered in the registry
with the value of the handle
TODO : the name could also be a function which could return the
attribute name to extract the instance name from
def get_class( kls ):
parts = kls.split('.')
module = ".".join(parts[:-1])
m = __import__( module )
for comp in parts[1:]:
m = getattr(m, comp)
return m
D = get_class("datetime.datetime")
@goliatone
goliatone / uuid.js
Created December 15, 2013 21:01
make UUID
function makeUUID(){
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx"
.replace(/[xy]/g,function(a,b){r eturn b = Math.random()*16, (a=="y"? b&3|8: b|0).toString(16)});
}
@goliatone
goliatone / fm.php
Created December 17, 2013 03:01 — forked from eric1234/fm.php
<?php
/*** A stupid simple PHP-based file manager ***/
// Were to put the files. Assume the "fm" directory where this script
// Is located but you can change it to anything you want.
$storage_dir = implode(DIRECTORY_SEPARATOR, array(dirname(__FILE__), 'fm'));
// Set to the name of the file that is the header and footer of the HTML
$header = null;
$footer = null;
/*! ******************************
Handlebars helpers
*******************************/
define([
"use!underscore",
"use!handlebars",
"moment"
],
function(
@goliatone
goliatone / stringinterpolation.php
Last active January 1, 2016 13:49
PHP string interpolation.
<?php
class Message
{
/**
* @param string $message String template
* @param array $context Context providing vars
* @param bool $consume If true, missing matches will be
* removed, else they are left.
* @return string
@goliatone
goliatone / gfonts_download.sh
Last active January 1, 2016 13:59
Download google fonts
#!/bin/sh
for family in $*; do
for url in $( {
for agent in \
'Mozilla/5.0 (X11; Linux i686; rv:6.0) Gecko/20100101 Firefox/6.0' \
'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_8; de-at) AppleWebKit/533.21.1 (KHTML, like Gecko) Version/5.0.5 Safari/533.21.1' \
'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 7.1; Trident/5.0)' ;
do
curl -A "$agent" -s "http://fonts.googleapis.com/css?family=$family" | \
<?php
class Benchmark {
/**
* Creates a loop that lasts for $allowed_time and logs how many
* times a function was able to run
*
* @param string $name the name of the test
* @param function $test the function to run