Skip to content

Instantly share code, notes, and snippets.

- class:
name: Enum;DefinitionType
properties:
- Unknown
- OidValueAssignment
- Scalar
- Table
- Entry
- Column
#!/usr/bin/env ruby
# see http://timeless.judofyr.net/tailin-ruby for what the define_singleton_method's are about
define_singleton_method(:find_nth_largest_tco) do |a, b, n, low, high|
if (high < low)
return nil
end
mid = low + (high - low) / 2
k = mid + binary_search(b, a[mid]) + 1
## Ruby - 154 characters
def h i,n;(l=Math).log(i,2)*l.log(i,3)*l.log(i,5)/6>n ?[i]:[i]+h(2*i,n)+h(3*i,n)+h(5*i,n)end
puts h(1,n=gets.to_i).sort.uniq.first(n).map(&:to_s).join" "
Very slow because of the expensive heuristic for the recursion completion and the multiples of the same solutions, but can compute the first 150 or so numbers quickly.
[﹤﹤IObjectTree﹥﹥{bg:cornsilk}]
[ObjectTree{bg:orange}]
[﹤﹤IObjectRegistry﹥﹥{bg:cornsilk}]
[ObjectRegistryBase{bg:cornsilk}]
[DefaultObjectRegistry]
[ReloadableObjectRegistry]
[﹤﹤IDefinition﹥﹥{bg:cornsilk}]
[Definition{bg:cornsilk}]
[Enum;DefinitionType|Unknown;OidValueAssignment;Scalar;Table;Entry;Column]
[ObjectIdentifier]
@Nemo157
Nemo157 / README.markdown
Created February 20, 2011 12:10
A JSON validator written in Befunge

This gist is going to contain a JSON validator written in Befunge-93. So far there is a working ruby "pseudocode" version that should be able to be directly translated to Befunge.

The architecture of this program is to have one central dispatcher, and use continuation passing style via the stack to determine which functions to call. The biggest problem with this is that by using the stack as the function call information it cannot be used for arguments. The solution to this is to minimize the number of arguments that have to be used. This has been almost perfectly accomplished, only the number related functions require arguments. This means that one cell can be set aside to be used for storing this argument when they return.

require 'benchmark'
require 'benchmark/ips'
Benchmark.ips do |x|
dec_include = 0..10
dec_exclude = 0...10
hex_include = 0xffff..0xfffff
hex_exclude = 0xffff...0xfffff
flt_include = 0.5..2.4
flt_exclude = 0.5...2.4
@Nemo157
Nemo157 / Makefile
Created April 14, 2011 02:04
Installs avr-gcc on OS X 10.7
gdb := gdb-7.3.1
binutils := binutils-2.20.1
gcc := gcc-4.5.1
gcc_core := gcc-core-4.5.1
gcc_gpp := gcc-g++-4.5.1
avr_libc := avr-libc-1.7.1
target := avr
prefix := /usr/local/${target}
PATH := ${prefix}/bin:${PATH}
@Nemo157
Nemo157 / test.rb
Created May 1, 2011 23:48
Rubinius error
→ ruby -d -W2 --vv test.rb
rubinius 1.2.4dev (1.8.7 77994afa yyyy-mm-dd) [x86_64-apple-darwin10.7.0]
Options:
Interpreter type: static
JIT disabled
An exception occurred running test.rb
Tried to use object of type PackedObject (45) as type LookupTable (35) (TypeError)
Backtrace:
class A
def speak
puts "This class is #{self.class}, with greeting #{self.class.greeting}"
end
@greeting = "Default greeting"
class << self
attr_reader :greeting
end
end

This gist is related to this project. This is the results from my initial testing round.