Skip to content

Instantly share code, notes, and snippets.

@ohaal
ohaal / find_relative_path.func.php
Created June 15, 2012 11:47
Find the relative path between two paths
/**
*
* Find the relative file system path between two file system paths
*
* @param string $frompath Path to start from
* @param string $topath Path we want to end up in
*
* @return string Path leading from $frompath to $topath
*/
function find_relative_path ( $frompath, $topath ) {
@ohaal
ohaal / justify.func.php
Created June 16, 2012 02:18
Justify (similar to HTML align="justify") a string, without looping
// Answer to http://stackoverflow.com/a/11059923/1210983
function justify($str, $maxlen) {
$str = trim($str);
$strlen = strlen($str);
if ($strlen >= $maxlen) {
$str = wordwrap($str, $maxlen);
$str = explode("\n", $str);
$str = $str[0];
$strlen = strlen($str);
@ohaal
ohaal / FetchURL.regex
Last active October 6, 2015 06:38
Regular expression to grab (most) URLs from any string, pre gTLD craze
# Regex to grab (most) URLs from any string (except most gTLD's, but can be added manually)
# This will never be perfect (see [1]&[2]), but it does its job fair enough, currently only 2 exceptions are added (museum & travel)
#
# Capture groups:
# 1. Full URL
# 2. The protocol
# 3. Hostname+path including `www*.`
# 4. Hostname+path excluding `www*.`
# TODO: Capture group for path
#
@ohaal
ohaal / exiftool_sort.sh
Created June 29, 2012 20:34
Sort and rename JPG and AVI recursively with exiftool (year/month/fulldate), then remove duplicates (no prompt to delete)
#!/bin/sh
exiftool -ext AVI -ext JPG -r -d %Y/%m/%Y_%m_%d-%H_%M_%S-%%.2c.%%e "-FileName<DateTimeOriginal" .
# use with caution
#fdupes -rdN .
/*!
* Scroll Sneak
* http://mrcoles.com/scroll-sneak/
*
* Copyright 2010, Peter Coles
* Licensed under the MIT licenses.
* http://mrcoles.com/media/mit-license.txt
*
* Date: Mon Mar 8 10:00:00 2010 -0500
*/
@ohaal
ohaal / parseDate.js
Last active December 30, 2015 10:29
Return milliseconds until a specified date string (very specific use case)
function _parseDate(input) {
var re = /^(?:(?:(\d{1,2})[\/.\\-](\d{1,2})(?:[\/.\\-]((?:\d{2}|\d{4})))?(?:\D(\d{1,2}):(\d{1,2})(?::(\d{1,2}))?)?)|(?:(\d{1,2}):(\d{1,2})(?::(\d{1,2}))?))$/;
var time = re.exec(input);
var year, month, day, hour, minute, second;
var future, now;
var curDate = new Date();
var unixCurDayOfMonth = new Date(curDate.getFullYear(), curDate.getMonth(), curDate.getDate()).getTime();
var unixCurTime = curDate.getTime();
<script>
$(document).ready(function() {
$('.menu-open > ul').show();
$('ul.menu-list > li > div').on('click', function() {
var list_element = $(this).parent();
var submenu = list_element.children('ul');
if (list_element.hasClass('menu-closed')) {
list_element.addClass('menu-open');

Description

This simple script will take a picture of a whiteboard and use parts of the ImageMagick library with sane defaults to clean it up tremendously.

The script is here:

#!/bin/bash
convert $1 -morphology Convolve DoG:15,100,0 -negate -normalize -blur 0x1 -channel RBG -level 60%,91%,0.1 $2

Results

# Set ctrl-a as prefix
set -g prefix C-a
unbind C-b
# ctrl-a passthrough by sending ctrl-a 2 times
bind C-a send-prefix
# Less delay
set -sg escape-time 1
// source: https://github.com/Conlectus/WhoAmI
var rawSites = {
'programming': [
'http://blog.codinghorror.com/',
'http://thedailywtf.com/',
'http://www.hanselman.com/blog/',
'http://code.tutsplus.com',
'https://news.ycombinator.com/',
'http://www.reddit.com/r/programming/',
'http://codebetter.com',