Skip to content

Instantly share code, notes, and snippets.

View Fardinak's full-sized avatar
🧠
AI-ing

Fardin Koochaki Fardinak

🧠
AI-ing
View GitHub Profile
@Fardinak
Fardinak / alertbox.jquery.js
Last active December 23, 2015 02:49
A multi-alert handler, with show/hide/timeout/dismiss functionality; developed based on Twitter Bootstrap's alert styling, but easy to modify. It's using jQuery, but a vanilla implementation is easy to achieve.
/** @constructor */
window.alertbox = new (function($, window, undefined) {
var $alb = $('<div id="alertbox" class="alert">').hide().appendTo('body')
, timer = null
, next = [];
/**
* Enum for alert types and their respective class names
*
* @public
@Fardinak
Fardinak / copyvid.sh
Last active December 31, 2015 07:49
Copy fully played online videos from services that use flash players.Run commands as root.
#!/bin/bash
STORAGE=/home/$USER/Downloads;
# Get Process ID
PROCID=$(pgrep -f flash);
# Change current directory to
cd /proc/$PROCID/fd;
# Get file names
@Fardinak
Fardinak / loadStack.js
Created December 18, 2013 15:29
Simple script to load a stack of javascript requisites. Depends on jQuery's getScript.
function loadStack(stack, cb) {
if($.isArray(stack)) {
if(stack.length === 0) return cb();
// TODO: implement the getScript method to make it standalone
$.getScript(stack.shift() + '.js', loadStack.bind(this, stack, cb));
}
}
@Fardinak
Fardinak / template.js
Last active August 29, 2015 14:04
A simple JavaScript Template Engine
/*
* A simple JavaScript Template Engine
*
* By default replaces every {{ foo.bar }} with the
* the respective value from provided data object.
*/
/*
* Return the value addressed in args from obj
*
@Fardinak
Fardinak / has-parent.js
Last active August 29, 2015 14:07
Element has parent
/*
* Addressing the issue provided in the following Stackoverflow question:
* Check if class exists somewhere in parent - vanilla JS
* http://stackoverflow.com/q/16863917/717221
*/
function hasParent(element, parentSelector) {
var potentialParents = document.querySelectorAll(parentSelector);
for(i in potentialParents) if(potentialParents[i].contains(element))
return potentialParents[i];
return false;
@Fardinak
Fardinak / datetime.js
Last active August 29, 2015 14:21
A Multi-Calendar-System DateTime Service based on Moment.js (and moment-jalaali)
define(['ng', 'moment-jalaali'],
function(ng, moment) {
var mod = ng.module('app.service.datetime', []);
mod.run(['$rootScope', function($rootScope) {
$rootScope.$on('$languageChangeSuccess', function(evt, newLang) {
if(newLang === 'fa') moment.loadPersian();
else moment.locale('en');
});
}]);
// Retrieve a deep item from obj, recursively
function getDeep (obj, addr) {
if(typeof obj !== 'object' && !Array.isArray(obj))
throw new TypeError("The Object argument must be an Object or an Array");
if(typeof addr !== 'string' && !Array.isArray(addr))
throw new TypeError("The Address argument must be a string or and array");
// Split the dotted address into an array
if(typeof addr === 'string') {
addr = addr.split('.');
@Fardinak
Fardinak / dominantcolor.go
Last active March 3, 2017 06:04
Extract the dominant web-safe color from a decoded image
package dominantcolor
// Optionally use this importable repository instead:
// https://github.com/Fardinak/dominantcolor
import (
"github.com/nfnt/resize"
"image"
"image/color"
"image/color/palette"
@Fardinak
Fardinak / pgclone.sh
Last active March 3, 2017 06:08
Clone a PostgreSQL server using Docker and Union Mounting
#!/bin/bash
# This simple script mounts a PostgreSQL data directory as
# the lower dir, and a temp directory as the upper dir of
# a union mount; then bind mounts the volume into a docker
# container, running a new instance of PostgreSQL/PostGIS.
#
# This enables the user to run tests and migrations on
# production data, without worrying about data integrity or
# using too much storage for a full clone.
@Fardinak
Fardinak / pre-commit
Created May 14, 2017 15:38
some git hooks
#!/usr/bin/env bash
# Inspiration and sonarlint function from: https://github.com/janosgyerik/sonarlint-git-hooks
# ENVs
# $SKIPBRANCHTEST optional boolean
# $SKIPDIFFCHECK optional boolean
# $SKIPSONARLINT optional boolean
# use `-n` or `--no-verify` to bypass pre-commit and commit-msg hooks