Skip to content

Instantly share code, notes, and snippets.

View wbotelhos's full-sized avatar
💭
I'm not my code.

Washington Botelho wbotelhos

💭
I'm not my code.
View GitHub Profile
@rodolfoliviero
rodolfoliviero / jstryker
Created September 19, 2011 19:13
JStryker disable Referential Integrity
Coloca isso no @before. Criar uma classe que faz isso ai é só chamar no before de cada classe.
No After faz a mesma coisa.
Connection connection = ConnectionHelper.getConnection();
disableHsqldbDatabaseReferentialIntegrity(connection);
cleanInsert("dataset.xml", connection);
connection.close();
@runemadsen
runemadsen / description.markdown
Created September 26, 2011 15:23
Reverse polymorphic associations in Rails

Polymorphic Associations reversed

It's pretty easy to do polymorphic associations in Rails: A Picture can belong to either a BlogPost or an Article. But what if you need the relationship the other way around? A Picture, a Text and a Video can belong to an Article, and that article can find all media by calling @article.media

This example shows how to create an ArticleElement join model that handles the polymorphic relationship. To add fields that are common to all polymorphic models, add fields to the join model.

@rponte
rponte / db_examples_on_activerecord.rb
Created October 31, 2011 02:35
Disabling referential integrity examples with ruby (and probably rails too)
## ORACLE
def disable_referential_integrity(&block) #:nodoc:
sql_constraints = <<-SQL
SELECT constraint_name, owner, table_name
FROM user_constraints
WHERE constraint_type = 'R'
AND status = 'ENABLED'
SQL
old_constraints = select_all(sql_constraints)
begin
@cmilfont
cmilfont / tbodyScroll.css
Created October 31, 2011 17:51 — forked from henriquegogo/tbodyScroll.css
Scroll on TBODY
table {
display: block;
width: 100%;
}
table thead tr {
display: block;
}
table th,
table td { width: 100px; min-width: 100px; }
table tbody {
@mikeyk
mikeyk / gist:1329319
Created October 31, 2011 22:56
Testing storage of millions of keys in Redis
#! /usr/bin/env python
import redis
import random
import pylibmc
import sys
r = redis.Redis(host = 'localhost', port = 6389)
mc = pylibmc.Client(['localhost:11222'])
@ctoestreich
ctoestreich / gist:1337648
Created November 3, 2011 20:08
Testing storage of millions of keys in Redis using Custom Number Encoder
@Grapes([
@Grab('redis.clients:jedis:1.5.1'),
@GrabConfig(systemClassLoader=true)
])
import redis.clients.jedis.*
performTest("unencoded", null) {n, e->
n.toString()
}
@ctoestreich
ctoestreich / gist:1337772
Created November 3, 2011 21:02
Custom Number Encoder Memory Storage Size Test
def r = new Random()
def num = r.nextInt(12000000).toString()
println num
println num.bytes.length
println encodeNumber(num, getEncoder())
println encodeNumber(num, getEncoder()).bytes.length
def getEncoder(){
['1','2','3','4','5','6','7','8','9','0','-','=','!','@','#','$','%','^','&','*','(',')','_',
'+','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',
@bkimble
bkimble / gist:1365005
Last active August 22, 2024 14:21
List local memcached keys using Ruby
#!/usr/bin/env ruby
# List all keys stored in memcache.
# Credit to Graham King at http://www.darkcoding.net/software/memcached-list-all-keys/ for the original article on how to get the data from memcache in the first place.
require 'net/telnet'
headings = %w(id expires bytes cache_key)
rows = []
@rponte
rponte / normalize.js
Created November 19, 2011 00:30
normalize.js
// Created by Nando Vieira
String.prototype.normalize = function() {
var from = "àáâãäåæçèéêëìíîïðñòóôõöøùúûüýþßàáâãäåæçèéêëìíîïðñòóôõöøùúûýýþÿŕŕ";
var to = "aaaaaaaceeeeiiiidnoooooouuuuybsaaaaaaaceeeeiiiidnoooooouuuyybyrr";
var value = this;
for(var i = 0; i < from.length; i++) {
char_re = new RegExp(from.charAt(i), "gim");
value = value.replace(char_re, to.charAt(i))
};
@dblock
dblock / oauth_controller.rb
Created December 11, 2011 15:16
An updated OAuth2 controller for a Rails app (implies you have ClientApplication and AccessGrant)
class OauthController < ApplicationController
class ApiOAuthError < StandardError
attr_accessor :code, :description, :uri, :state
def initialize(code, description, uri = nil, state = nil)
@code = code
@description = description
@uri = uri