Skip to content

Instantly share code, notes, and snippets.

require 'dm-core'
require 'dm-sqlite-adapter'
db_path = 'sqlite:///Users/knowtheory/data/chat/skype_main.db'
DataMapper.setup(:default, db_path)
# CREATE TABLE Accounts (id INTEGER NOT NULL PRIMARY KEY,
# is_permanent, Integer
# status, Integer
# pwdchangestatus, Integer
#!/usr/bin/env ruby
require 'kconv'
if ARGV.size < 2
puts <<-HELP
HELP:
ruby concat_csv.rb [number of header rows] [list of files with identical headers]
e.g.
ruby concat_csv.rb 2 census2005_miyagi_age/*C*.txt
HELP
exit
require 'dm-core'
require 'dm-validations'
require 'dm-tags'
module Confoosed
class Speaker
include DataMapper::Resource
property :id, Serial
property :name, String, :length => 255
D/dalvikvm( 766): GC_EXPLICIT freed 2200 objects / 90728 bytes in 90ms
D/dalvikvm( 188): GC_EXPLICIT freed 3333 objects / 190232 bytes in 76ms
D/WifiService( 87): acquireWifiLockLocked: WifiLock{NetworkLocationProvider type=2 binder=android.os.Binder@44d15248}
D/LocationMasfClient( 87): getNetworkLocation(): Returning cache location with accuracy 58.0
D/WifiService( 87): releaseWifiLockLocked: WifiLock{NetworkLocationProvider type=2 binder=android.os.Binder@44d15248}
I/WindowManager( 87): Setting rotation to 3, animFlags=0
I/ActivityManager( 87): Config changed: { scale=1.0 imsi=310/260 loc=en_US touch=3 keys=1/1/2 nav=3/1 orien=2 layout=34 uiMode=17 seq=12}
I/UsageStats( 87): Unexpected resume of com.android.settings while already resumed in com.android.settings
D/dalvikvm( 87): GC_EXTERNAL_ALLOC freed 18388 objects / 869528 bytes in 89ms
D/dalvikvm( 87): GC_EXPLICIT freed 1958 objects / 94368 bytes in 102ms
caelesta:wifi_detector knowtheory$ rake install
(in /Users/knowtheory/Code/ruby/wifi_detector)
Android SDK Tools Revision 10
Project Target: Android 2.2
API level: 8
------------------
Resolving library dependencies:
No library dependencies.
@knowtheory
knowtheory / Dead simple legacy data access with DataMapper.mdown
Created February 18, 2011 03:57
See how DataMapper is perfect for extracting data from legacy stores without backflips, kungfu, or dangerous acrobatics. You can even use your data extraction models directly in web apps without any fuss.

Abstract

Ruby and Rails are well known for greenfield development, and sits amongst the top choices for startups. However, the expanded world of open data sources, and enterprise Ruby, there's a lot more to life than dreaming up new web apps. But when (not if) you deal with pre-existing data, why spend all your time writing brittle one off shims to translate your data from your legacy store? Why not rely on a robust and well designed Ruby library like DataMapper? DataMapper will let you write readable and natural Ruby code to access data of all types. Your legacy models will be a delight to work with. Use them directly in your web app if you like!

Technically speaking, DataMapper allows for different modeling tasks than ActiveRecord or Sequel. DataMapper is highly customizeable, allowing users to override and redefine naming conventions, key and field mappings at whatever granularity users may desire (from individual fields all the way up to global table mapping). This ability coupled with DataM

require 'dm-core'
require 'dm-sweatshop'
require 'dm-migrations'
class Foo
include DataMapper::Resource
property :id, Serial
property :name, String
property :sku, String
@knowtheory
knowtheory / datamapper_composite_index.rb
Created February 15, 2011 02:16
Demonstrating how to do composite indexes in DataMapper
require 'dm-core'
require 'dm-migrations'
DataMapper.setup(:default, "mysql://localhost/test")
class TotallyContrivedForThisExample
include DataMapper::Resource
property :id, Serial # already part of the primary key
property :plerp, String, :key => true # Adds this to the primary key
require 'dm-core'
require 'dm-validations'
require 'dm-aggregates'
require 'dm-types'
require 'dm-migrations'
# See chromium/src/base/{time.h,time_mac.cc}
begin
# provide Time#utc_time for DateTime#to_time in AS
ruby-1.9.2-p0 :006 > visits = Visit.all('visit_time.gte' => DateTime.now.midnight.prev_day.prev_day, 'visit_time.lt' => DateTime.now.midnight.prev_day); ''
=> ""
ruby-1.9.2-p0 :010 > urls = visits.map(&:url); ''
EXPECTED: 1297486800 # this is some debug output i put in dm-core
RECORD_VALUE 2011-02-12 08:31:17 -0500 # this is some debug output i put in dm-core
ArgumentError: comparison of Time with 1297486800 failed
from /Users/knowtheory/.rvm/gems/ruby-1.9.2-p0/gems/dm-core-1.0.2/lib/dm-core/query/conditions/comparison.rb:866:in `>='
from /Users/knowtheory/.rvm/gems/ruby-1.9.2-p0/gems/dm-core-1.0.2/lib/dm-core/query/conditions/comparison.rb:866:in `matches?'
from /Users/knowtheory/.rvm/gems/ruby-1.9.2-p0/gems/dm-core-1.0.2/lib/dm-core/query/conditions/operation.rb:461:in `block in matches?'
from /Users/knowtheory/.rvm/gems/ruby-1.9.2-p0/gems/dm-core-1.0.2/lib/dm-core/query/conditions/operation.rb:159:in `block in each'