Skip to content

Instantly share code, notes, and snippets.

@lfborjas
lfborjas / archivos.py
Created December 9, 2010 16:44
ejemplos de python
#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
@lfborjas
lfborjas / json.py
Created November 28, 2010 02:09
ejemplo de serialización de consultas de django con json
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
@lfborjas
lfborjas / session_counter.rb
Created October 20, 2010 02:00
A simple script to decode sinatra sessions and tamper them
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
@lfborjas
lfborjas / application.rb
Created July 31, 2013 12:25
inspect the rack env before it hits the rails app
#config/application.rb
config.middleware.use "Peekaboo"
@lfborjas
lfborjas / Gemfile
Last active December 15, 2015 03:59
prueba de concepto de app
gem 'sinatra'
gem 'rest-client'
gem 'json' #probablemente innecesaria
@lfborjas
lfborjas / fake_endpoints.rb
Created March 18, 2013 13:46
Serves a rack app based on paths/responses defined in a cucumber feature
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
@lfborjas
lfborjas / ugh.rb
Created March 5, 2013 01:59
fugly foobar
eval(
(%w[
1 0
1 0 0
]).zip(%w[
o d
e v n
]).map{ |(to, fro)|
%Q{
#{to}.upto(9) do |#{fro}|
@lfborjas
lfborjas / fun.js
Last active December 14, 2015 08:48 — forked from syntacticsugar/gist:5059926
//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)
);
<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)
@lfborjas
lfborjas / mens.sql
Last active November 14, 2015 06:49
Flipping: M Nov 2015
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