Skip to content

Instantly share code, notes, and snippets.

@jsl
jsl / replacer.rb
Last active August 29, 2015 13:56
Dictionary Replacer
require 'minitest/autorun'
require 'stringio'
class DictionaryReplacer
MARK = '$'
ESCAPE = '\\'
def initialize(to_replace, dictionary)
@to_replace = StringIO.new(to_replace)
@jsl
jsl / fix_osx_build.patch
Created February 16, 2014 16:01
Fix HaXml build on OS X
1 patch for repository http://code.haskell.org/HaXml:
Sun Feb 16 10:47:50 ECT 2014 Justin Leitgeb <justin@stackbuilders.com>
* Fix compilation on Mac OS X
The build of HaXml is currently broken on Mac OS X. Since a lot of packages
depend on HaXml this is quite inconvenient. Below is a description of the
problem that was previously posted to Stack Overflow:
http://stackoverflow.com/questions/20497348/haxml-installation-issues-on-os-x-10-9-mavericks
@jsl
jsl / gist:995ccbe928e50635a5d4
Created August 12, 2014 03:51
Ruby generated file from Idris -> Ruby backend
#!/usr/bin/env ruby
# Example generated from https://github.com/edwinb/idris-demos/blob/master/RLE/rle-vect.idr.
class I_VM
attr_accessor :valstack, :valstack_top, :valstack_base, :ret, :callstack
def initialize()
@valstack = []
@valstack_top = 0
@valstack_base = 0
#!/usr/bin/env sh
GHC_VERSION_STRING=`ghc --version 2> /dev/null`
if [ $? -ne 0 ]
then
echo "Unable to obtain GHC version!"
exit 1
fi
outsidein@ey05-s00398 ~ $ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 6.0G 6.0G 0 100% /
udev 10M 124K 9.9M 2% /dev
shm 769M 0 769M 0% /dev/shm
/dev/sdb1 19G 2.4G 17G 13% /data
@jsl
jsl / gist:711058
Created November 23, 2010 01:06
cattr_reader
# File activesupport/lib/active_support/core_ext/class/attribute_accessors.rb, line 10
def cattr_reader(*syms)
options = syms.extract_options!
syms.each do |sym|
next if sym.is_a?(Hash)
class_eval("unless defined? @@\#{sym}\n@@\#{sym} = nil\nend\n\ndef self.\#{sym}\n@@\#{sym}\nend\n", __FILE__, __LINE__ + 1)
unless options[:instance_reader] == false
class_eval("def \#{sym}\n@@\#{sym}\nend\n", __FILE__, __LINE__ + 1)
end
@jsl
jsl / immediate_failure_formatter.rb
Created March 2, 2011 23:37
Untested Untested
require 'spec/runner/formatter/base_text_formatter'
require 'spec/runner/formatter/no_op_method_missing'
module Spec
module Runner
module Formatter
class ImmediateFailureFormatter < BaseTextFormatter
include NOOPMethodMissing
def example_failed(example, counter, failure)
def index
search = PartnerPage.find_all_by_indexed_name(params[:term])
names = search.hits.map do |h|
name = h.stored(:name_kword)
url = partner_page_url(h.stored(:friendly_id))
{ :value => name, :id => url }
end
SELECT DISTINCT message_id
FROM SELECT *, id AS message_id FROM user_messages WHERE user_id = ?
AND read = false AND parent_id IS NULL AS initial_messages
UNION
SELECT *, parent_id AS message_id FROM user_messages WHERE user_id = ?
AND read = false AND parent_id IS NOT NULL AS replies;