Skip to content

Instantly share code, notes, and snippets.

View matiasleidemer's full-sized avatar

Matias H. Leidemer matiasleidemer

View GitHub Profile
function validateDateFormat(dateValue) {
var dateRegex = /^(\d{2})\/(\d{2})\/(\d{4})$/;
var dateOK = true;
if (!dateValue.blank() ) {
if(!dateRegex.test(dateValue)) {
dateOK = false;
} else {
var d = new Date(dateValue.replace(dateRegex, '$2/$1/$3'));
var ok = ( parseInt(RegExp.$2, 10) == (1+d.getMonth()) ) &&
select s.table_name, s.column_name, s.data_type, s.character_maximum_length, s.ordinal_position, s.is_nullable, s.column_default, x.conname, x.rel_table
from information_schema.columns s
left join
(
SELECT p1.relname AS table, a1.attname AS column, c.conname, p2.relname as rel_table
FROM pg_constraint c, pg_namespace n, pg_class p1, pg_class p2, pg_attribute a1, pg_attribute a2,
pg_namespace n2
WHERE
c.contype = 'f'
AND c.confrelid > 0
@matiasleidemer
matiasleidemer / template.rb
Created September 1, 2011 18:41
Meganti's rails template
say "I'm assuming that you have RVM and Ruby 1.8.7 or 1.9.2 installed throught it.\n If not, you should!"
current_ruby = ask("Which version of ruby is configured? 1.8.7 or 1.9.2?")
#create rvmrc file / this was a little tricky (http://stackoverflow.com/questions/3604077/setting-up-rvm-gemset-via-rails-3-template)
run "rvm gemset create #{app_name}"
run "rvm #{current_ruby}@#{app_name} gem install bundler" #we need to install bundler, otherwise we won't be able to run the bundler install
#clean up the Gemfile (I don't like the comments there)
remove_file "Gemfile"
@matiasleidemer
matiasleidemer / lame_batch.sh
Created September 2, 2011 22:29
Lame Bash Script
for song in *.mp3; do lame "${song}" "${song}_128.mp3"; done
@matiasleidemer
matiasleidemer / gist:1225751
Created September 19, 2011 00:17
iOS Tips
iOS Tips
========
- métodos que possuem o prefixo "-" são métodos de instância, enquanto métodos com prefixo "+" são métodos de classe;
- variaveis de instancia e properties sao a "mesma coisa". através de properties, entretanto, é possível usar "dot notation"
- @synthesize gera o getter/setter da propertie automagicamente (entretanto, é possível sobescrever tais métodos, caso necessário)
- int x = eye; (chama a variável de instância diretamente)
@matiasleidemer
matiasleidemer / gist:1329306
Created October 31, 2011 22:52
Ruby 1.9.2 X Ruby 1.9.3

time bundle exec rake

ruby-1.9.2-p290

  • real 1m28.383s
  • user 1m3.491s
  • sys 0m8.299s

ruby-1.9.3-p0

@matiasleidemer
matiasleidemer / gist:1594766
Created January 11, 2012 13:58
PhoneGap Whitelist
<key>ExternalHosts</key>
<array>
<string>localhost</string>
<string>google</string>
</array>
# encoding: UTF-8
class EmailsController < ApplicationController
def plano
@plano = Plano.find(params[:plan_id], include: [:assistencias])
Notifier.plano(params[:recipients], @plano).deliver!
render json: "Email sent successfully", status: :ok
rescue => e
render json: e.message, status: :bad_request
end
@matiasleidemer
matiasleidemer / gist:2989298
Created June 25, 2012 15:34
Como trabalhar com múltiplas contas no heroku

Criar uma nova chave ssh para sua nova conta:

ssh-keygen -t rsa -C "seu_nome@host.com" -f ~/.ssh/id_rsa_sua_conta_heroku

Fazer login na nova conta:

heroku auth:login

Fazer upload da nova chave pública gerada:

# usando @user= dentro de um before(:each)
rspec spec/models/user_spec.rb
.........................................................
Finished in 46.62 seconds
57 examples, 0 failures
Randomized with seed 60306