Skip to content

Instantly share code, notes, and snippets.

@max-power
max-power / LICENSE.txt
Created April 3, 2012 01:02 — forked from 140bytes/LICENSE.txt
number to human byte size
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 YOUR_NAME_HERE <YOUR_URL_HERE>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@max-power
max-power / color.rb
Last active January 2, 2016 06:59
simple color value object
class Color < Struct.new(:r, :g, :b)
def self.hex(value)
new(*value.to_s.delete('#').scan(/../).map(&:hex))
end
def hex
"%.2X%.2X%.2X" % values
end
def to_s
@max-power
max-power / CSS3-Figure-Counter.css
Last active December 11, 2015 11:48
CSS3 Counter for Figures
article {
counter-reset: figure;
}
article figure {
counter-increment: figure;
}
article figure > figcaption:before {
content: "Fig. " counter(figure) ": ";
}
html[lang=de] article figure > figcaption:before {
@max-power
max-power / Backbone.ListViews.js
Last active December 9, 2015 21:59
Backbone.js Collection Views: - UnorderedList - OrderedList - Table
var listViewsRoot = window
;(function(ns){
// LIST ITEMS
ns.ListItem = Backbone.View.extend({
tagName: 'li',
template: '<%= id %>',
render: function(){
@max-power
max-power / backbone.mongomodel.js
Created August 23, 2012 20:06
Backbone MongoModel: embbedded models and collections.
Backbone.MongoModel = Backbone.Model.extend({
idAttribute: '_id',
embedded: {},
parse: function(i){
_.each(this.embedded, function(klass,k){ i[k] = new klass(i[k], {parse: true}) })
return i
},
toJSON: function(){
return _.reduce(this.attributes, function(o,v,k){ o[k] = v && v.toJSON ? v.toJSON() : v; return o }, {})
}
@max-power
max-power / LICENSE.txt
Created July 20, 2012 19:19 — forked from 140bytes/LICENSE.txt
Geographic coordinate conversion Latitude/Longitude to Degrees, Minutes, Seconds
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 YOUR_NAME_HERE <YOUR_URL_HERE>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@max-power
max-power / geolocation_polyfill.js
Created May 3, 2012 06:12
HTML5 Geolocation Polyfill
// requires jquery.js, tested with reqwest.js with jquery compat mode
// uses http://geoplugin.net/json.gp
// lowercase arguments are just string placeholder
// F = Function placeholder
// Z = Cache placeholder
;(function(N,g,c,x,y,u,j,F,Z) {
F=function(s,e){Z?s(Z):$.ajax({url:'//'+u+'.net/'+j+'.gp',dataType:j+'p',jsonp:j+'callback',error:e,success:function(R){Z={};Z[c]={};Z[c][x]=R[u+'_'+x];Z[c][y]=R[u+'_'+y];s(Z)}})}
N[g]=N[g]||{getCurrentPosition:F,watchPosition:F,clearWatch:function(){Z=undefined}}
class Duration
attr_accessor :from, :till
def initialize(from: nil, till: nil)
@from = from || Time.now
@till = till || Time.now
end
def seconds
(till - from).round
module Schmutz
Types = {
feinstaub: ["\u0323", "\u0307", "\u0312"],
mettwurst: ["\u0314", "\u031C", "\u0358", "\u0353", "\u0335"],
nein_nein: ["\u0337", "\u0338", "\u0336", "\u0335", "\u20d2", "\u20d3", "\u20e5", "\u20e6", "\u20eb"]
}.freeze
Types.each do |name, runes|
define_singleton_method name do |input, prop = 0.25|
mangle(input, runes, prop)
@max-power
max-power / authorization.gemspec
Last active August 29, 2015 14:17
Super simple policy authentication.
Gem::Specification.new do |s|
s.name = 'policy-authorization'
s.version = '0.0.2'
s.platform = Gem::Platform::RUBY
s.author = 'Kevin Melchert'
s.email = 'kevin.melchert@gmail.com'
s.summary = 'Super simple policy authentication.'
s.description = 'Super simple policy authentication.'
s.files = ['authorization.rb']