Skip to content

Instantly share code, notes, and snippets.

View jfcalvo's full-sized avatar

José Francisco Calvo jfcalvo

View GitHub Profile
@jfcalvo
jfcalvo / 00.imgproxy_vs_alternatives.md
Created May 5, 2020 09:33 — forked from DarthSim/00.imgproxy_vs_alternatives.md
imgproxy vs alternatives benchmark

imgproxy vs alternatives benchmark

Setup

  • c5.xlarge AWS instance: 4 CPUs, 8 GB RAM
  • Ubuntu 18.04
  • Go 1.12
  • Python 2.7
  • Vips 8.7.4
@jfcalvo
jfcalvo / user.rb
Created April 15, 2013 17:19
Validación email Rails (from Rubytutorial.org)
class User < ActiveRecord::Base
attr_accessible :name, :email
validates :name, presence: true, length: { maximum: 50 }
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
validates :email, presence: true, format: { with: VALID_EMAIL_REGEX }
end
@jfcalvo
jfcalvo / JavaC.sublime-build
Created September 26, 2012 18:21
Sublime Text 2 Build System for Java (Compile and running)
{
"cmd": ["javac \"$file_name\" && java \"$file_base_name\""],
"shell": true,
"file_regex": "^(...*?):([0-9]*):?([0-9]*)",
"selector": "source.java"
}
@jfcalvo
jfcalvo / run.sh
Created June 26, 2012 22:38
My Sublime Text 2 Build System to build MoaiSDK Projects with MacOS
/*
Change MOAI_BIN environment for the directory where your have MoaiSDK bin
*/
{
"cmd": ["./run.sh"],
"working_dir": "${project_path:${folder}}",
"env": {
"MOAI_BIN": "/Users/jfcalvo/Development/moai-sdk/bin/osx/moai"
},
"selector": "source.lua"
@jfcalvo
jfcalvo / gist:2919090
Created June 12, 2012 18:12
Sublime Text 2 Build System for C at MacOS
/*
Useful to build simple C files. Compile the source file and run Terminal executing the
binary application.
*/
{
"cmd": "gcc \"$file_name\" -o \"$file_base_name\" && open -a Terminal.app \"$file_path/$file_base_name\"",
"shell": true,
"selector": "source.c"
}
@jfcalvo
jfcalvo / digest.rb
Created October 3, 2011 09:28
Hash of files an strings with Ruby using MD5 and SHA256
require 'digest'
# Get SHA256 Hash of a file
puts Digest::SHA256.hexdigest File.read "data.dat"
# Get MD5 Hash of a file
puts Digest::MD5.hexdigest File.read "data.dat"
# Get MD5 Hash of a string
puts Digest::SHA256.hexdigest "Hello World"
# Get SHA256 Hash of a string using update
@jfcalvo
jfcalvo / gist:1182935
Created August 31, 2011 06:27
Ruby block example using each_with_index and inject at the same time.
[1, 2, 3, 4].each_with_index.inject(0) do | memo, (number, i) |
puts "number: #{number}, i: #{i}."
puts "memo: #{memo}."
memo += number
end
@jfcalvo
jfcalvo / chromosomes.rb
Created July 1, 2011 16:36
A simple function to generate random chromosome strings
# 54.73 seconds generating 10.000.000 chromosomes
def generate_chromosome_1(length, alleles)
(1..length).collect { alleles[rand(alleles.size)] }.join
end
# 49.15 seconds generating 10.000.000 chromosomes
def generate_chromosome_2(length, alleles)
chromosome = String.new
for i in 1..length