Skip to content

Instantly share code, notes, and snippets.

@BenHall
BenHall / gist:bab721dfba3b32c36f88
Created May 28, 2015 13:45
Adding in JavaScript
> var total = 0
undefined
> total += 4.4
4.4
> total += 4.4
8.8
> total += 4.4
13.200000000000001
var total = 0.0
undefined
> ping 172.17.5.108
PING 172.17.5.108 (172.17.5.108) 56(84) bytes of data.
64 bytes from 172.17.5.108: icmp_seq=1 ttl=64 time=0.094 ms
64 bytes from 172.17.5.108: icmp_seq=2 ttl=64 time=0.063 ms
64 bytes from 172.17.5.108: icmp_seq=3 ttl=64 time=0.063 ms
^C
--- 172.17.5.108 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 1999ms
rtt min/avg/max/mdev = 0.063/0.073/0.094/0.016 ms
routes.rb
map.term ':term', :controller => 'conference', :action => 'index'
index.rhtml
<% form_for :term, :url => { :controller => :conference, :action => :index }, :html => {:method => :get} do |f| %>
<input type="text" name="term" id="search" size="50" />
<input type="submit" value="Submit" id="submit" />
<% end %>
@BenHall
BenHall / My First Test
Created September 28, 2009 13:52
My first gist
public static string Test()
{
return "abc";
}
@BenHall
BenHall / Mongo_Controller.rb
Created October 25, 2009 10:13
using mongomapper with ruby on rails
class HomeController < ApplicationController
def index()
post = Post.create({
:title => 'John'
})
post.save
@posts = Post.find(:all)
end
@BenHall
BenHall / Automated RubyGem Install
Created November 16, 2009 17:23
How to install RubyGems via an automated ruby script
#!c:/ruby/bin/ruby.exe
require 'rubygems'
require 'rubygems/gem_runner'
require 'rubygems/exceptions'
def install(lib)
begin
Gem::GemRunner.new.run ['install', lib]
rescue Gem::SystemExitException => e
end
@BenHall
BenHall / xunit.msbuild
Created November 22, 2009 00:42
XUnit Build
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<UsingTask
AssemblyFile="3rdParty\CodePlex.MSBuildTasks.dll"
TaskName="CodePlex.MSBuildTasks.RegexReplace"/>
<UsingTask
AssemblyFile="3rdParty\CodePlex.MSBuildTasks.dll"
TaskName="CodePlex.MSBuildTasks.Unzip"/>
<UsingTask
AssemblyFile="3rdParty\CodePlex.MSBuildTasks.dll"
require 'net/http' => true
require 'uri'
res = Net::HTTP.post_form(URI.parse('http://gist.github.com/api/v1/xml/new'), { 'files[file1.rb]' => "puts 'Hello World!'", 'files[file2.rb]' => "puts 'Gists example'"})
puts res.body
#http://gist.github.com/240755
@BenHall
BenHall / Ruby Format
Created November 22, 2009 22:45
String format in Ruby
str = "a%sb%sc%s"
str % ['_', '/', '.']
=> "a_b/c."
@BenHall
BenHall / YieldBlock.rb
Created November 27, 2009 15:20
Yield a block of code in Ruby
def x()
yeild
end
x { puts 'abc' }