Skip to content

Instantly share code, notes, and snippets.

View Tronix117's full-sized avatar

Jeremy TRUFIER Tronix117

View GitHub Profile
@Tronix117
Tronix117 / crypt_id.rb
Created August 12, 2012 19:22
Algorithm: Rails crypt integer to random short string, can be used as link shortener (by directly crypting databse ids). 1296 possibility for each Int (for each crypting key). String generated are not linear and also include a validity check (hashsum), an
##
# MonkeyPatch crypt_id
#
# Provide an efficient way to crypt an id, with
# different possibility for each id.
#
# Three provided methods are:
# Int.crypt_id(key='')
# String.decrypt_id(key='')
# String.change_charset(charset_from, charset_to)
@Tronix117
Tronix117 / change_charset.rb
Created July 25, 2012 10:04
changing character base, need adding some xoring somewhere
# Optimised if the BASE array has the same size as a power of 2, otherwise disable symetrie
# Optimised if 0 is the first in the BASE array
BASE_2 = ['0','1']
BASE_4 = ('0'..'3').to_a
BASE_8 = ('0'..'7').to_a
BASE_16 = ('0'..'9').to_a + ('a'..'f').to_a
BASE_32 = ('0'..'9').to_a + ('a'..'v').to_a
BASE_64 = ('0'..'9').to_a + ('a'..'z').to_a + ('A'..'Z').to_a + ['$','_']
SHUFFLE_BASE_16 = ['0','4','2','1','8','6','7','5','9','3','c','b','a','f','d','e']
SHUFFLE_BASE_64 = ['0','7','S','q','j','6','N','C','u','8','W','k','4','J','K','5','m','1','F','f','D','X','g','V','n','z','B','i','L','P','l','a','G','s','Q','2','Z','d','v','o','I','x','_','M','Y','c','9','h','$','R','b','U','y','O','A','w','e','p','3','T','E','H','t','r']
@Tronix117
Tronix117 / rails_dev_env_osx-10.7.sh
Created July 17, 2012 05:42
Rails 3 and Ruby 1.9.2, Installation development environment on Mac OSX Lion. Require: https://github.com/kennethreitz/osx-gcc-installer/downloads
#!/bin/bash
# Configuration (to edit)
RCPATH=~/.bashrc
PROJECT_DIRECTORY=~/Sites/myproject # project directoy (if it doesn't exist, the project will be installed here)
PROJECT_GIT_REPOSITORY='git@github.com:myname/myproject.git' # git repository of the project
DBPASS='123456' # root pass
# Your current Rails configuration (fill it with config/database.yml)
RAILS_BASE='myproject_dev'
@Tronix117
Tronix117 / float.rb
Created June 7, 2012 16:27
MonkeyPatch roundHalfToEven (Banker round)
##
# MonkeyPatch roundHalfToEven (Banker round)
#
# Solve most of floating binary point problems, and round
# to the specified decimal using banker round for financial
# calculations. Half fraction between number are rounded to
# the nearest even number.
#
# @author Jeremy Trufier <jeremy@trufier.com>
# @copyright Storific 2012