Skip to content

Instantly share code, notes, and snippets.

View jpillora's full-sized avatar
👶

Jaime Pillora jpillora

👶
View GitHub Profile
@jpillora
jpillora / s3-sign.js
Last active December 22, 2015 03:09
S3 Request Signing (generates Authorization headers)
//Performs the signing in the first example of:
// http://docs.aws.amazon.com/AmazonS3/latest/dev/RESTAuthentication.html
//Requires:
// http://www.defensivejs.com/djcl/encoding.js
// http://www.defensivejs.com/djcl/hashing.js
var str = "GET\n"+
"\n"+
"\n"+
@jpillora
jpillora / JSON-stringify.js
Last active December 22, 2015 06:39
mini stringify
var stringify = function(obj) {
var t;
if(obj === null)
return 'null';
if(obj instanceof Array) {
t = [];
for(var k in obj) t.push(stringify(obj[k]));
return "["+t.join(",")+"]";
}
switch(typeof obj) {
@jpillora
jpillora / dijkstra.js
Last active July 17, 2022 17:53
Dijkstra's algorithm in JavaScript
//dijkstra solve graph starting at s
function solve(graph, s) {
var solutions = {};
solutions[s] = [];
solutions[s].dist = 0;
while(true) {
var parent = null;
var nearest = null;
var dist = Infinity;
@jpillora
jpillora / valid-url-regex.js
Last active March 27, 2020 16:38
Valid URL Regular Expression
var isValidUrl = /^(?:(?:https?|ftp):\/\/)(?:\S+(?::\S*)?@)?(?:(?!10(?:\.\d{1,3}){3})(?!127(?:\.​\d{1,3}){3})(?!169\.254(?:\.\d{1,3}){2})(?!192\.168(?:\.\d{1,3}){2})(?!172\.(?:1[​6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1​,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00​a1-\uffff0-9]+-?)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]+-?)*[a-z\u​00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:\/[^\s]*)?$/i;
var url = "...";
console.log(isValidUrl.test(url)) //=> true/false
@jpillora
jpillora / 1-two-switches.py
Last active August 26, 2021 16:44
Mininet LOCAL port not responding
#!/usr/bin/python
from mininet.net import Mininet
from mininet.node import OVSSwitch
from mininet.cli import CLI
from mininet.log import setLogLevel
if __name__ == '__main__':
setLogLevel( 'info' ) # for CLI output
@jpillora
jpillora / index.html
Last active January 3, 2016 18:39 — forked from mbostock/.block
<!DOCTYPE html>
<meta charset="utf-8">
<style>
.link {
fill: none;
stroke: #666;
stroke-width: 1.5px;
}
@jpillora
jpillora / combine-through.js
Created May 5, 2014 01:56
Combine 'through' streams
// combine an existing pipeline:
// entry -> s1 -> s2 -> s3 -> s4 -> exit
// into:
// P
// where sX -> P => sX -> entry
// and P -> sY => exit -> sY
var combine = function(entry, exit) {
//simple proxy stream
var combination = through();
@jpillora
jpillora / config.fish
Last active November 13, 2018 05:46
Fish Config
set PATH $HOME/bin /usr/local/bin /usr/local/go/bin $PATH
set -x GOPATH $HOME/go
function fish_greeting
end
function fish_prompt
set_color cyan
echo -n $USER
echo -n ' '
@jpillora
jpillora / line-graph.html
Created May 30, 2014 10:24
Line Graph with D3
<!DOCTYPE html>
<meta charset="utf-8">
<style>
body {
font: 10px sans-serif;
}
.axis path,
.axis line {
fill: none;
stroke: #000;
@jpillora
jpillora / keybase.md
Created July 16, 2014 13:59
keybase.md

Keybase proof

I hereby claim:

  • I am jpillora on github.
  • I am jpillora (https://keybase.io/jpillora) on keybase.
  • I have a public key whose fingerprint is 76E4 EC44 A889 E24C EF63 CB20 FBE6 99A2 4DBB 8F37

To claim this, I am signing this object: