Skip to content

Instantly share code, notes, and snippets.

@AndrewO
AndrewO / Main.hs
Created February 6, 2014 14:05 — forked from anonymous/Main.hs
module MountJSON where
-- import Prelude hiding (getContents)
import qualified Data.Aeson as JSON
import qualified Data.ByteString.Lazy.Char8 as Char
main :: IO ()
main = do
input <- Char.getContents
case JSON.eitherDecode input of
@AndrewO
AndrewO / multi_index_elastic_search.rb
Created April 16, 2014 20:38
Multi-index searching with highlighting across heterogenous types.
# We have a couple of indices that have been created independently.
# Now we want to search across them, with highlighting (and ideally
# suggestors as well) without breaking exisiting services.
#
# The mappings do not have consistent field names, but they have fields that can
# be semantically mapped into "title" or "body" (and some others) fields.
#
# From the size of the data, I'm told that creating a new purpose-build index is
# out of the question--even something that would duplicate data in another field
# in the same index is a stretch.
class A
attr_reader :val
def initialize(a, &b)
@val = a || (b ? b.call : :nada)
end
end
class B < A
def initialize(b)
super(b)

Stephen's Shitlist

Person/Place/Thing Shit-storm level (tm)
Obama / Healthcare ![1][poo] ![2][poo] ![3][poo] ![4][poo] ![5][poo]
ERB and HAML templates ![1][poo] ![2][poo] ![3][poo] ![4][poo] ![5][poo]
Matt Newton Metaprogramming ![1][poo] ![2][poo] ![3][poo] ![4][poo] ![5][poo]
T-Mobile ![1][poo] ![2][poo] ![3][poo] ![4][poo] ![5][poo]
Ruby Hash Rockets ![1][poo] ![2][poo] ![3][poo] ![4][poo] ![5][poo]
PHP Developers ![1][poo] ![2][poo] ![3][poo] ![4][poo] ![5][poo]
ruby >& ~/Library/Logs/tm_treetop_debug <<END &
require "#{ENV["TM_SUPPORT_PATH"]}/lib/ui"
begin
require "$TM_BUNDLE_SUPPORT/syntax_tree_viewer"
s = SyntaxTreeViewer.new_with_unknown_grammar
s.dialog if s
rescue Exception => error
TextMate::UI.alert(:warning, "You’ve discovered a bug", "Please report the following text: #{error}\n\n#{error.backtrace.join(%Q{\n})}")
#project.rb
has_many :usages
has_many :asset_orders
has_many :usages, :through => :requests
#request.rb
belongs_to :project
#usage.rb
belongs_to :request
// Contrived example. Your f() is presumably correct and should be returning a pointer
// to an unsigned short
unsigned short *f() {
return (unsigned short *)"foo";
}
// A simple g() that takes a pointer to a char and prints its string
void g(char *s) {
printf("Got: %s\n", s);
}
require 'test/unit'
class SubsectionGraph
# This gives us access to the class's singleton object which will sit between the actual Class structure and
# any instances and child classes
#
# If you're using metaid, this can be replaced by something like:
# meta_eval do
# def prefix(p = nil)
# ...
class CheckAssociationProcessor < ETL::Processor::RowProcessor
attr_reader :ids, :foreign_key
def initialize(control, configuration)
super
@foriegn_key = configuration[:foreign_key] || raise ArgumentError, ":foreign_key option required"
model = configuration[:model] || raise ArgumentError, ":model option required"
# Optional :conditions or :find_options
find_options = cond = (configuration[:conditions] ? {:conditions => cond} : configuration[:find_options]) || {}
set :additional_shared_paths, ["public/page_attachments", "public/excel_page_attachments"]
namespace :deploy do
after "deploy:update_code", "deploy:link_additional_shared_paths"
desc "Link directories to shared paths if they're in the additional_shared_paths variable"
task :link_additional_shared_paths do
additional_shared_paths.each do |path|
run "ln -nfs #{shared_path}/#{path} #{release_path}/#{path}"
end
end