Skip to content

Instantly share code, notes, and snippets.

View beccasaurus's full-sized avatar

Rebecca Taylor beccasaurus

View GitHub Profile
$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"
# 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
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
%w[ rubygems sinatra haml ].each {|lib| require lib }
get '/' do
"Hello World! The time is now #{ Time.now }"
end
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());
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
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
@beccasaurus
beccasaurus / factorial.cs
Created October 30, 2010 23:12
Factorial in C# and Ruby (loop vs recursion)
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;
%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.
@beccasaurus
beccasaurus / CheckIfPortIsAvailable.cs
Created November 27, 2010 21:43
CheckIfPortIsAvailable C#
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);