Skip to content

Instantly share code, notes, and snippets.

# http://gist.github.com/458158
require 'rubygems'
require 'dm-core'
require 'dm-migrations'
DataMapper::Logger.new($stdout, :debug)
DataMapper.setup(:default, 'sqlite::memory:')
class Thing
include DataMapper::Resource
@MichaelXavier
MichaelXavier / wtf.hs
Created February 12, 2011 05:45
This is why you don't parse JSON in Haskell
{-# LANGUAGE DeriveDataTypeable #-}
import Text.JSON
import Text.JSON.Generic
import Control.Monad (liftM2)
data Foo = Foo { name :: String } deriving (Eq, Show, Typeable, Data)
data FooSet = FooSet { foos :: [(String, Foo)]} deriving (Eq, Show)
-- Input data looks like
@r00k
r00k / gist:906356
Created April 6, 2011 19:33
Custom devise strategy
# In config/initializers/local_override.rb:
require 'devise/strategies/authenticatable'
module Devise
module Strategies
class LocalOverride < Authenticatable
def valid?
true
end
// The following is your top-level parent model in serialized JSON format:
var myModel = new Person({
"name" : {
"first_name" : "Andrew",
"last_name" : "de Andrade"
},
"address" : {
"street_address_1" : "Avenida Paulista 1000",
"street_address_2" : "Apt. 101",
@mtigas
mtigas / gist:952344
Last active June 20, 2024 11:22
Mini tutorial for configuring client-side SSL certificates.

Client-side SSL

For excessively paranoid client authentication.


Updated Apr 5 2019:

because this is a gist from 2011 that people stumble into and maybe you should AES instead of 3DES in the year of our lord 2019.

some other notes:

@simonmichael
simonmichael / gist:1185421
Created September 1, 2011 03:59
ghc-pkg-clean, ghc-pkg-reset
# unregister broken GHC packages. Run this a few times to resolve dependency rot in installed packages.
# ghc-pkg-clean -f cabal/dev/packages*.conf also works.
function ghc-pkg-clean() {
for p in `ghc-pkg check $* 2>&1 | grep problems | awk '{print $6}' | sed -e 's/:$//'`
do
echo unregistering $p; ghc-pkg $* unregister $p
done
}
# remove all installed GHC/cabal packages, leaving ~/.cabal binaries and docs in place.
@MichaelXavier
MichaelXavier / hash_of_arrays_permutations.rb
Created September 13, 2011 17:10 — forked from dplummer/hash_of_arrays_permutations.rb
Permutations of a hash of arrays
# Input:
# choices = {
# 'color' => %w(blue red green),
# 'sizes' => %w(small medium large extra-large),
# 'style' => %w(tshirt longsleeve)
# }
#
# Output:
# [{"sizes"=>"small", "color"=>"blue", "style"=>"tshirt"},
# {"sizes"=>"small", "color"=>"blue", "style"=>"longsleeve"},
@MichaelXavier
MichaelXavier / deepvalue.hs
Created October 15, 2011 07:36
Recursive operator for parsing values from deeply nested Objects in Aeson
(.:/) :: (FromJSON a) => Object
-> [Text]
-> Parser a
obj .:/ (k:ks) = maybe (fail msg) parseJSON parsed
where parsed = deepValue ks =<< M.lookup k obj
msg = "Failed to find " ++ (intercalate "/" $ map unpack (k:ks))
obj .:/ [] = parseJSON $ Object obj
deepValue :: [Text]
-> Value
@burke
burke / 0-readme.md
Created January 27, 2012 13:44 — forked from funny-falcon/cumulative_performance.patch
ruby-1.9.3-p327 cumulative performance patch for rbenv

ruby-1.9.3-p327 cumulative performance patch for rbenv

This installs a patched ruby 1.9.3-p327 with various performance improvements and a backported COW-friendly GC, all courtesy of funny-falcon.

Requirements

You will also need a C Compiler. If you're on Linux, you probably already have one or know how to install one. On OS X, you should install XCode, and brew install autoconf using homebrew.