Skip to content

Instantly share code, notes, and snippets.

View jblyberg's full-sized avatar
🏠
Working from home

John Blyberg jblyberg

🏠
Working from home
View GitHub Profile
@jblyberg
jblyberg / time_ago.php
Created January 6, 2012 21:02
Human-readable "time ago" function
<?php
function TimeAgo($datefrom, $dateto = -1)
{
if ($datefrom <= 0) {
return "A long time ago";
}
if ($dateto == -1) {
$dateto = time();
}
@jblyberg
jblyberg / create_audiobook
Created January 29, 2012 04:22
Creates an iPod/iTunes .m4b audiobook file from a bunch of MP3s
#!/bin/bash
# create ipPod audiobook from group of sequentially named MP3 files
# Set environmental variables for track ID3 tags
# AUTHOR, TITLE, YEAR
# usage: create_audiobook
#
# Pass output filename on command-line with no extension, and use quotes if there are spaces in filenames
# e.g. create_audiobook "Terry Pratchett - Colour of Magic" *.mp3
# e.g. create_audiobook "Terry Pratchett - Colour of Magic" “Terry Pratchett - Colour of Magic - *.mp3″
@jblyberg
jblyberg / Default (OSX).sublime-keymap
Created September 16, 2012 14:40
Sublime Text Keybinding
// Fixes Home and End keys in Sublime Text 2
[
{ "keys": ["end"], "command": "move_to", "args": {"to": "eol"} },
{ "keys": ["home"], "command": "move_to", "args": {"to": "bol"} },
{ "keys": ["shift+end"], "command": "move_to", "args": { "to": "eol", "extend": true } },
{ "keys": ["shift+home"], "command": "move_to", "args": { "to": "bol", "extend": true } }
]
@jblyberg
jblyberg / gist:3827335
Created October 3, 2012 14:51
rtd's mutli-account fix
function sopac_subaccounts_confirm_remove_submit($form, &$form_state) {
$account = $form_state['values']['account'];
$subID = $form_state['values']['subID'];
$sub_cards = explode(',', $account->profile_pref_additional_cardnum);
$removed_card = $sub_cards[$subID];
unset($sub_cards[$subID]);
$update = array(
'profile_pref_additional_cardnum' => implode(',', $sub_cards),
'profile_pref_cardnum' => $account->profile_pref_cardnum,
@jblyberg
jblyberg / ripper.sh
Created October 9, 2012 13:10
Totally basic script to rip audiobook CDs into a single file.
#!/bin/sh
#
# Totally basic script to rip audiobook CDs into a single file.
# I then use Audiobookbinder to create .m4b files so I can listen to them
# on my iPhone
#
# You'll need to:
# brew install cdparanoia
# brew install shntool
# brew install lame
@jblyberg
jblyberg / gist:3865611
Created October 10, 2012 13:21
Sphinx charset_table
charset_table = 0..9, a..z, _, A..Z->a..z, U+00C0->a, U+00C1->a, U+00C2->a, U+00C3->a, U+00C4->a, U+00C5->a, U+00C7->c, U+00C8->e, U+00C9->e, U+00CA->e, U+00CB->e, U+00CC->i, U+00CD->i, U+00CE->i, U+00CF->i, U+00D1->n, U+00D2->o, U+00D3->o, U+00D4->o, U+00D5->o, U+00D6->o, U+00D8->o, U+00D9->u, U+00DA->u, U+00DB->u, U+00DC->u, U+00DD->y, U+00E0->a, U+00E1->a, U+00E2->a, U+00E3->a, U+00E4->a, U+00E5->a, U+00E7->c, U+00E8->e, U+00E9->e, U+00EA->e, U+00EB->e, U+00EC->i, U+00ED->i, U+00EE->i, U+00EF->i, U+00F1->n, U+00F2->o, U+00F3->o, U+00F4->o, U+00F5->o, U+00F6->o, U+00F8->o, U+00F9->u, U+00FA->u, U+00FB->u, U+00FC->u, U+00FD->y, U+00FF->y, U+0100->a, U+0101->a, U+0102->a, U+0103->a, U+0104->a, U+0105->a, U+0106->c, U+0107->c, U+0108->c, U+0109->c, U+010A->c, U+010B->c, U+010C->c, U+010D->c, U+010E->d, U+010F->d, U+0112->e, U+0113->e, U+0114->e, U+0115->e, U+0116->e, U+0117->e, U+0118->e, U+0119->e, U+011A->e, U+011B->e, U+011C->g, U+011D->g, U+011E->g, U+011F->g, U+0120->g, U+0121->g, U+0122->g, U+0123->g
@jblyberg
jblyberg / suid-wrapper.c
Created October 16, 2012 14:29
A very small C wrapper for running shell scripts suid. Pretty dangerous, but handy.
#include <unistd.h>
#include <errno.h>
main( int argc, char ** argv, char ** envp )
{
if( setgid(getegid()) ) perror( "setgid" );
if( setuid(geteuid()) ) perror( "setuid" );
envp = 0; /* blocks IFS attack on non-bash shells */
system( "/path/to/bash/script", argv, envp );
perror( argv[0] );
@jblyberg
jblyberg / gist:35e68be7fa9ebf1e66ed
Last active January 2, 2020 18:50 — forked from saetia/gist:1623487
Clean Install – OS X 10.11 El Capitan

OS X Preferences


most of these require logout/restart to take effect

# Enable character repeat on keydown
defaults write -g ApplePressAndHoldEnabled -bool false

# Keyboard repeat
@jblyberg
jblyberg / gist:97845a429c81b967f222
Last active November 1, 2015 19:25
Working with Dates for Weekly Calendar
$year = date('Y');
$week_no = date('W');
$week_start = new DateTime();
$week_start->setISODate($year, $week_no);
echo $week_start->format('l jS F (Y-m-d)'); // Monday for the current week
// Gets the week range for given date YYYY-MM-DD
function rangeWeek($datestr) {
@jblyberg
jblyberg / Plugin.php
Last active February 17, 2017 11:54 — forked from frzsombor/gist:ddd0e11f93885060ef35
Share Laravel 5.1 session and check authentication from Moxiemanager.
<?php
/*
|--------------------------------------------------------------------------
| Sharing Laravel's session and checking authentication
|--------------------------------------------------------------------------
|
| Customized Moxiemanager plugin for use in our Laravel App. We use a custom
| External authentication module, but you get the gist (ha ha) of it.
| Put the Plugin.php file in moxiemanager/plugins/LaravelAuthenticator