Skip to content

Instantly share code, notes, and snippets.

View richthegeek's full-sized avatar

Richard Lyon richthegeek

View GitHub Profile
@richthegeek
richthegeek / _tooltip.scss
Created January 25, 2012 09:56
Cheap and easy tooltips :)
@mixin tooltip($text, $top: 0px, $left: 0px) {
&:hover::after {
$top: $top - 7px;
$left: $left - 10px;
content: quote($text);
position: absolute;
@include transition(all, 0.3s);
@include linear-gradient(rgba(0,0,0,0.6), rgba(0,0,0,0.8), transparent);
border-radius: 20px;
.treeview {
& > ul > li:first-of-type {
& > span {
padding-left: 12px !important;
}
&::before {
content: '';
position: absolute;
width: 10px;
@richthegeek
richthegeek / _ios-checkbox.scss
Created January 26, 2012 14:54
iOS checkboxes
@mixin linear-gradient($a, $b: false, $c: false, $d: false, $e: false, $f: false, $g: false) {
$value: $a;
@each $var in $b, $c, $d, $e, $f, $g {
@if $var {
$value: $value + ', ' + $var;
}
}
$value: unquote($value);
@include value-prefix('background', "linear-gradient(" + $value + ")");
}
@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
@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 / 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 / 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 / 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 / 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 / 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 {