Skip to content

Instantly share code, notes, and snippets.

View fredkelly's full-sized avatar

Freddy Kelly fredkelly

View GitHub Profile
@fredkelly
fredkelly / navigation.html
Last active April 19, 2018 13:38
Generating a nested navigation in Jekyll with Liquid
{% 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 / squid_auth.rb
Created August 3, 2013 17:12
Gmail authentication helper for use with Squid proxy.
#!/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 / retina_detect.js
Created November 26, 2013 21:53
jQuery Retina Replacement
// 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 / a16z_your_name.rb
Created November 4, 2015 10:28
"Andreessen Horowitz" => "A16z" etc.
def a16z_your_name(name)
(h, *m, t) = name.gsub(/\s/,'').split(//)
[h, m.size, t].join
end
@fredkelly
fredkelly / gist:3655228
Created September 6, 2012 11:38
ffmpeg homebrew for html5 video
brew install ffmpeg --with-theora --with-libogg --with-libvorbis
@fredkelly
fredkelly / determine_win.php
Created July 29, 2011 15:01
Determine win (boolean) based on given odds string.
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 July 5, 2011 09:35
Quick fix for the HTML5 placeholder="" attribute using jQuery & Modernizr
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
/*************************************************
** jQuery Nice Menus version 1.0.0
** copyright Fred Kelly, licensed GPL & MIT
** http://fredkelly.net/
**************************************************/
(function($){
$.fn.menus = function() {
return this.each(function() {
<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
$plugin_info = array(
'pi_name' => 'Post Categories',
'pi_version' =>'1.0',
'pi_author' =>'Fred Kelly',
'pi_author_url' => 'http://fredkelly.net/',
'pi_description' => 'Returns the post categories how I want them.'
/*************************************************
** jQuery Multi Column Lists version 1.0.5
** copyright Fred Kelly, licensed GPL & MIT
** http://fredkelly.net/
**************************************************/
(function($){
$.fn.multilists = function(options, callback) {
var defaults = {