Skip to content

Instantly share code, notes, and snippets.

Avatar

Freddy Kelly fredkelly

View GitHub Profile
@fredkelly
fredkelly / navigation.html
Last active Apr 19, 2018
Generating a nested navigation in Jekyll with Liquid
View navigation.html
{% assign pages = site.html_pages | where: 'visible', true | where_exp: 'page', 'page.url contains include.context' | group_by: 'dir' %}
<ul>
{% for group in pages %}
{% if group.size > 1 and group.name != include.context %}
<li class="{% if page.url contains group.name %}active{% endif %}">
<span>{{ group.name | replace: '/', '' | capitalize }}</span>
{% include navigation.html context=group.name %}
</li>
{% else %}
{% for item in group.items %}
@fredkelly
fredkelly / a16z_your_name.rb
Created Nov 4, 2015
"Andreessen Horowitz" => "A16z" etc.
View a16z_your_name.rb
def a16z_your_name(name)
(h, *m, t) = name.gsub(/\s/,'').split(//)
[h, m.size, t].join
end
View gist:7247ce3f3612d24daf44
### Keybase proof
I hereby claim:
* I am fredkelly on github.
* I am fredkelly (https://keybase.io/fredkelly) on keybase.
* I have a public key whose fingerprint is C136 6714 3B16 C5A5 2AB8 7CB6 3F46 C1D7 7087 503A
To claim this, I am signing this object:
@fredkelly
fredkelly / s3cmd-delete.sh
Created Aug 15, 2014
Delete all contents of s3 bucked using s3cmd
View s3cmd-delete.sh
s3cmd sync --delete-removed /dev/null s3://my-bucket
View date_formatter.m
// ..snip
// Setup date formatter
NSDateFormatter *dateFormatter = [NSDateFormatter new];
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"];
dateFormatter.timeZone = [NSTimeZone timeZoneWithAbbreviation:@"UTC"];
entityMapping.preferredDateFormatter = dateFormatter;
// snip..
@fredkelly
fredkelly / retina_detect.js
Created Nov 26, 2013
jQuery Retina Replacement
View retina_detect.js
// assumes the following image tag:
// <img src="foo.png" data-2x="foo-hires.png" />
$(document).ready(function () {
// substitute @2x images where available
if (window.isRetina()) {
console.log("loading retina images..");
var replacement;
$('img[data-2x]').each(function(i, img) {
replacement = $(img).clone().attr('src', $(img).data('2x')) || img;
@fredkelly
fredkelly / squid_auth.rb
Created Aug 3, 2013
Gmail authentication helper for use with Squid proxy.
View squid_auth.rb
#!/usr/bin/env ruby
require 'net/imap'
while true
# open connection
imap = Net::IMAP.new('imap.googlemail.com', 993, true)
# get credentials
user, pass = $stdin.readline.split
@fredkelly
fredkelly / gist:3655228
Created Sep 6, 2012
ffmpeg homebrew for html5 video
View gist:3655228
brew install ffmpeg --with-theora --with-libogg --with-libvorbis
@fredkelly
fredkelly / determine_win.php
Created Jul 29, 2011
Determine win (boolean) based on given odds string.
View determine_win.php
function determine_win($odds) {
$range = explode('/', $odds);
return in_array(mt_rand(0, $range[1]), range(0, $range[0]));
}
$one_in_ten = determine_win('1/10');
$fifty_fifty = determine_win('1/2');
$three_in_seven = determine_win('3/7');
@fredkelly
fredkelly / placeholde.js
Created Jul 5, 2011
Quick fix for the HTML5 placeholder="" attribute using jQuery & Modernizr
View placeholde.js
if (!Modernizr.input.placeholder) {
$("input").each(function(){
if ($(this).val() == "" && $(this).attr("placeholder") != "") {
$(this).val($(this).attr("placeholder"));
$(this).focus(function(){
if ($(this).val() == $(this).attr("placeholder")) $(this).val("");
}); // focus
$(this).blur(function(){
if ($(this).val() == "") $(this).val($(this).attr("placeholder"));
}); // blur