Skip to content

Instantly share code, notes, and snippets.

@bitifet
bitifet / morse.php
Last active December 18, 2015 13:18
Funny utility to encode and (yet buggy) decode strings into morse.
#!/usr/bin/env php
<?php
class morse {/*{{{*/
private $a2m;
private $m2a;
private $sep;
private $lang;
public function __construct(/*{{{*/
@bitifet
bitifet / tunedArray.js
Created October 13, 2014 00:08
Array with steroids.
"use strict"
var myArray = (function(Array) { // Array with steroids.//{{{
// Implement an Array clone with extended functions.
// In only imlements a simple .contains() method, but can be extended to
// add many more.
// The main key feature is the ability to do this WITHOUT
// altering the original Array object in any way.
// NOTE: Now we should use the myArray object to declare it. Main goal
// is to implement it as "var Array = (function(arr){...})(Array);"
@bitifet
bitifet / a.back-btn_jquery-mobile
Created October 21, 2014 21:25
Convert any anchor with the .back-btn class in "intelligent" back buttons in jquery-mobile framework.
// Implement .back-btn class bassed (self-explainatory) functionality for anchors.
$(".back-btn").each(function(){
var btn = $(this); // me (.back-btn)
var pageId = btn.closest("div[data-role='page']").attr("id"); // My page id.
$('a[href="#' + pageId + '"]').each(function(){ // Anchors linking my page.
var srcLink = $(this);
var srcPageId = srcLink.closest("div[data-role='page']").attr("id"); // Their page id.
// Awesome magic!! ;-)
// Handy plv8 console object (debugging)
var console = (function(){
var columns = 100;
function logString(level, str) {
var chunk = str.substring(0, columns);
var overflow = str.substring(columns);
plv8.elog(level, chunk);
if (overflow.length) logString(level, " | "+overflow);
};
@bitifet
bitifet / plv8_enhanced.js
Last active October 9, 2015 16:52
Enhanced plv8 (debugging) object to easily examine and measure query execution time.
var _debug = true;var pg = (function(_debug){ // Our enhanced plv8 object.//{{{
if (! _debug) return {
prepare: plv8.prepare,
log: function(){},
};
function gett() {
return parseInt(plv8.execute("select EXTRACT(EPOCH FROM (clock_timestamp()))*100000 as t")[0].t);
};
@bitifet
bitifet / _HTML5_hacks.md
Last active July 30, 2018 13:25
HTML5 Hacks

HTML5 Hacks

Simple class to make smooth scroll to make fully visible givien item inside a container.

Example:

@bitifet
bitifet / ObjectIntersect.js
Created March 4, 2015 12:28
Array (or object) values intersection.
// Exapmle var foo = intersect({foo: [1, 2, 5, 8], bar: {two: 2, tree: 3, four: 4, five: 5, six: 6}});
function intersect (arrList) { // Calculate intersection of multiple array or object values: //{{{
var l = Object.keys(arrList).length; // Also accepts regular objects as input.
var index = {};
for (var i in arrList) {
for (var j in arrList[i]) {
var v = arrList[i][j];
@bitifet
bitifet / window dialogs jQueryzed
Last active June 13, 2022 22:38
jQuery-UI replacement for window's alert() cofirm() and prompt() dialog functions.
// document dialogs overload:
// ==========================
//
// WARNING: This javascript versions CAN'T stop rest of javascript processing (except by an infinite
// loop which will also block this dialogs functionalities).
//
// I tryed to implement a "non-self-blocking" internal loop but need a nextTick() function which is
// not available on most (if not all) browser javascript implementations.
//
// I tryed to emulate it using ontimeout()'s and other tricks, but it doesn't work anyway.
@bitifet
bitifet / perSchema_plv8_init.js.sql
Last active October 6, 2016 13:11
Allow per-schema plv8_init functions.
/* public.plv8_startup()
*
* Allow to have multiple per-schema plv8_init functions.
*
* USAGE:
*
* 1. Add the following line to the end of your postgresql.conf file:
*
* plv8.start_proc = 'public.plv8_startup'
*
@bitifet
bitifet / astack.js
Created October 24, 2015 09:40
Asynchronous stack (LIFO)
"use strict";
var stack = (function(){
function _stack(){
this.stack = [];
this.queue = [];
};
_stack.prototype.push = function stack_push(data){