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
| #!/usr/bin/env ruby | |
| # A toy program demonstrating consuming REST API and quering and | |
| # inserting documents to MongoDB database with Ruby and its standard | |
| # library without extra dependencies. | |
| # | |
| # Usage: | |
| # | |
| # $ mongod # leave it running | |
| # |
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
| (defun tkareine/active-region-or-line () | |
| (if mark-active (list (region-beginning) (region-end)) | |
| (list (line-beginning-position) | |
| (line-beginning-position 2)))) | |
| (defun tkareine/comment-or-uncomment-region-or-line () | |
| (interactive) | |
| (let ((region (tkareine/active-region-or-line))) | |
| (when region | |
| (let ((rbegin (car region)) |
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
| package org.tkareine.demo.service.csv.parser; | |
| import com.google.inject.Inject; | |
| import org.tkareine.demo.model.Address; | |
| import org.tkareine.demo.model.Office; | |
| import org.tkareine.demo.service.OfficeService; | |
| import org.tkareine.demo.support.GuiceJUnit4ClassRunner; | |
| import org.tkareine.demo.support.di.StubExternalServicesMongoModule; | |
| import org.junit.Before; | |
| import org.junit.Test; |
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
| #!/usr/bin/env ruby | |
| puts "from original executable, args: #{ARGV.join(" ")}" |
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
| require "pstore" | |
| module Notes | |
| class << self | |
| attr_accessor :store_location | |
| def put_note(id, note) | |
| store.transaction do | |
| store[:notes] ||= {} | |
| store[:notes][id] = note |
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
| #!/usr/bin/env ruby | |
| def exit_upon(*signals) | |
| process_going_down = false | |
| signals.map { |signal| signal.to_s.upcase }.each do |signal| | |
| Signal.trap(signal) do | |
| exit! if process_going_down # terminate if still executing the given block | |
| process_going_down = true | |
| yield(signal) if block_given? | |
| exit! 0 |
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
| # coding: utf-8 | |
| SIZE = ARGV.shift.to_i | |
| FILENAME = ARGV.shift | |
| if SIZE < 1 || FILENAME.nil? | |
| puts "Usage: ruby #{File.basename(__FILE__)} <size> <file>" | |
| exit 1 | |
| 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
| # coding: utf-8 | |
| # Test global state changing code with fork | |
| # | |
| # * You should avoid having global state altogether | |
| # * That said, if you cannot avoid it, for one reason or another, | |
| # you can execute state changing code in a child process | |
| # * Fork a child process, execute state changing code there | |
| # * The forked child process has its own memory space, separate | |
| # from the parent process |
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
| function withBeforeAll(tests) { | |
| var beforeAllCalled = false | |
| var helpers = { | |
| beforeAll: function (fun) { | |
| beforeEach(function () { | |
| if (beforeAllCalled) return | |
| fun() | |
| runs(function () { beforeAllCalled = true } ) | |
| }) |
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
| (ns pi-estimation | |
| "See Opinion 18 in <http://programmers.blogoverflow.com/2012/08/20-controversial-programming-opinions/>") | |
| ;; Given that Pi can be estimated using the function 4 * (1 – 1/3 + 1/5 | |
| ;; – 1/7 + …) with more terms giving greater accuracy, write a function that | |
| ;; calculates Pi to an accuracy of 5 decimal places.) | |
| ;; with lazy-seq | |
| (defn odds [] |
OlderNewer