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
# A naive approach to implement a picky search | |
module SelectiveSearchable | |
def searchable_on(*attrs) | |
search_attrs = attrs.map { |attr| "#{attr}_cont".to_sym } | |
define_singleton_method(:picky_search) do |query, page = 0, limit = 10| | |
if query.try(:empty?) | |
sentence = Proc.new { self.all } | |
else | |
q = search_attrs.reduce({}) {|dict, attr| dict.merge({attr => query}) } |
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
threads 3, 3 | |
workers 2 | |
on_worker_boot do | |
require "active_record" | |
require "erb" | |
cwd = File.dirname(__FILE__)+"/.." | |
ActiveRecord::Base.connection.disconnect! rescue ActiveRecord::ConnectionNotEstablished | |
configuration = YAML.load(ERB.new(File.read("#{cwd}/config/database.yml")).result) | |
ActiveRecord::Base.establish_connection(configuration[ENV["RAILS_ENV"]]) |
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/ruby | |
# *****------->>>>>Usage: cesar.rb 'texto' | |
def transposicion(msg) | |
cif = C(msg).map(&:reverse).transpose.map { |fila| fila.join('') }.join(' ') | |
return "****---->>>> Mensaje cifrado: #{cif} \n****---->>>> Mensaje descifrado: #{C(cif,cif.split[0].size).reverse.transpose.map { |fila| fila.join('') }.join(' ')}" | |
end | |
def C(msg,s=-1) | |
arr,ran, matrix = [msg.split.join.split('')] + [s == -1 ? Random.rand(3...6) : s] + [[[]]] | |
ran.times {|n| arr.each_slice(ran).with_index { |bloq,i| matrix[i] = Array.new(ran).each_with_index.map { |val,idx| val = bloq[idx].nil? ? (10...36).map { |i| i.to_s 36 }.sample : bloq[idx] } } } | |
return matrix |
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/ruby | |
# *****------->>>>>Usage: cesar.rb 'texto' #Desplazamiento | |
ALFABETO = ((0...36).map { |i| i.to_s 36 } + " ,/;'[]\=-!@#.$%^&*<>?:{}|".chars) * 10 | |
def cesar(msg,n) | |
viejo = [nuevo = msg.chars.map { |c| C(TRUE,c,n.to_i) }.join('')][0].chars.map { |c| C(FALSE,c,n.to_i) }.join('') | |
puts "*****----> El mensaje despues de E(msg,#{n}): #{nuevo} \n*****----> El mensaje despues de D(msg,#{n}): #{viejo}" | |
end | |
def C(s,x,n) | |
return s ? ALFABETO[ (ALFABETO.index(x) + n) % ALFABETO.count] : ALFABETO[ (ALFABETO.index(x) - n) % ALFABETO.count] | |
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
#!/usr/bin/python2 | |
################################################################################################################# | |
# TODO # | |
# tecnicas dict(k:tupla)? (tecnica(costo,funcion) diccionario que saca tupla # | |
# Validaciones .:. # | |
# Necesita Indicadores reales y temporales, cuando el hp este bajo el limite. # | |
# Ejemplo: Vida max = 100, after damage = 80, use potion = efect !> 100 # | |
# # | |
################################################################################################################# | |
# |
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 serial | |
import os | |
def U(): | |
print 'boton Up volumen++' | |
os.system("amixer sset Master playback 5%+") | |
def D(): | |
print 'boton Down volmen--' | |
os.system("amixer sset Master playback 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
/*Variables a usar*/ | |
int latch = 2; // set the latch pin | |
int clock = 3; // set the clock pin | |
int datin = 4;// set the data in pin | |
byte datosDelControl = 0; | |
void setup() { | |
Serial.begin(9600); |
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
#include <16F628A.h> //Pic a utilizar | |
#FUSES NOWDT //No usar el watchdog | |
#FUSES INTRC_IO //Usar el cristal interno, sin CLKOUT | |
#FUSES BROWNOUT //activa el brownout | |
#use delay(clock=4000000) // frecuencia de 4Mhz | |
void main( void ){ |
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
#include <16F628A.h> //Pic a utilizar | |
#FUSES NOWDT //No usar el watchdog | |
#FUSES INTRC_IO //Usar el cristal interno, sin CLKOUT | |
#FUSES BROWNOUT //activa el brownout | |
#use delay(clock=4000000) // frecuencia de 4Mhz | |
void main( void ){ |
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
int Interruptor = 0; // El interruptor a utilizar sera el 0 es decir el pin digital 2 | |
int ledSalida = 4; // Aqui pondremos un led para ver como funcionan las interrupciones | |
int estado = HIGH; // El estado del led | |
void setup() | |
{ | |
// ponemos en modo output el led | |
pinMode(ledSalida, OUTPUT); | |
digitalWrite(ledSalida, estado); //Lo encendemos |
NewerOlder