Skip to content

Instantly share code, notes, and snippets.

@bitifet
bitifet / inspect_even_circular.js
Last active November 3, 2015 07:35
Circular-references aware inspect() function.
// util.inspect() alternative returning always valid JSON even having circular refernces.
// Only for debugging and inspection purposes.
// Intended to be used in conjunction with underscore. Ex: "underscore print --color"
// Also useful with my lovely javascript inspection vim mappings:
// https://github.com/bitifet/dotfiles/blob/master/.vim/after/syntax/javascript/SyntaxInclude.vim
var inspect = (function(){
var utilInspect = require("util").inspect;
return function inspect (obj) {
var result;
var str = "var Circular = \"(->CIRCULAR<-)\";\n";
@bitifet
bitifet / jasmine_checkEquals.js
Last active November 12, 2015 05:53
Jasmine templates
// checkEquals (fn, tests) - Helper function to build equality tests with Jasmine.
function checkEquals(fn, tests){
if (fn instanceof Array) { // Allow to specify as ["this", fn] if required.
var target = fn[0]; // this
fn = fn[1];
} else { // fn expected to be a single functin by default.
var target = this; // Or any other arbitrary value.
};
return function(){
tests.map(function(t){
@bitifet
bitifet / pgclone
Last active January 6, 2024 15:49
Instantly clone PostgreSQL databases thought btrfs subvolumes.
#!/usr/bin/env bash
# SETUP EXAMPLE:
# --------------
#
# # Install btrfs-tools:
# sudo apt-get install btrfs-tools
#
# # Create btrfs filesystem across one or more divices:
# # -> Check device names!!
@bitifet
bitifet / jsDateTime.js
Last active March 21, 2017 06:24
Miscellaneous JavaScript Date/Time Helpers.
function dateParse(d){// Parse date in "dd/mm/yyyy" format. {{{
d = d.split("/");
return new Date(
parseInt(d[2])
, parseInt(d[1]) - 1
, parseInt(d[0])
);
};//}}}
function dateCmp (d1, d2){// Compare dates (returning -1, 0, 1). {{{
@bitifet
bitifet / cpd.sql
Created July 13, 2017 09:01
PostgreSQL long term IDLE processes disconnection.
-- CPD.sql - Crappy Processes Disconnection
-- ----------------------------------------
--
-- Close PostgresSQL connections left IDLE forever by crappy processes.
--
--
-- Credits: https://stackoverflow.com/questions/12391174/how-to-close-idle-connections-in-postgresql-automatically?answertab=active#tab-top
--
-- Minimum inactivity interval to
@bitifet
bitifet / arrayFall.js
Last active September 4, 2017 05:41
Sequential waterfall over array of promisorys.
// Performs sequential waterfall over array of promisorys.
// Following two sentences:
// var P = Promise.all(inArr.map(cbk))
// var P = arrayfall(inArr, cbk)
// ...are pretty much the same.
// Both runs all promises sequentially and returns new promise resolving with
// an array with resolved data (if none rejected).
// But in the former all promises are run as fast as input array is scanned.
// Whereas with arrayfall() promises are executed in sequence: each after
// previous one is resolved (or rejected) even being completely asyncronous.
@bitifet
bitifet / nodeEnsaimeitor.js
Created September 12, 2017 15:27
NodeJS Ensaimeitor Draft.
// Node Ensaimeitor Draft.
// Thanks to http://ensaimeitor.apsl.net/
"use strict";
const srvHost = "ensaimeitor.apsl.net";
const srvPort = 80;
const index = {//{{{
fiscal: "NIF's",
cif: "CIF's",
@bitifet
bitifet / NextCloud_Hacks.md
Last active July 12, 2018 17:43
NextCloud Hacks

My personal NextCloud hacks

fixletime.sh

Script to 'touch' media (photo / video) files to the time that they have been taken (according available information: exif headers, filename patterns..).

[B9B80A21DF98BE68DB4033CF3D4D2246B2AF9078989B9AB5260C1C5F349F5BE338DBA0453B87F1C5F2D66B6C1526EC2771317B2DAFB1E22DD0A5A7C689DB6BFBC5745A5569054495288B1B91894C73DDBDAB97F25C862DF282DBF46559AC91165E47A660BB98BAAA6E717724BE210B78C45E3AC83F152D4424965057093B2F2FA1B17257E1DB20F6CE30141F38880B42520F6107C61CDA31815B6E6293B74FDDFC0C9D7159B098FA4F5694F697E1FC6EE92284CA6EE2474F93B32E2608195EAAA573295004DC499276FDC698C2FFDE49543562F3BA5931479F37E9994C0A299FEEDF26247AE0E05890AEE439423633D151CEA28FDEB352BD46AF9F96BB7E18FD99F98CB964C154BE60232C7CFF32B7]
@bitifet
bitifet / BestPractice_Solution.js
Created August 28, 2019 16:12
.softBind() - Rebindable [function].bind() alternative.
// Unless it could become ECMASCRIPT proposal best practice
// would be to use regular function in order to avoid polluting
// [function]'s prototype
// Twitter: https://twitter.com/bitifet/status/1166745132651220992?s=20
const softBind = (function() {
const master = Symbol();
return function softBind(self, ...args) {
const fn0 = self[master] || self;
const fn = fn0.bind(...args)
fn[master] = fn0;