Skip to content

Instantly share code, notes, and snippets.

View cristobal's full-sized avatar
💭
¯\_(ツ)_/¯

Cristobal Dabed cristobal

💭
¯\_(ツ)_/¯
View GitHub Profile
@cristobal
cristobal / URLHash.php
Created November 24, 2010 15:20
URLHash php
<?php
// Port of http://code.google.com/p/loolu/source/browse/trunk/common/lib/url/hash.py to PHP
/**
* LooLu is Copyright (c) 2009 Shannon Johnson, http://loo.lu/
*/
class URLHash {
@cristobal
cristobal / truncate_text.php
Created February 17, 2011 23:44
Truncate Text
<?php
/**
* Truncate text
*
* @param $text
* @param $max
* @param $type
* @param $suffix
*/
@cristobal
cristobal / 01_validate_orgnr.php
Last active July 10, 2020 11:13
Validate Norwegian Organization Number
<?php
/**
* Validate orgnr
* Validates an string number according to the brreg spec
* https://www.brreg.no/om-oss/oppgavene-vare/alle-registrene-vare/om-enhetsregisteret/organisasjonsnummeret/
*
* Test case: https://repl.it/repls/TechnicalForcefulBsddaemon
*
* @param <string> $value
@cristobal
cristobal / numeric.js
Created August 31, 2011 13:05
jQuery Numeric - Number validator
/**
* Numeric.js
*
* @author Cristobal Dabed
* @version 0.1
*/
(function ($) {
var re = new RegExp('[A-Za-z\\]\\[!\\"#$%&\'()*+,.\\/:;<=>?@\\^_`{|}~-]');
var re_s = new RegExp("\\D");
/**
* Test for IE
* - http://blogs.msdn.com/giorgio/archive/2009/04/14/how-to-detect-ie8-using-javascript-client-side.aspx
* - http://blogs.msdn.com/mikeormond/archive/2008/09/25/ie-8-compatibility-meta-tags-http-headers-user-agent-strings-etc-etc.aspx
* - http://msdn.microsoft.com/en-gb/library/cc817572.aspx
* - http://stackoverflow.com/questions/5825385/javascript-can-i-detect-ie9-if-its-in-ie7-or-ie8-compatibility-mode
*/
if(window.ActiveXObject){
var rv = -1;
var ua = navigator.userAgent;
@cristobal
cristobal / LUA unserialize
Created September 5, 2012 23:39
Lua php unserialize port
--[[
LUA variant of the php unserialize function
Port of http://phpjs.org/functions/unserialize
]]--
local function unserialize (data)
local function utf8Overhead (chr)
local code = chr:byte()
if (code < 0x0080) then
return 0
@cristobal
cristobal / serialize.lua
Created September 6, 2012 10:38
Lua php serialize port
--[[
LUA variant of the php serialize function
Port of http://phpjs.org/functions/unserialize
]]--
function serialize (mixed_value)
-- body
local val, key, okey,
ktype, vals, count, _type;
ktype = ''; vals = ''; count = 0;
@cristobal
cristobal / Build node.js and ZMQ - step 1.sh
Last active December 14, 2015 23:09
Builde nodejs and ZMQ on a shared host when build tools are available
# 1. Downdload the latest distribution from http://nodejs.org
# 2. Extract the nodejs distribution
$> tar zxvf node-{version}.tar.gz
$> cd node-{version}
# 3. Configure and gmake with the location for your distribution i.e.
$> ./configure --prefix=$HOME/local
$> gmake
$> gmake install
@cristobal
cristobal / date.lua
Last active December 15, 2015 11:59
Port of php.js date to lua http://phpjs.org/functions/date/
function date (format, timestamp)
-- @credits https://raw.github.com/kvz/phpjs/master/functions/datetime/date.js
local c = {}
local f = nil
local formatPattern = "%a"
local pad = function (v, s)
v = tostring(v)
if string.len(v) < s then
@cristobal
cristobal / strpos.lua
Created April 9, 2013 16:01
Lua variant for the php strpos function
function strpos (haystack, needle, offset)
local pattern = string.format("(%s)", needle)
local i = string.find (haystack, pattern, (offset or 0))
return (i ~= nil and i or false)
end