Skip to content

Instantly share code, notes, and snippets.

@Krule
Krule / get_params.js
Created January 26, 2011 13:04
Small javascript snippet to convert location.search parameters and return them as hash
/**
* Returns location search parameters as hash, so we can
* use them more naturally in our javascript. Like...cough... rails :P
*
* Example url: http://my_domain.ext/?page=products&condition=cheap
*
*
* var params = get_params();
*
* alert( params['page'] ); // => products
@andrei-m
andrei-m / levenshtein.js
Last active January 12, 2024 23:00
Levenshtein distance between two given strings implemented in JavaScript and usable as a Node.js module
/*
Copyright (c) 2011 Andrei Mackenzie
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
@SamWhited
SamWhited / get_test.sh
Created March 6, 2012 20:29
Continuously make requests to a server with curl and measure the request frequency with pv
#!/usr/sbin/env bash
while true; do
curl $1 -s > /dev/null
echo .
done | pv -l > /dev/null
@jexchan
jexchan / multiple_ssh_setting.md
Created April 10, 2012 15:00
Multiple SSH keys for different github accounts

Multiple SSH Keys settings for different github account

create different public key

create different ssh key according the article Mac Set-Up Git

$ ssh-keygen -t rsa -C "your_email@youremail.com"
@masak
masak / explanation.md
Last active April 11, 2024 02:50
How is git commit sha1 formed

Ok, I geeked out, and this is probably more information than you need. But it completely answers the question. Sorry. ☺

Locally, I'm at this commit:

$ git show
commit d6cd1e2bd19e03a81132a23b2025920577f84e37
Author: jnthn <jnthn@jnthn.net>
Date:   Sun Apr 15 16:35:03 2012 +0200

When I added FIRST/NEXT/LAST, it was idiomatic but not quite so fast. This makes it faster. Another little bit of masak++'s program.

@jlong
jlong / uri.js
Created April 20, 2012 13:29
URI Parsing with Javascript
var parser = document.createElement('a');
parser.href = "http://example.com:3000/pathname/?search=test#hash";
parser.protocol; // => "http:"
parser.hostname; // => "example.com"
parser.port; // => "3000"
parser.pathname; // => "/pathname/"
parser.search; // => "?search=test"
parser.hash; // => "#hash"
parser.host; // => "example.com:3000"
@callmephilip
callmephilip / gist:3490036
Created August 27, 2012 16:22
[JavaScript] Get viewport size
var viewportwidth;
var viewportheight;
// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
if (typeof window.innerWidth != 'undefined')
{
viewportwidth = window.innerWidth,
viewportheight = window.innerHeight
}
@callmephilip
callmephilip / gist:3517765
Created August 29, 2012 19:39
[JavaScript] Dispatching mouse move event
// look here for more details : https://developer.mozilla.org/en-US/docs/DOM/event.initMouseEvent
var mouseMoveEvent = document.createEvent("MouseEvents");
mouseMoveEvent.initMouseEvent(
"mousemove", //event type : click, mousedown, mouseup, mouseover, mousemove, mouseout.
true, //canBubble
false, //cancelable
window, //event's AbstractView : should be window
1, // detail : Event's mouse click count
@callmephilip
callmephilip / gist:3519403
Created August 29, 2012 21:52
[JavaScript] Dispatching keyboard event
// gecko and webkit
// details here https://developer.mozilla.org/en-US/docs/DOM/event.initKeyEvent
var keyboardEvent = document.createEvent("KeyboardEvent");
var initMethod = typeof keyboardEvent.initKeyboardEvent !== 'undefined' ? "initKeyboardEvent" : "initKeyEvent";
keyboardEvent[initMethod](
"keydown", // event type : keydown, keyup, keypress
true, // bubbles
@ajace
ajace / prime_generator.js
Last active October 5, 2020 03:03
nodejs script to generate prime numbers
#!/usr/bin/env node
var fs = require('fs');
var outfile = "primes.txt";
var count = 0;
var maxCount = 100;
var primes = [];
var i = 2;