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 / 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}}
@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 / 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 / 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 / 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 / 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
Gem::Specification.new do |s|
s.name = 'cptn-log'
s.version = '0.0.2'
s.platform = Gem::Platform::RUBY
s.author = 'Kevin Melchert'
s.email = 'kevin.melchert@gmail.com'
s.summary = 'MongoDB Logger.'
s.description = 'MongoDB Logger.'
s.files = ['cptn-log.rb']
@max-power
max-power / passbook.rb
Last active August 29, 2015 13:56
ruby passbook generation in one tiny file
%w(pathname json openssl net/http digest/sha1 zip).each { |lib| require lib }
module Passbook
def self.wwdr_certificate
OpenSSL::X509::Certificate.new <<-EOF.gsub /^\s+/, ""
-----BEGIN CERTIFICATE-----
MIIEIzCCAwugAwIBAgIBGTANBgkqhkiG9w0BAQUFADBiMQswCQYDVQQGEwJVUzET
MBEGA1UEChMKQXBwbGUgSW5jLjEmMCQGA1UECxMdQXBwbGUgQ2VydGlmaWNhdGlv
biBBdXRob3JpdHkxFjAUBgNVBAMTDUFwcGxlIFJvb3QgQ0EwHhcNMDgwMjE0MTg1
NjM1WhcNMTYwMjE0MTg1NjM1WjCBljELMAkGA1UEBhMCVVMxEzARBgNVBAoMCkFw
@max-power
max-power / sinatra_mongo_api.rb
Last active October 29, 2017 14:42
Sinatra + MongoDB + JSON
require "sinatra"
require "mongo"
require "json"
class SimpleMongoApi < Sinatra::Base
set :mongo, Mongo::Client.new("mongodb://my.mongo.host/database")
def collection
settings.mongo["things"]
end