Skip to content

Instantly share code, notes, and snippets.

@krypton
krypton / ibanvalidator.js
Created May 8, 2013 14:44
Javascript IBAN (International Bank Account Number) Validation
function validateIBAN(iban) {
var newIban = iban.toUpperCase(),
modulo = function (divident, divisor) {
var cDivident = '';
var cRest = '';
for (var i in divident ) {
var cChar = divident[i];
var cOperator = cRest + '' + cDivident + '' + cChar;
@krypton
krypton / nibvalidator.js
Created May 8, 2013 14:42
Javascript NIB (Bank Identification Number) Validation
function validateNIB(t, max_len)
{
var pesos = [0, 1, 10, 3, 30, 9, 90, 27, 76, 81, 34, 49, 5, 50, 15, 53, 45, 62, 38, 89, 17, 73, 51, 25, 56, 75, 71, 31, 19, 93, 57],
validateValue = t.toString(),
s = validateValue.split(''),
r = s.reverse(),
tot = 0;
if (t == undefined) {
return false;
@krypton
krypton / erb.sublime-snippet
Last active December 12, 2015 01:39
Sublime Text 2 snippet to create ERB tag
<!--
Inspired on Dr.Nic ruby-tmbundle (https://github.com/drnic/ruby-tmbundle/blob/master/Snippets/Insert%20ERb's%20%3C%25%20__%20%25%3E%20or%20%3C%25%3D%20__%20%25%3E.tmSnippet)
In your Sublime Text 2 User folder (Sublime Text 2/Packages/User), create this file and give a name "erb.sublime-snippet".
Than open a Ruby on Rails view file like HAML or ERB, type "erb" command and tab key.
This create ERB tag on your view file.
-->
<snippet>
<content><![CDATA[<%= ${0} %>]]></content>
<tabTrigger>erb</tabTrigger>
@krypton
krypton / gist:3910865
Created October 18, 2012 10:13
Assets include
<?php
define('_ROOT', dirname(realpath(__FILE__)));
function assets_include_tag($assets, $tmpl, $options)
{
if (empty($assets)) {
return false;
}
@krypton
krypton / gist:3452863
Created August 24, 2012 16:55
Bubble sort in PHP
function bubbleSort ($items) {
$size = count($items);
for ($i=0; $i<$size; $i++) {
for ($j=0; $j<$size-1-$i; $j++) {
if ($items[$j+1] < $items[$j]) {
arraySwap($items, $j, $j+1);
}
}
}
return $items;
@krypton
krypton / gist:3452101
Created August 24, 2012 15:39
Prototypal Inheritance in JavaScript
// From http://javascript.crockford.com/prototypal.html
// This way we are follow the true nature of Javascript.
if (typeof Object.create !== 'function') {
Object.create = function (o) {
function F() {}
F.prototype = o;
return new F();
};
}
@krypton
krypton / Preferences.sublime-settings
Created August 22, 2012 08:41
Sublime Text 2 User Settings
{
"bold_folder_labels": true,
"color_scheme": "Packages/Color Scheme - Default/Railscasts.tmTheme",
"default_encoding": "ISO-8859-1",
"detect_indentation": false,
"draw_minimap_border": true,
"font_face": "Bitstream Vera Sans Mono",
"font_size": 10,
"highlight_line": true,
"highlight_modified_tabs": true,
@krypton
krypton / cycle.php
Created April 16, 2012 17:32
Walks on the values ​​of an array value each time the function is invoked
function cycle($obj)
{
static $key = -1;
static $last_obj = array();
if(count(array_diff_assoc($obj, $last_obj)) > 0)
$key = 0;
else
$key++;
@krypton
krypton / colormeter.js
Created April 16, 2012 17:22
Calculate difference in percentage between 2 hex colors
function color_meter(cwith, ccolor) {
if (!cwith && !ccolor) return;
var _cwith = (cwith.charAt(0)=="#") ? cwith.substring(1,7) : cwith;
var _ccolor = (ccolor.charAt(0)=="#") ? ccolor.substring(1,7) : ccolor;
var _r = parseInt(_cwith.substring(0,2), 16);
var _g = parseInt(_cwith.substring(2,4), 16);
var _b = parseInt(_cwith.substring(4,6), 16);
@krypton
krypton / Bcrypt.php
Created June 29, 2011 09:33
Simple PHP 5.3+ Bcrypt class adapted from phpass
<?php
/*
Adaptation by Marco Arment <me@marco.org>.
Adapted from Portable PHP Password Hashing Framework (phpass) version 0.3:
http://www.openwall.com/phpass/
phpass was by Solar Designer <solar at openwall.com> in 2004-2006 and is in
the public domain. This adaptation is also in the public domain.