Skip to content

Instantly share code, notes, and snippets.

View nrk's full-sized avatar
🤔
はい、猫のように見えます。

Daniele Alessandri nrk

🤔
はい、猫のように見えます。
View GitHub Profile
@nrk
nrk / runtest.io
Created July 24, 2008 15:42
just a quick test of Io's unit testing facility
// runtest.io
TestSuite clone setPath(System launchPath) run
@nrk
nrk / messageManipulation001.io
Created July 25, 2008 06:50
Message manipulation at runtime in Io
foo := block(str,
str asMutable asCapitalized println
)
foo call("my awesome string") // ==> My awesome string
foo message // ==> str asMutable asCapitalized println
foo message next // ==> asMutable asCapitalized println
foo message next next // ==> asCapitalized println
adaniele@nutcracker:~/ironruby$ mono bin/ir.exe
IronRuby 1.0.0.1 on .NET 2.0.50727.42
Copyright (c) Microsoft Corporation. All rights reserved.
Note that local variables do not work today in the console.
As a workaround, use globals instead (eg $x = 42 instead of x = 42).
>>> puts 'hello'
hello
=> nil
@nrk
nrk / tumblr_read_json.io
Created August 20, 2008 14:32
Parsing posts from tumblr using JSON
// Parsing posts from tumblr using JSON
JSON
Regex
Map squareBrackets := method(
return self at(call evalArgs at(0))
)
URL with("http://staff.tumblr.com/api/read/json") fetch findRegex("^var tumblr_api_read = (.*);\s*$") ?at(1) fromJSON ["posts"] foreach(post, post ["type"] println)
@nrk
nrk / tumblr_read_json.lua
Created August 20, 2008 15:13
This is the same as http://gist.github.com/6376 but written in Lua
http = require "socket.http"
require "json"
local json_res = http.request("http://staff.tumblr.com/api/read/json")
local tumblr = json.decode(string.match(json_res, "^var tumblr_api_read = (.*);%s*$"))
for _, post in ipairs(tumblr.posts) do print(post.type) end
--[[ **** OUTPUT ****
@nrk
nrk / gist:8100
Created August 30, 2008 09:13
Win32API.so ported to IronRuby: first (barely) working bits
IronRuby 1.0.0.0 on .NET 2.0.50727.1433
Copyright (c) Microsoft Corporation. All rights reserved.
Note that local variables do not work today in the console.
As a workaround, use globals instead (eg $x = 42 instead of x = 42).
>>> require 'mscorlib'
=> true
>>> require 'Win32API'
=> true
@nrk
nrk / dump_from_irb_console.txt
Created September 2, 2008 18:32
Win32API.so ported to IronRuby
irb(main):001:0> require 'Win32API'
=> true
irb(main):002:0> $get_logical_drives = Win32API.new('kernel32', 'GetLogicalDriveStrings', ['P', 'P'], 'I')
=> #<Win32API:0x2e2a200>
irb(main):003:0> $buffer = ' ' * 32
=> " "
irb(main):004:0> $length = $get_logical_drives.call($buffer.length, $buffer)
=> 16
irb(main):005:0> $buffer
=> "A:\\\000C:\\\000D:\\\000S:\\\000\000 "
@nrk
nrk / win32_map_network_drive.rb
Created September 7, 2008 19:22
How to map a network share in Windows with Ruby & Win32API
require 'Win32API'
module NetworkDrive
CONNECT_UPDATE_PROFILE = 0x1
RESOURCE_CONNECTED = 0x1
RESOURCE_GLOBALNET = 0x2
RESOURCETYPE_DISK = 0x1
RESOURCEDISPLAYTYPE_SHARE = 0x3
RESOURCEUSAGE_CONNECTABLE = 0x1
@nrk
nrk / httparty_couchdb.rb
Created September 23, 2008 10:57
A simple CouchDB client with HTTParty
require 'httparty'
class CouchDB
include HTTParty
base_uri '172.22.107.12:5984'
format :json
def self.info
get '/'
@nrk
nrk / https_post.rb
Created September 23, 2008 16:30
Post form data using https
require 'net/http'
require 'net/https'
post_url = URI.parse('https://my.host.name/path/to/post')
request = Net::HTTP::Post.new(post_url.path)
request.set_form_data({
'name' => 'nrk',
'test' => '1',
# ...