Skip to content

Instantly share code, notes, and snippets.

View teleological's full-sized avatar

Riley Lynch teleological

  • Teleological Software, LLC
View GitHub Profile
@teleological
teleological / ffi1.rb
Created April 29, 2011 13:23
FFI internals 1
require 'ffi'
module RubyInternals
extend FFI::Library
ffi_lib(FFI::CURRENT_PROCESS)
end
@teleological
teleological / ffi2.rb
Created April 29, 2011 13:33
FFI internals 2
module RubyInternals
attach_variable :ptr_vm_core, :rb_mRubyVMFrozenCore, :pointer
end
@teleological
teleological / ffi3.rb
Created April 29, 2011 13:36
FFI internals 3
module RubyInternals
attach_function :const_def_pointer, :rb_define_const,
[:pointer, :string, :pointer], :void
attach_variable :ptr_object_class, :rb_cObject, :pointer
const_def_pointer(ptr_object_class, "RubyCore", ptr_vm_core)
end
@teleological
teleological / ffi4.rb
Created April 29, 2011 13:37
FFI internals 4
module RubyInternals
def define_iseq_singleton_method(mod,sel,iseq)
mod.module_eval do
RubyCore.send("core#define_singleton_method",mod,sel,iseq)
end
end
end
@teleological
teleological / ffi5.rb
Created April 29, 2011 13:38
FFI internals 5
module Greeter
extend RubyInternals
iseq = RubyVM::InstructionSequence.compile <<-RUBY
puts "Hello, world."
RUBY
define_iseq_singleton_method(self, :greet, iseq)
end
@teleological
teleological / ffi6.rb
Created April 29, 2011 13:47
FFI internals 6
require 'ffi'
module RubyInternals
extend FFI::Library
ffi_lib(FFI::CURRENT_PROCESS)
attach_variable :ptr_vm_core, :rb_mRubyVMFrozenCore, :pointer
attach_function :const_def_pointer, :rb_define_const,
[:pointer, :string, :pointer], :void
@teleological
teleological / make_following_list.rb
Created February 14, 2012 19:36
How to make a Twitter list from a list of tweeps someone is following using ruby and twitter gem
require 'rubygems'
require 'twitter'
follower = ARGV[0] || raise("USAGE: #$0 <follower_name> [list_name]")
list_name = ARGV[1] || ("FollowedBy" + follower.upcase)
# Requires read-write token
CONSUMER_KEY = YOUR_CONFIG_HERE
CONSUMER_SECRET = YOUR_CONFIG_HERE
OAUTH_TOKEN = YOUR_CONFIG_HERE
var iphost = "http://api.hostip.info/get_json.php";
var countryhost = "http://api.hostip.info/get_json.php?ip=";
function getIP() {
return $.ajax({
type: 'GET',
url: iphost,
dataType: 'json'
});
}
congress=# select d.state, d.cong_dist, n.state, n.cong_dist from cgd113p010g d join cgd113p010g n on ST_Touches(d.geom, n.geom) order by d.state, d.cong_dist, n.state, n.cong_dist;
state | cong_dist | state | cong_dist
----------------------+-----------+----------------------+-----------
Alabama | 01 | Alabama | 02
Alabama | 01 | Alabama | 07
Alabama | 01 | Florida | 01
Alabama | 01 | Mississippi | 04
Alabama | 02 | Alabama | 01
Alabama | 02 | Alabama | 03
Alabama | 02 | Alabama | 06

Keybase proof

I hereby claim:

  • I am teleological on github.
  • I am teleological (https://keybase.io/teleological) on keybase.
  • I have a public key ASBCsw5qW2n-gbGU8HneNtWGE7Gw8Uxeac877bRhRXhZZwo

To claim this, I am signing this object: