Skip to content

Instantly share code, notes, and snippets.

View huyderman's full-sized avatar

Jo-Herman Haugholt huyderman

View GitHub Profile
meter {
-webkit-appearance: meter;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
display: inline;
display: -moz-inline-box;
display: -webkit-inline-box;
display: inline-block;
/**
* Simple example use of Paginator and jQuery
* @requires jQuery
* @requires Paginator.js
*/
var pager = new Paginator();
pager.setCurrent(5);
pager.setLast(23);
@huyderman
huyderman / EpochDateTime.cs
Created February 9, 2012 11:22
An object for working with time as commonly found in languages like java, c/c++, or *NIX platforms.
/** @file
* This software is licensed under the MIT license.
*
* @par The MIT License
*
* Copyright (c) 2012 Jo-Herman Haugholt
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
private static readonly Type StringType = typeof(string);
private static readonly Dictionary<Type, bool> IsStringAssignable = new Dictionary<Type, bool> { { StringType, true } };
private static readonly Dictionary<Type, ConstructorInfo> SingleStringConstructor = new Dictionary<Type, ConstructorInfo>();
private static readonly Dictionary<Type, MethodInfo> ParseMethod = new Dictionary<Type, MethodInfo>();
public static T Get<T>(string setting)
{
object value = ConfigurationManager.AppSettings.Get(setting);
@huyderman
huyderman / Newline.cs
Created March 16, 2012 13:20
C# Normalize Newline
using System.Text.RegularExpressions;
public static class StringHelpers {
private const char _cr = '\u000D';
private const char _lf = '\u000A';
private const string _crlf = _cr + _lf;
private static Regex _crlfRegex = new Regex(_cr + '|' + _lf + '|' + _crlf);
public static string NormalizeNewline(this string str){
@huyderman
huyderman / Rakefile
Created April 27, 2012 13:55
A rake snippet for auto-erb goodness
class TiltHelper
def initialize(prefix)
@prefix = prefix
end
def include(partial)
Tilt.new("#{@prefix}/#{partial}").render
end
end
rule( /\.((?!erb$)([A-Za-z0-9]))+$/ =>
# Calculates the area of a triangle given the length of it's sides
def heron(a, b, c)
s = (a+b+c)/2
Math.sqrt(s*(s-a)*(s-b)*(s-c))
end
@huyderman
huyderman / 12_days_of_christmas.rb
Created January 2, 2014 10:50
12 Days of Christmas via rounin (http://rounin.livejournal.com/23870.html) with improvments by me
#!/usr/bin/env ruby
days = %w(first second third fourth fifth sixth seventh eighth ninth tenth eleventh twelfth)
things = ['a partridge in a pear tree', 'two turtledoves', 'three French hens', 'four calling birds', 'five golden rings', 'six geese a-laying', 'seven swans a-swimming', 'eight maids a-milking', 'nine ladies dancing', 'ten lords a-leaping', 'eleven pipers piping', 'twelve drummers drumming']
days.each_with_index do |day, i|
puts "On the #{day} day of Christmas, my true love sent to me:"
day_things = things[0..i].reverse.each_with_index.map do |thing, j|
case j
# Maintainer: Jo-Herman Haugholt <johannes@huyderman.com>
pkgname=gitver-git
pkgver=0.0.0
pkgrel=1
pkgdesc="Simple version string management for git"
arch=('any')
url="https://github.com/manuelbua/gitver"
license=('Apache')
groups=()
@huyderman
huyderman / fork.rb
Created April 21, 2015 10:45
Fork with logger
require 'logger'
logger = Logger.new STDOUT
function = -> { logger.info "Something that takes a while..." }
# fork is not portable
if Process.respond_to?(:fork)
Process.detach fork(&function)
else