Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@niyazpk
niyazpk / pQuery.js
Created October 25, 2014 14:03
Add or update query string parameter
// Add / Update a key-value pair in the URL query parameters
function updateUrlParameter(uri, key, value) {
// remove the hash part before operating on the uri
var i = uri.indexOf('#');
var hash = i === -1 ? '' : uri.substr(i);
uri = i === -1 ? uri : uri.substr(0, i);
var re = new RegExp("([?&])" + key + "=.*?(&|$)", "i");
var separator = uri.indexOf('?') !== -1 ? "&" : "?";
if (uri.match(re)) {
@niyazpk
niyazpk / gist:636361
Created October 20, 2010 12:54
Simple url shortener bookmarklet
javascript:(function() {
/* Replace login and apiKey, get your's from http://bit.ly/a/your_api_key */
var login="xxxxxxxxx",
apiKey="R_xxxxxxxx",
otherlib=false;
if (typeof jQuery=='undefined' && typeof $=='function') {
otherlib=true;
}
function getScript(url,success){
var script=document.createElement('script');
@niyazpk
niyazpk / Crypto.js
Created December 11, 2012 10:29
A murmur hash implemetation
crypto = (function (){
/**
* JS Implementation of MurmurHash2
*
* @see http://github.com/garycourt/murmurhash-js
*
* @param {string} str ASCII only
// make an ajax call before DOM ready.
$.ajax({
url: '/myAwesomeService'
}).done(function(data){
// when the result arrives,
// wait till DOM ready
$(function(){
// and attach it to the DOM
$('body').append(data);
});
// on document-ready,
$(function(){
// make an ajax call..
$.ajax({
url: '/myAwesomeService'
}).done(function(data){
// and attach the result to the DOM
$('body').append(data);
});
});
{
"name": "b3c",
"version": "0.1.2",
"description": "My App",
"devDependencies": {
"grunt": "git://github.com/gruntjs/grunt.git#ead4eb8f8ed778c6a637577ba812df806b455fe9",
"grunt-contrib-jshint": "~0.1.0",
"grunt-contrib-nodeunit": "~0.1.0",
"grunt-contrib-sass": "~0.2.1",
"grunt-contrib-uglify": "git://github.com/gruntjs/grunt-contrib-uglify.git#a2ba9375441d1ba94194b2113b3731b9d399907c",
@niyazpk
niyazpk / extract(object, string).js
Last active December 9, 2015 23:49
extract(object, string) : Uses the string as a path finder inside the object to retrieve the specified item. Returns undefined if anything went wrong in finding the item.
function extract(obj, path) {
try {
return eval("obj." + path);
} catch(e) {
return undefined;
}
}
var obj = {
@niyazpk
niyazpk / Monty_Hall.py
Created November 14, 2012 16:08
A Tiny program to simulate the Monty Hall problem
from random import randint, choice
p_switch = 0
p_no_switch = 0
for i in range(0, 100000):
choices = ['G'] * 3
choices[randint(0, len(choices) - 1)] = 'C'
# Dude chooses once
app.addEventListener("activated", function (args) {
if (args.detail.kind === activation.ActivationKind.launch) {
if (args.detail.previousExecutionState !== activation.ApplicationExecutionState.terminated) {
// paste the code here
} else {
}
...
@niyazpk
niyazpk / gist:4046552
Created November 9, 2012 16:11
JavaScript for Windows8 live tiles
var notifications = Windows.UI.Notifications;
var recurrence = notifications.PeriodicUpdateRecurrence.hour;
var urls = [
new Windows.Foundation.Uri("http://localhost/tile1.xml"),
new Windows.Foundation.Uri("http://localhost/tile2.xml"),
new Windows.Foundation.Uri("http://localhost/tile3.xml"),
new Windows.Foundation.Uri("http://localhost/tile4.xml"),
new Windows.Foundation.Uri("http://localhost/tile5.xml")
];