This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// app/classes/myrules.php | |
class MyRules | |
{ | |
// note this is a static method | |
public static function _validation_unique($val, $options) | |
{ | |
list($table, $field, $id) = explode('.', $options); | |
$result = DB::select("LOWER (\"$field\")", 'id') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rails_helper' | |
feature "Login" do | |
background do | |
#Factory Girl | |
@user = create(:user) | |
end | |
scenario "With correct credentials" do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
npm config set registry https://registry.npmjs.org/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe HappyNumber do | |
it "Is possible to chek if a number is happy?" do | |
happy_number = HappyNumber.new | |
expect(happy_number.happy?(7)).to be true | |
end | |
end | |
#happy_number.rb | |
class HappyNumber | |
def happy?(number) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Recebe a função soma como argumento (f = soma) | |
def meu_decorator(f): | |
#Escreve uma nova função | |
#nova_soma recebe os mesmos argumentos da soma (não precisa ser *args) | |
#Imagine que é uma nova versão da sua soma | |
def nova_soma(x,y): | |
#Executa algo antes | |
print 'iniciando nova soma' | |
f(x,y) #Chama a própria função soma (a soma externa) | |
#Executa algo depois |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
#Exemplo de *args e **kwargs (argumentos ilimitados, nomeados e em qualquer ordem) | |
class Conta(): | |
#É precico passar o self para dentro dos métodos de instância | |
#O Python é bem explícito :) | |
def metodo(self, *args, **kwargs): | |
print args | |
print kwargs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Exemplo de for super legal utilizando Scala | |
object Laco{ | |
//main (um pouquinho diferente do java) | |
def main(args: Array[String]){ | |
for{ | |
/* | |
Para cada 5 incrementos em i vai haver 1 incremento em j | |
Quando i chegar a 5 vai resetar seu contador para 1 e j vai incrementar para 2 | |
E assim sucessivamente... ate j chegar a 5 | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//mdc (PHP 5.3) | |
$mdc = function($x,$y) use (&$mdc){ | |
$a = max($x,$y); | |
$b = min($x,$y); | |
return ($a%$b == 0) ? ($b) : ($mdc($b,($a%$b))); | |
}; | |
//mmc (PHP 5.3) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<!-- jquery CDN --> | |
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"> | |
</script> | |
<script type="text/javascript"> | |
$(function(){ | |
//Verifica se temos acesso ao recurso |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//Content-Type do tipo stream | |
header('Content-Type: text/event-stream'); | |
//Sem cash | |
header('Cache-Control: no-cache'); | |
//Inicia uma função | |
function send_msg($msg) { | |
//Envia um json | |
echo 'data:'.json_encode(array('id' => rand(0,100), 'msg' => $msg)); | |
//Descarrega o buffer de saída |
OlderNewer