This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Node A: | |
| # iex --sname "nodea" | |
| Process.register self, :iex | |
| # Blocking | |
| receive do | |
| { :hello, pid } -> | |
| IO.puts "Hello from #{inspect(pid)}" | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| defmodule Future do | |
| def new(fun) do | |
| fn(x) -> | |
| spawn_link fn -> | |
| value = try do | |
| { :ok, fun.(x) } | |
| rescue | |
| e -> { :error, e } | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| graph = {} | |
| ObjectSpace.each_object(Class) do |klass| | |
| sup = klass.superclass and graph[klass] = sup | |
| end | |
| puts "digraph{" | |
| graph.map do |key, value| | |
| puts %("#{key}"\n"#{key}"->"#{value}") | |
| end | |
| puts"}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Square < Rectangle | |
| def initialize(side) | |
| @side = side | |
| end | |
| def height | |
| @side | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class CreateUsers < ActiveRecord::Migration | |
| def change | |
| create_table :users do |t| | |
| t.string :name | |
| t.timestamps | |
| end | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| search_id | rank | property_id | price | |
|---|---|---|---|---|
| 3 | 1 | 8011 | 3787 | |
| 4 | 1 | 326 | 752 | |
| 5 | 1 | 7973 | 780 | |
| 5 | 2 | 87 | 13580 | |
| 5 | 3 | 5265 | 19920 | |
| 6 | 1 | 5981 | 8349 | |
| 7 | 1 | 5814 | 6585 | |
| 9 | 1 | 3942 | 14780 | |
| 10 | 1 | 6925 | 11286 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # [X] length/size | |
| # [X] push | |
| # [X] [] (slice) | |
| # [X] pop | |
| # [X] first | |
| # [X] last | |
| # [X] shift | |
| # [X] unshift | |
| # [X] each | |
| # [X] select/reject/collect/inject |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| a = 1 # one | |
| b = a - 1 # zero | |
| (b..a).include?(a) #=> true | |
| (b..a).include?(a.to_f) #=> true | |
| (b..a).include?(0.5) #=> true | |
| a = DateTime.now # now | |
| b = a - 1 # 24 hours ago | |
| (b..a).include?(a) #=> true | |
| (b..a).include?(a.to_date) #=> false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var server = require('http').createServer(serveFile); | |
| var fs = require('fs'); | |
| var ntwitter = require("ntwitter"); | |
| var io = require('socket.io').listen(server); | |
| function serveFile(request, response){ | |
| fs.readFile(__dirname + '/index.html', function(error, data){ | |
| if(error) { | |
| response.writeHead(404, {'Content-Type': 'text/html'}); | |
| response.write("<html><body>No drank for you!</body></html>"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var ntwitter = require("ntwitter"); | |
| var client = new ntwitter({ | |
| consumer_key: process.env["TWITTER_CONSUMER_KEY"], | |
| consumer_secret: process.env["TWITTER_CONSUMER_SECRET"], | |
| access_token_key: process.env["TWITTER_ACCESS_TOKEN"], | |
| access_token_secret: process.env["TWITTER_ACCESS_SECRET"] | |
| }); | |
| var coffee, tea, wine, beer, water; |