Skip to content

Instantly share code, notes, and snippets.

View tobiashm's full-sized avatar

Tobias H. Michaelsen tobiashm

View GitHub Profile
@tobiashm
tobiashm / sass-yuv.gemspec
Last active September 30, 2015 00:47
SASS YUV color space extensions
Gem::Specification.new do |spec|
spec.name = 'sass-yuv'
spec.version = '0.1.0'
spec.platform = Gem::Platform::RUBY
spec.author = 'Tobias H. Michaelsen'
spec.email = '[email protected]'
spec.summary = 'YUV color space in SASS'
spec.description = 'A simple extension to SASS that alows you to convert to and from the YUV color space, and adjust brightness.'
spec.homepage = 'https://gist.github.com/1694554'
spec.license = 'MIT'
@tobiashm
tobiashm / contrast.js
Last active October 15, 2021 02:02
Calculate contrasting colors, using https://github.com/One-com/one-color
var contrast = (function () {
var MIN_CONTRAST_RATE_AA = { normal: 4.5, large: 3 },
MIN_CONTRAST_RATE_AAA = { normal: 7, large: 4.5 },
MIN_BRIGHT_DIFF = 125/255,
MIN_COLOR_DIFF = 500/255,
BRIGHTNESS_COEFS = [0.299, 0.587, 0.114],
LUMINANCE_COEFS = [0.2126, 0.7152, 0.0722];
function abs_diff(array, other) {
@tobiashm
tobiashm / erb-encoding-test.rb
Created October 14, 2011 15:26
Test encoding in ERB
# encoding: UTF-8
require 'erb'
puts __ENCODING__
puts ERB.new('<%= __ENCODING__ %>').result
-- initial
UPDATE item SET depth = 0 WHERE parent_item_guid IS NULL;
-- SQLite3 doesn't support loops, so run this until `select count(*) from item where product_code is null` = 0
INSERT OR REPLACE INTO item(item_guid, user_guid, parent_item_guid, name, depth)
SELECT t.item_guid, t.user_guid, t.parent_item_guid, t.name, p.depth + 1 FROM item AS t
INNER JOIN item AS p ON (t.parent_item_guid = p.item_guid)
WHERE p.depth >= 0
AND NOT p.item_guid IS NULL
AND t.depth IS NULL;
@tobiashm
tobiashm / gist:985689
Created May 22, 2011 17:27
xkcd show image title bookmarklet
javascript:(function(){var i=document.querySelector('#comic img'),t=i.getAttribute('title');i.insertAdjacentText('afterEnd',t);})();
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>beforeRunningCommand</key>
<string>nop</string>
<key>command</key>
<string>`which node` "$TM_FILEPATH"</string>
<key>input</key>
<string>none</string>
@tobiashm
tobiashm / ROD-Ex.patch
Created February 3, 2011 09:57
Modification of http://www.autohotkey.net/~Skan/Scripts/RoD/ROD-Ex.ahk to create 2 icons in resource.dll
24c24
< ResourceFile := "AutoHotkeySC.bin" ; you many comment out one of
---
> ;ResourceFile := "AutoHotkeySC.bin" ; you many comment out one of
71a72
> {
72a74,75
> GoSub,RT_ICON ; 2011-02-03/THM: Add another copy of the same icon to work around a bug in Stack Docklet 2.0
> }
@tobiashm
tobiashm / new-operator-test.js
Created December 16, 2010 12:47
JavaScript `new` operator return an object
function foo() { return 'foo'; }
function bar() { return foo; }
foo()
//=> "foo"
bar()
//=> function foo() { return 'foo'; }
new foo()
//=> [Object foo]
new bar()
//=> function foo() { return 'foo'; }
@tobiashm
tobiashm / extensions.cs
Created December 3, 2010 12:09
Extension methods for .NET
// Source: http://www.pluralsight-training.net/community/blogs/keith/archive/2010/11/12/min-max-between-limit.aspx
public static class IComparableExtensions
{
public static T Limit<T>(this T value, T minValue, T maxValue) where T : IComparable
{
if (value.CompareTo(minValue) < 0)
return minValue;
if (value.CompareTo(maxValue) > 0)
return maxValue;
return value;
@tobiashm
tobiashm / fn-test.js
Created November 5, 2010 15:56
FunctionDeclarations vs FunctionExpression
try {
print(fn1);
print(fn2);
function fn1 () {} // FunctionDeclarations
(function fn2 () {}) // FunctionExpression
} catch (e) {