This is a simple chat-like program using pub-sub pattern, backed by PostgreSQL's LISTEN/NOTIFY command.
publish message to foo channel from user nickname.
$ python pub.py foo nickname
PUBLISH to channel #foo
| ITEMS = [6,2,2,4].map { |q| {quantity: q} } | |
| KNAPSACKS = [10,4,4].map { |c| {capacity: c} } | |
| N = ITEMS.length | |
| M = KNAPSACKS.length | |
| A = Array.new(N*M, 0) | |
| # [0 1 1 1 [3 | |
| # 1 0 0 0 ----> 1 | |
| # 0 1 0 1] 2] | |
| def sum_rows(x, w) |
| //: Playground - noun: a place where people can play | |
| import UIKit | |
| // generic function using pass by reference | |
| func swap<T>(inout a: T, inout b: T) { | |
| let tempA: T = a | |
| a = b | |
| b = tempA | |
| } |
| # Python boolean fail | |
| # Or how to redefine True and False and win any argument on the internet! | |
| # Love, @tlehman | |
| from unittest import TestCase | |
| class BoolFail(TestCase): | |
| def test_false(self): | |
| True = False | |
| assert True == False |
| puts UDPSocket.open { |s| s.connect('www.example.com', 1); s.addr.last } |
| $ curl -s https://rubygems.org/gems/faraday | ruby -rnokogiri -e "puts Nokogiri::HTML(STDIN.read).css('.gem__desc p').children.first" | |
| HTTP/REST API client library. | |
| $ curl -s https://rubygems.org/gems/nokogiri | ruby -rnokogiri -e "puts Nokogiri::HTML(STDIN.read).css('.gem__desc p').children.first" | |
| Nokogiri (鋸) is an HTML, XML, SAX, and Reader parser. Among Nokogiri's | |
| many features is the ability to search documents via XPath or CSS3 selectors. | |
| XML is like violence - if it doesn’t solve your problems, you are not using | |
| enough of it. |
| # Balanced paren strings have the property that each opening ( has a closing ). | |
| # This proceeds by scanning left to right, using a stack to keep track of open | |
| # parens. | |
| def balanced?(string) | |
| characters = string.split(//) | |
| stack = [] | |
| characters.each do |c| | |
| stack.push(c) if c == "(" | |
| return false if stack.empty? and c == ")" |
I hereby claim:
To claim this, I am signing this object:
| // clever trick from http://stackoverflow.com/a/8618383/46871 | |
| var arraysEqual = function(a,b) { return !!a && !!b && !(a<b || b<a); } |