Skip to content

Instantly share code, notes, and snippets.

View richthegeek's full-sized avatar

Richard Lyon richthegeek

View GitHub Profile
@richthegeek
richthegeek / hmac.java
Last active August 29, 2015 14:26
Veoo Subscriber API HMAC generation
private static String toHexString(byte[] bytes) {
Formatter formatter = new Formatter();
for (byte b : bytes) {
formatter.format("%02x", b);
}
return formatter.toString();
}
public static String generateHMAC(String path, String body, String key) throws SignatureException, NoSuchAlgorithmException, InvalidKeyException {
SecretKeySpec signingKey = new SecretKeySpec(key.getBytes(), "HmacSHA1");
@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 / 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 {