Skip to content

Instantly share code, notes, and snippets.

View ddeaguiar's full-sized avatar

Daniel De Aguiar ddeaguiar

  • Nubank
  • Miami, Fl
View GitHub Profile
require 'rubygems'
require 'activesupport' # => true
$KCODE='UTF8' # => "UTF8"
s = 'Peña'
t = 'PEÑA'
s.chars.downcase.to_s # => "peña"
t.chars.downcase.to_s # => "peña"
s.chars.downcase.to_s.eql?(t.chars.downcase.to_s) # => true
%w(edit new formatted).each do |action|
module_eval <<-EOT, __FILE__, __LINE__
def #{action}_polymorphic_url(record_or_hash, options = {})
polymorphic_url(record_or_hash, options.merge(:action => "#{action}"))
end
def #{action}_polymorphic_path(record_or_hash, options = {})
polymorphic_url(record_or_hash, options.merge(:action => "#{action}", :routing_type => :path))
end
EOT
public void testInject() {
List ints = Arrays.asList(new Integer[]{new Integer(1), new Integer(2), new Integer(3)});
SumAccumulator acc = new SumAccumulator();
CollectionUtils.forAllDo(ints, acc);
assertEquals(6, acc.result);
}
static class SumAccumulator implements Closure {
public int result;
public void execute(Object arg0) {
//it requires reflection...how unfortunate.
public List getKeys() {
Cache cache = getCacheAdministrator().getCache();
try {
Field mapField = cache.getClass().getDeclaredField("cacheMap");
mapField.setAccessible(true);
LRUCache map = (LRUCache) mapField.get(cache);
return new ArrayList(map.keySet());
} catch (Exception e) {
log.error(e);
select
CASE
WHEN (REGEXP_SUBSTR(category, '(a[[:alnum:]]|sa)', 1, 1, 'i') is not null) THEN 'SUITE'
WHEN (REGEXP_SUBSTR(category, '(d[[:digit:]]|sd)', 1, 1, 'i') is not null) THEN 'DELUXE_BALCONY'
WHEN (REGEXP_SUBSTR(category, '(b[[:alnum:]]|sb)', 1, 1, 'i') is not null) THEN 'BALCONY'
WHEN (REGEXP_SUBSTR(category, '(c|d|e|f|g|h)[[:alnum:]]?', 1, 1, 'i') is not null) THEN 'OCEANVIEW'
ELSE 'INTERIOR'
END AS META
from foo
# Sample file encryption
function encrypt() {
openssl des3 -salt -in "$1" -out "$2"
}
function decrypt() {
openssl des3 -d -salt -in "$1" -out "$2"
}
#multiruby aliases
alias mr186='export PATH=~/.multiruby/install/1.8.6-p369/bin:$ORIGPATH && which ruby'
alias mr187='export PATH=~/.multiruby/install/1.8.7-p174/bin:$ORIGPATH && which ruby'
alias mr191='export PATH=~/.multiruby/install/1.9.1-p129/bin:$ORIGPATH && which ruby'
alias mree='export PATH=~/.multiruby/install/enterprise-1.8.6-20090610/bin:$ORIGPATH && which ruby'
alias mroff='export PATH=$ORIGPATH && which ruby'
def self.establish_connection(spec = nil)
case spec
when nil
raise AdapterNotSpecified unless defined? RAILS_ENV
establish_connection(RAILS_ENV)
when ConnectionSpecification
@@connection_handler.establish_connection(name, spec)
when Symbol, String
if configuration = configurations[spec.to_s] || configuration = configurations[Rails.env][spec.to_s]
establish_connection(configuration)
<?php
class Foo {
function __construct($method) {
$this->$method = create_function('', 'print "foobar";');
}
public function __call($name, $arguments) {
call_user_func($this->$name, $arguments);
}
diff --git Library/Formula/npm.rb Library/Formula/npm.rb
index 7c7d620..ac2edf9 100644
--- Library/Formula/npm.rb
+++ Library/Formula/npm.rb
@@ -1,9 +1,9 @@
require 'formula'
class Npm <Formula
- url 'http://github.com/isaacs/npm/tarball/v0.1.25'
+ url 'http://github.com/isaacs/npm/tarball/v0.1.27'