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
#encoding: utf-8 | |
import sys #para operaciones sobre el sistema | |
from inspect import getargspec #para reflexión: http://docs.python.org/library/inspect.html | |
def search(linea, criterio): | |
if criterio in linea: | |
#aquí usamos formato con nombres, es más explícito que el formato que ya conocíamos | |
print "Encontrado '%(criterio)s' en '%(linea)s'" % {'criterio': criterio, 'linea': linea.strip()} | |
return linea |
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
import json | |
from rojoverdeajo.espaciofisico.models import zona | |
#obtener todas las zonas | |
zonas = Zona.objects.all() | |
#construir una lista de diccionarios que representen a las zonas | |
lista = [{'pk': zona.pk, 'zona': zona.zona} for zona in zonas] | |
#convertir eso en un json |
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 'sinatra' | |
enable :sessions | |
#cf: http://rack.rubyforge.org/doc/Rack/Session/Cookie.html | |
class Visits | |
@@global = 0 | |
def self.global; @@global; end | |
def self.add | |
@@global +=1 | |
end |
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
#config/application.rb | |
config.middleware.use "Peekaboo" |
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
gem 'sinatra' | |
gem 'rest-client' | |
gem 'json' #probablemente innecesaria |
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 'gherkin/parser/parser' | |
require 'gherkin/formatter/json_formatter' | |
#This is intended to be mounted on top of a rails app with | |
#mount FakeEndpoints => "/fake_api" | |
#this allows clients to play around with an intended implementation of the API without it being actually coded at all | |
#the features look like | |
# Given I GET /an/endpoint; Then the JSON response is: | |
class FakeEndpoints | |
def initialize | |
@routes = gather_routes |
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
eval( | |
(%w[ | |
1 0 | |
1 0 0 | |
]).zip(%w[ | |
o d | |
e v n | |
]).map{ |(to, fro)| | |
%Q{ | |
#{to}.upto(9) do |#{fro}| |
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
//The fun solution: using array methods | |
var ary = []; | |
for(var i = 1; i <= 1000; i++){ ary.push(i); } | |
console.log( | |
ary.filter(function(item){ | |
return (item % 3 == 0 || item % 5 == 0) | |
}).reduce(function(memo, current){ | |
return memo + current | |
}, 0) | |
); |
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
<html> | |
<head> | |
<meta http-equiv="content-type" content="text/html; charset=utf-8" /> | |
<title>Brainfuck</title> | |
<script type="text/javascript" charset="utf-8"> | |
/* | |
Google HTML5 slides template | |
Authors: Luke Mahé (code) |
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
CREATE TEMPORARY TABLE boxes_to_restore | |
(rebillable_id int(10) unsigned, | |
bh_id int(10) unsigned, | |
billing_frequency tinyint(3) unsigned, | |
prev_cycle_status int(10) unsigned, | |
unique index (rebillable_id), | |
unique index (bh_id)); | |
INSERT INTO boxes_to_restore (rebillable_id, bh_id, billing_frequency, prev_cycle_status) | |
SELECT rs.rebillable_id as rebillable_id, bh2.id as bh_id, rs.billing_frequency as billing_frequency, COALESCE(SUM(ctl.result='success')*100 - SUM(ctl.result='failure'),0) as prev_cycle_status |