This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.Monoid ((<>)) | |
import Data.Text (Text) | |
import Text.Parsec | |
import Text.Parsec.Text | |
import qualified Data.Text as T | |
-- Replace all successful parses with a text transformation. E.g.: | |
-- λ> replaceParsed (read <$> many1 digit) (T.pack . show . (+1)) "foo42bar99baz12quux" | |
-- "foo43bar100baz13quux" | |
replaceParsed :: Parser a -> (a -> Text) -> Text -> Text |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
escape :: [(Char, String)] -> String -> String | |
escape = foldr f id | |
where f (c,s) acc = acc . replaceOne (c,s) | |
replaceOne (c,s) = concatMap (\x -> if x == c then s else [x]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Inference where | |
-- This is extremely rough (a good bit is a gross amount of confusing mutual | |
-- recursion, and a few pieces just work without my understanding), but I | |
-- thought it'd be a good idea to get this down in case my laptop is hit with a | |
-- bus. | |
import Control.Applicative | |
import Data.Char | |
import Data.List |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Like this: | |
# | |
# params.allow_nested( | |
# user: must( | |
# name: must, | |
# age: maybe, | |
# article: must( | |
# title: must, | |
# publish_at: maybe | |
# ), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var width = 400; | |
var height = 300; | |
var len = 20; | |
var rand_data = function() { | |
return d3.range(len).map(function() { return 1 + Math.random() }); | |
} | |
var stack = d3.select("#chart"). | |
append("svg:svg"). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'sinatra' | |
require 'serialport' | |
port_str = "/dev/tty.usbmodemfa131" | |
baud_rate = 9600 | |
data_bits = 8 | |
stop_bits = 1 | |
parity = SerialPort::NONE |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>> module M | |
>> def foo | |
>> self.class::FOO | |
>> end | |
>> end | |
=> nil | |
>> class A; FOO = 1; extend M; end | |
=> A | |
>> class B; FOO = 42; extend M; end | |
=> B |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config/elastic_search.rb | |
ElasticSearchSettingsForUser = YAML.load_file('config/elastic_search_user.yml').with_indifferent_access | |
# user.rb | |
class User < ActiveRecord::Base | |
settings ElasticSearchSettingsForUser do | |
mapping do | |
[:name, :email, :company].each do |attribute| | |
indexes attribute, type: 'string', analyzer: 'ngram_analyzer' | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
settings analysis: { | |
filter: { | |
ngram_filter: { | |
type: "nGram", | |
min_gram: 3, | |
max_gram: 8 | |
} | |
}, | |
analyzer: { | |
ngram_analyzer: { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User < ActiveRecord::Base | |
include Tire::Model::Search | |
include Tire::Model::Callbacks | |
attr_accessible :name, :email, :company | |
#... | |
end |