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_lambda = lambda { return } | |
def method_with_a_lambda | |
puts "lambda START" | |
begin | |
$a_lambda.call | |
rescue Exception => ex | |
puts " raised exception: #{ex}" | |
return | |
end | |
puts "lambda 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
# Because dm-ar-finders likes to fuck your mother | |
module DataMapper::Model | |
def method_missing_with_less_stupidity name, *args, &block | |
extension_response = FactoryGirlExtensions.__method_missing(self, name, *args, &block) | |
if extension_response == :no_extension_found | |
super | |
else | |
extension_response | |
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
rails dm_rails3_app -m http://github.com/snusnu/rails-templates/raw/master/dm_rails_master.rb | |
create | |
create README | |
create .gitignore | |
create Rakefile | |
create config.ru | |
create Gemfile | |
create app | |
create app/helpers/application_helper.rb | |
create app/controllers/application_controller.rb |
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
%w[ rubygems sinatra haml ].each {|lib| require lib } | |
get '/' do | |
"Hello World! The time is now #{ Time.now }" | |
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
import java.net.URL; | |
import org.openqa.selenium.By; | |
import org.openqa.selenium.WebDriver; | |
import org.openqa.selenium.WebElement; | |
import org.openqa.selenium.remote.RemoteWebDriver; | |
import org.openqa.selenium.remote.DesiredCapabilities; | |
public class Example { | |
public static void main(String[] args) throws java.net.MalformedURLException, java.lang.Exception { | |
WebDriver driver = new RemoteWebDriver(new URL("http://127.0.0.1:4444/wd/hub/"), DesiredCapabilities.firefox()); |
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 Hash | |
def method_missing name, *args | |
if name.to_s =~ /=$/ # eg. @hash.foo = 'bar' | |
self[$`.to_s] = args.first | |
else | |
if args.empty? | |
self[name.to_s] # eg. @hash.foo | |
else | |
super # anything else ... fall back to super | |
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
require 'rubygems' | |
require 'restclient' | |
require 'nokogiri' | |
require 'sequel' | |
DB = Sequel.sqlite 'course-stuff.sqlite' | |
html = RestClient.get 'https://webapp4.asu.edu/catalog/classlist?s=&t=2109&e=open&hon=F' | |
doc = Nokogiri::HTML(html) | |
unless DB.tables.include? :courses |
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
using System; | |
using System.Diagnostics; | |
using System.Runtime.CompilerServices; | |
public class Factorial { | |
public static void Main(string[] args) { | |
string method = (args.Length > 0) ? args[0] : null; | |
long number = (args.Length > 1) ? Int64.Parse(args[1]) : 1; | |
int times = (args.Length > 2) ? Int32.Parse(args[2]) : 1; |
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
%w[ rubygems nokogiri open-uri ].each {|lib| require lib } | |
# Usage: | |
# MyClass = make_me_a_class "http://some/url" | |
# | |
# See the irb-example.rb below | |
# | |
# Note: you don't *have* to set a constant with this method but | |
# if you just use a regular variable, the class won't know | |
# it's name. Ruby classes get their name from their constant's name. |
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
using System; | |
using System.Net; | |
using System.Net.Sockets; | |
public class CheckIfPortIsAvailable { | |
public static bool IsAvailable(int portNumber) { | |
var localhost = (IPAddress) Dns.GetHostAddresses("localhost")[0]; | |
try { | |
var sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); |