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 / randstr.go
Last active June 15, 2020 16:28
Random string generator
package randstr
import (
"math/rand"
"time"
"unsafe"
)
// Randomness source
var src = rand.NewSource(time.Now().UnixNano())
@Fardinak
Fardinak / irancell_ppg.js
Last active December 4, 2019 09:16
MTN Irancell data package price per gig
// Since MTN Irancell loves to experiment with their data packages and pricing
// i made this little snippet so I can easily choose a new package, fit for my
// needs and expectations instead of calculating the new PPGs every couple of
// month.
//
// Just run it in the console after page load and PPGs should replace the USSD
// Codes
const connection_speed = 20; // Mbps (approximate downlink speed)
const fair_usage_limit = 999; // GBs
@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
@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 / 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"
// 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 / 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');
});
}]);
@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 / 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 / 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));
}
}