Skip to content

Instantly share code, notes, and snippets.

View kanakiyajay's full-sized avatar
💭
Reach out to my email address

Jay Kanakiya kanakiyajay

💭
Reach out to my email address
View GitHub Profile
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>A simple SlideShow using :checked</title>
<style>
.slider-wrapper{
overflow: hidden;
width: 300px;
height: 300px;
@kanakiyajay
kanakiyajay / flattenRecursive
Created February 14, 2014 06:43
Flatten any array of any level using recursive function
var flattenRecursive = function (arr) {
return arr.reduce(function (a,b) {
if (b instanceof Array) {
return a.concat(flattenRecursive(b));
}else{
return a.concat(b);
}
},[]);
}
@kanakiyajay
kanakiyajay / app.js
Created February 25, 2014 16:30
A simple way to use native form POSTs in express and myql
var mysql = require("mysql"),
express = require("express"),
app = express();
var connection = mysql.createConnection({
host : "localhost",
user : "root",
password : "",
database : "node"
});
function getQueryObj (query) {
query = query.substring(query.indexOf("?")+1,query.length);
var keys = query.split("&") , obj = {};
for (var i = 0; i < keys.length; i++) {
var pair = keys[i].split("=");
obj[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1]);
}
return obj;
}
console.log(getQueryObj("http://example.com?x=hello&y=des%20t"));
@kanakiyajay
kanakiyajay / getQueryMatch
Created May 26, 2014 08:37
Get only one value from the query string value using Regex and javascript
function getQueryMatch (query,key) {
var regx = new RegExp(key+"=([^&]*)");
return decodeURIComponent(query.match(regx)[1]);
}
console.log(getQueryMatch("http://example.com?x=hello&y=des%20t","y"));
@kanakiyajay
kanakiyajay / let.js
Created August 3, 2014 09:10
let keyword in ecmascript 6
for (let i = 0; i < 10; i++) {
x += 10;
}
console.log(x);
try {
console.log(i);
} catch(e) {
console.log(
//
// Super simple base64 encoding / decoding with node.js
//
var base64 = exports = {
encode: function (unencoded) {
return new Buffer(unencoded).toString('base64');
},
decode: function (encoded) {
return new Buffer(encoded, 'base64').toString('utf8');
@kanakiyajay
kanakiyajay / clone
Last active August 29, 2015 14:05
Cloning an object with multiple nested functions or keys using javascript
function cloneObject(obj) {
var clone = {};
for(var i in obj) {
if(typeof(obj[i])=="object" && obj[i] != null)
clone[i] = cloneObject(obj[i]);
else
clone[i] = obj[i];
}
return clone;
}
@kanakiyajay
kanakiyajay / isArrayLike
Created August 14, 2014 09:05
Angular: is the Object array like
function isArrayLike(obj) {
if (obj == null || isWindow(obj)) {
return false;
}
var length = obj.length;
if (obj.nodeType === 1 && length) {
return true;
}
@kanakiyajay
kanakiyajay / nextUid
Created August 14, 2014 09:09
Angular: UID function creator
var uid = ['0', '0', '0'];
function nextUid() {
var index = uid.length;
var digit;
while(index) {
index--;
digit = uid[index].charCodeAt(0);
if (digit == 57 /*'9'*/) {