Skip to content

Instantly share code, notes, and snippets.

View Fonsan's full-sized avatar

Erik Fonselius Fonsan

View GitHub Profile
require 'socket'
puts "Please enter host:"
hostname = STDIN.gets.chop # Read host and remove the newline
port = 80
s = TCPSocket.open(hostname, port)
s.write("HEAD / HTTP/1.0\n")
require 'socket'
puts "Please enter host:"
hostname = STDIN.gets.chop # Read host and remove the newline
port = 80
s = TCPSocket.open(hostname, port)
s.write("HEAD / HTTP/1.0\n")
link_to raw("We" + image_tag('heart.png') + " Feedback")
# generates
# <a class="footer_link" href="/feedback">We&lt;img alt="Heart" src="/images/heart.png?1297276993" /&gt; Feedback</a>
#include <CoreServices/CoreServices.h>
static void callback(ConstFSEventStreamRef streamRef,
void *clientCallBackInfo,
size_t numEvents,
void *eventPaths,
const FSEventStreamEventFlags eventFlags[],
const FSEventStreamEventId eventIds[]) {
exit(0);
}
@Fonsan
Fonsan / router.rb
Created March 13, 2011 17:09
Ugly non threadsafe way of routing a subdomain to a controller
class SupportSubdomain
def self.subdomain
@@request.subdomain.to_sym rescue :not_found
end
def self.matches?(request)
@@request = request
request.path_parameters[:controller] = request.subdomain
Rails.logger.info request.path_parameters[:controller]
@Fonsan
Fonsan / Debugger.rb
Created May 13, 2011 08:57
Has many through 3.1 beta
(rdb:1) pp o
#<Arel::Nodes::SelectCore:0x000001056b0638
@groups=[],
@having=nil,
@projections=
[#<struct Arel::Attributes::Attribute
relation=
#<Arel::Table:0x000001056aea68
@aliases=[],
@columns=nil,
module MetaSearch
module Helpers
module UrlHelper
def order_indicator_for(order)
if order == 'asc'
'&#9650;' # replace this with a string or nil
elsif order == 'desc'
'&#9660;' # replace this with a string or nil
else
@samples = 10.times.map do rand(10) end
result = @samples.inject( Hash.new(0) ) do |hash,element|
hash[element] += 1
hash
end.to_a # => [[6, 3], [3, 1], [1, 1], [9, 2], [4, 2], [8, 1]]
@Fonsan
Fonsan / test.patch
Created May 29, 2011 15:53
default_scope select 3.1 aggregation
Form.count
(0.4ms) SELECT forms.id, forms.name, forms.created, forms.user_id, forms.category_id, forms.active_status, forms.read_only, forms.example_interview_id, COUNT(*) FROM `forms`
=> 1
> Form.unscoped.count
(0.2ms) SELECT COUNT(*) FROM `forms`
=> 4
> Form.unscoped.select("name").count
(0.3ms) SELECT COUNT(`forms`.`name`) FROM `forms`
=> 4
@Fonsan
Fonsan / Gemfile
Created June 10, 2011 13:22
Failing 2.0pre
source 'http://rubygems.org'
gem 'sinatra'
gem 'erubis'
gem 'shotgun'