Skip to content

Instantly share code, notes, and snippets.

@shakhal
shakhal / switcher.js
Last active August 29, 2015 14:09
Cytoscape js layout switcher
$(function(){ // on dom ready
var html = layouts.reduce(function(a,e,i){return a+"<a onclick='setLayout("+i+")'>"+e+"</a> - "},"Layouts:")
$("#cy").before(html);
}); // on dom ready
var layouts = [ 'concentric',
'breadthfirst',
@shakhal
shakhal / call_jsonp.js
Last active August 29, 2015 14:10
Call JSONP
function callJsonp(url, callbackFunc){
var callbackName;
if (callbackFunc == null || callbackFunc.length == 0){
callbackName = "dummy";
}
else if (typeof(callbackFunc) == "function"){
callbackName = functionName(callbackFunc);
if (window[callbackName] == undefined){
callbackName = 'jsonp_callback_' + Math.floor(Math.random() * 100000);
@shakhal
shakhal / quartrer.js
Created January 21, 2015 10:29
Yearly Quarters math, add, subtract, increase etc...
var Quarter = function(year, quarter){
this.year = year;
this.quarter = quarter;
this.str = function(){
return this.year+"_"+this.quarter;
}
this.increase = function(){
@shakhal
shakhal / toggleCheckbox
Created April 9, 2015 08:59
Toggle all checkboxes in column of HTML table by TH header checkbox
$("th input[type='checkbox']").on("click",function(){
var col = $(this).parent().children().index($(this));
var checked = $(this).is(":checked");
$(this).closest("table").find("tr td:nth-child("+col+") input[type=checkbox]").prop("checked", checked);
})
@shakhal
shakhal / location.php
Created November 26, 2015 01:39
Extracting Your Own Location Information From Google
// Today's time is needed to get the bounding for the request
$currentTime = time();
// Beginning and end of the day
$startTime = strtotime("midnight", $currentTime);
$endTime = strtotime("tomorrow", $startTime);
$smon = date("m", $startTime)-1;
$sday = date("d", $startTime);
$syear = date("Y", $startTime);
#!/bin/bash
if [ -z "$1" ]; then
echo "missing org name"
exit 1
else
name=$1
fi
if [ -z "$2" ]; then
@shakhal
shakhal / find_values.js
Last active January 27, 2023 22:52
Find values in JSON by key, recursively
function findValues(obj, key){
return findValuesHelper(obj, key, []);
}
function findValuesHelper(obj, key, list) {
if (!obj) return list;
if (obj instanceof Array) {
for (var i in obj) {
list = list.concat(findValuesHelper(obj[i], key, []));
}