Skip to content

Instantly share code, notes, and snippets.

View richthegeek's full-sized avatar

Richard Lyon richthegeek

View GitHub Profile
@richthegeek
richthegeek / debug.coffee
Created September 27, 2012 21:55
Node debugging functions
global.debug = ( ) ->
tabs = ( n ) -> ( "\t" for i in [0...n] ).join( '' )
for i in [0...arguments.length]
arg = arguments[i]
type = get_type arg
# last arg is boolean? sleep if true
if ( i + 1 ) is arguments.length and type is 'Boolean'
if arg
@richthegeek
richthegeek / .htaccess
Created August 13, 2012 15:34
Automatic SASS/SCSS compilation with PHPSass and Apache2
Action compile-sass /git/phpsass/compile-apache.php
AddHandler compile-sass .sass .scss
@richthegeek
richthegeek / jquery.auto-load.js
Created March 19, 2012 00:08
Auto-load templates
var templates = window['templates'] = {}
$.get('assets/html', function(data) {
$('a[href*=html]', data).each(function() {
$.get('assets/html/' + $(this).attr('href'), function(data) {
_name = this.url.split('/').pop().split('.')
_name.pop()
path = templates
for (var i = 0; i < _name.length; i++) {
segment = _name[i]
@richthegeek
richthegeek / safe-color.scss
Created March 18, 2012 17:49
Safe color mixin
@function mix-alpha($color, $bg) {
@return mix(opacify($color, 1), opacify($bg, 1), alpha($color) * 100);
}
@mixin safe-color($color, $bg) {
background: mix-alpha($color, $bg);
background: $color;
}
body {
@richthegeek
richthegeek / mutators.php
Created March 12, 2012 21:37
Laravel: response mutators
<?php
Route::filter('after', function($response)
{
$format = Input::get('format', Config::get('application.default_mutator'));
$response->mutator = $format;
});
Route::mutator('string', function($response) {
@richthegeek
richthegeek / cache_filter.php
Created March 8, 2012 16:24
Variable microcaching with Laravel
<?php
Route::filter('cache', function($response = NULL) {
$cname = 'response-' . Str::slug(URI::full());
if (!$response) {
return Cache::get($cname);
}
else if ($response->status == 200) {
$ctime = floor(pow(current(sys_getloadavg()) + 1, 5)); # cache for between 1 and 32 minutes
Cache::put($cname, $response, $ctime);
@richthegeek
richthegeek / fizzbuzz.scss
Created March 6, 2012 10:03
Fizzbuzz in SCSS
@function mod($l, $r) {
@while ($l - $r) >= 0 {
$l: $l - $r;
}
@return abs($l);
}
@for $i from 1 through 100 {
#{$i} {
@if mod($i, 3) == 0 and mod($i, 5) == 0 {
@richthegeek
richthegeek / transition_hack.css
Created March 5, 2012 22:33
Make an input retain a style after it's clicked/hovered using transitions
div {
background: #f00;
-webkit-transition: background 1000s linear;
-moz-transition: background 1000s linear;
transition: background 1000s linear;
}
div:hover {
background: #00f;
-webkit-transition: none;
@richthegeek
richthegeek / laravel-issue378.patch
Created March 5, 2012 04:20
Laravel: patch for adding generic validtor.
diff --git a/laravel/validator.php b/laravel/validator.php
index 0c84e8e..1a09bff 100644
--- a/laravel/validator.php
+++ b/laravel/validator.php
@@ -584,7 +584,7 @@ class Validator {
*/
protected function validate_alpha($attribute, $value)
{
- return preg_match('/^([a-z])+$/i', $value);
+ return $this->validate_match($attribute, $value, 'a-z');
@richthegeek
richthegeek / jquery.number.coffee
Created February 15, 2012 15:23
Number-input poly-fill (with optional added features)
$ = jQuery
jQuery.fn.number = (options) ->
defaults =
min: null
max: null
step: 1
pattern: /^(-?[0-9\.]*)$/
default_prefix: ''
default_suffix: ''
change_on_click: true