Skip to content

Instantly share code, notes, and snippets.

@jackdoe
jackdoe / rack-and-mongo.rb
Created March 6, 2012 17:48
mongoid stored rack session Rack::Session::RackAndMongo
# inspired by https://github.com/biilmann/mongo_sessions
require 'rack/session/abstract/id'
class Session
include Mongoid::Document
field :sid
field :data
field :ts, type: Integer
index :sid, unique: true #dont forget Session.create_indexes
def Session.find_by_sid(sid)
Session.first(conditions: {sid: sid})
@jackdoe
jackdoe / bot.go
Last active December 26, 2015 15:19
golang map[string]bool{} based user agent detect
// took the list from:
// http://www.phacks.net/detecting-search-engine-bot-and-web-spiders/
// and made it a map[string]bool
var BOTS = map[string]bool{
"Baiduspider+(+http://www.baidu.com/search/spider.htm": true,
"Mozilla/5.0 (compatible; Baiduspider/2.0; +http://www.baidu.com/search/spider.html)": true,
"Moreoverbot/5.1 (+http://w.moreover.com; [email protected]) Mozilla/5.0": true,
"UnwindFetchor/1.0 (+http://www.gnip.com/)": true,
"Voyager/1.0": true,
hidutil property --set '{"UserKeyMapping":[{"HIDKeyboardModifierMappingSrc":0x700000035,"HIDKeyboardModifierMappingDst":0x7000000e1}, {"HIDKeyboardModifierMappingSrc":0x700000064,"HIDKeyboardModifierMappingDst":0x700000035}]}'
# remap §(top left corner) to be `
# remap `(very weirdly positioned near left shift) to be left shift
# from http://www.usb.org/developers/hidpage/Hut1_12v2.pdf
# § - id 0x64
# left shift - id 0xe1
# ` - id 0x35
@jackdoe
jackdoe / iso6392to6391.go
Created December 15, 2017 13:16
language code map from iso 639-2 to 639-1 ("eng" -> "en", "fre" -> "fr" etc)
var languagesMap = map[string]string{
"aar": "aa",
"abk": "ab",
"ace": "xx",
"ach": "xx",
"ada": "xx",
"ady": "xx",
"afa": "xx",
"afh": "xx",
"afr": "af",