Skip to content

Instantly share code, notes, and snippets.

View rendro's full-sized avatar
🤘
🤨

Robert rendro

🤘
🤨
View GitHub Profile
type TAction<T: $Subtype<string>, P> = {
type: T,
payload: P,
};
const ActionTypes = {
STRING: 'STRING',
NUMBER: 'NUMBER',
LOGIN: 'LOGIN',
LOGIN_PAGE: 'LOGIN_PAGE',
@rendro
rendro / jwtDecode.js
Created August 25, 2015 12:24
Simple decode of JWT claims
function jwtDecode(token) {
const [header, claims, signature] = token.split('.');
try {
return JSON.parse(atob(claims));
} catch (e) {
return false;
}
}
@rendro
rendro / parsecookie.js
Last active May 4, 2024 15:38
Parse document.cookie into object
document.cookie.split(';').map(function(c) {
return c.trim().split('=').map(decodeURIComponent);
}).reduce(function(a, b) {
try {
a[b[0]] = JSON.parse(b[1]);
} catch (e) {
a[b[0]] = b[1];
}
return a;
}, {});
@rendro
rendro / nanoproxy.js
Last active August 29, 2015 14:19
Nano node http proxy
var http = require('http');
http.createServer(function requestHandler(clientRequest, clientRespose) {
clientRequest.pipe(http.request({
host: 'localhost',
port: 3003,
path: clientRequest.url,
method: clientRequest.method,
headers: clientRequest.headers
}, function(serverResponse) {
clientRespose.writeHead(serverResponse.statusCode, serverResponse.headers);
@rendro
rendro / arrayChunk.js
Created April 20, 2015 16:08
Chunk an array
function arrayChunk(arr, chunkSize) {
return arr
.map((e, i) => i%chunkSize ? [] : [arr.slice(i, i + chunkSize)])
.reduce((a, b) => a.concat(b), []);
}
@rendro
rendro / ajax.js
Last active December 19, 2015 17:49
ajax
var ajax = (function () {
var getAjaxRequest = function (callback) {
var ajaxRequest = new XMLHttpRequest();
ajaxRequest.onreadystatechange = function() {
if (ajaxRequest.readyState === 4) {
callback(ajaxRequest.responseText);
}
};
return ajaxRequest;
};
@rendro
rendro / valiDate.js
Last active December 18, 2015 04:49
VALIDATE ALL THE DATES!!!!
var leadingZeros = function(num, length) {
length = length || 2;
num = String(num);
while (num.length < length) {
num = "0" + num;
}
return num;
};
var validDate = function(value) {
@rendro
rendro / pub-sub.js
Last active December 18, 2015 01:48
JavaScript Pub-Sub
var pubsub = (function () {
'use strict';
var observers = [];
return {
subscribe: function (events, listener) {
var event, i;
events = events.split(' ');
for (i in events) {
if (events.hasOwnProperty(i)) {
event = events[i];
@rendro
rendro / Preferences.sublime-settings
Last active December 16, 2015 19:51
Sublime Settings
{
"close_windows_when_empty": false,
"color_scheme": "Packages/Theme - Flatland/Flatland Monokai.tmTheme",
"dictionary": "Packages/Language - English/en_GB.dic",
"draw_white_space": "all",
"ensure_newline_at_eof_on_save": true,
"folder_exclude_patterns":
[
".svn",
".git",
@rendro
rendro / Default (OSX).sublime-keymap
Created April 30, 2013 08:27
Avoid accidentally added non-breaking spaces
[
{
"keys": ["alt+space"],
"command": "insert_snippet",
"args": {
"contents": " "
}
}
]