Skip to content

Instantly share code, notes, and snippets.

View datatypevoid's full-sized avatar

Null Void datatypevoid

View GitHub Profile
@datatypevoid
datatypevoid / d_copy.lua
Created March 23, 2017 15:09 — forked from MihailJP/d_copy.lua
Shallow- and deep-copy of table in Lua
function clone (t) -- deep-copy a table
if type(t) ~= "table" then return t end
local meta = getmetatable(t)
local target = {}
for k, v in pairs(t) do
if type(v) == "table" then
target[k] = clone(v)
else
target[k] = v
end
@datatypevoid
datatypevoid / deepcopy.lua
Created March 23, 2017 15:09 — forked from Deco/deepcopy.lua
Lua Non-recursive Deep-copy
--[[ deepcopy.lua
Deep-copy function for Lua - v0.2
==============================
- Does not overflow the stack.
- Maintains cyclic-references
- Copies metatables
- Maintains common upvalues between copied functions (for Lua 5.2 only)
TODO

1. Clone your fork:

git clone git@github.com:YOUR-USERNAME/YOUR-FORKED-REPO.git

2. Add remote from original repository in your forked repository:

cd into/cloned/fork-repo
git remote add upstream git://github.com/ORIGINAL-DEV-USERNAME/REPO-YOU-FORKED-FROM.git
git fetch upstream
@datatypevoid
datatypevoid / gist:55dffe081e0080e8ddcf05199cd23f49
Created July 23, 2017 13:16 — forked from lingo/gist:5e53d2cb5b282d53d912
Separation of logic from request handlers
// mylogic.js
var MyLogic = {
_currentAccount: null,
fetchAccountByID: function(id) {
// fetch account from database, use promises to reject/resolve
},
setCurrentAccount: function(account) {
MyLogic._currentAccount = account;
}
@datatypevoid
datatypevoid / repo-rinse.sh
Created October 7, 2017 00:22 — forked from nicktoumpelis/repo-rinse.sh
Cleans and resets a git repo and its submodules
git clean -xfd
git submodule foreach --recursive git clean -xfd
git reset --hard
git submodule foreach --recursive git reset --hard
git submodule update --init --recursive
@datatypevoid
datatypevoid / gh-deploy-clone.sh
Created October 11, 2017 13:01 — forked from blvz/gh-deploy-clone.sh
Creates a deploy key and clones the repository.
#!/usr/bin/env bash
read -r -d '' usage << EOM
Usage:
gh-deploy-clone user/repo [ENVIRONMENT]
EOM
[ -z "$1" ] && echo && echo "$usage" && echo && exit 1
@datatypevoid
datatypevoid / Dockerfile
Created October 31, 2017 17:17 — forked from remarkablemark/Dockerfile
Install node and npm with nvm using Docker.
# set the base image to Debian
# https://hub.docker.com/_/debian/
FROM debian:latest
# replace shell with bash so we can source files
RUN rm /bin/sh && ln -s /bin/bash /bin/sh
# update the repository sources list
# and install dependencies
RUN apt-get update \
@datatypevoid
datatypevoid / client.js
Created November 6, 2017 17:03 — forked from PaulMougel/client.js
File upload in Node.js to an Express server, using streams
// node: v0.10.21
// request: 2.27.0
var request = require('request');
var fs = require('fs');
var r = request.post("http://server.com:3000/");
// See http://nodejs.org/api/stream.html#stream_new_stream_readable_options
// for more information about the highWaterMark
// Basically, this will make the stream emit smaller chunks of data (ie. more precise upload state)
var upload = fs.createReadStream('f.jpg', { highWaterMark: 500 });
@datatypevoid
datatypevoid / jwtRS256.sh
Created January 28, 2018 21:53 — forked from ygotthilf/jwtRS256.sh
How to generate JWT RS256 key
ssh-keygen -t rsa -b 4096 -f jwtRS256.key
# Don't add passphrase
openssl rsa -in jwtRS256.key -pubout -outform PEM -out jwtRS256.key.pub
cat jwtRS256.key
cat jwtRS256.key.pub
@datatypevoid
datatypevoid / color-conversion-algorithms.js
Created February 2, 2018 03:41 — forked from mjackson/color-conversion-algorithms.js
RGB, HSV, and HSL color conversion algorithms in JavaScript
/**
* Converts an RGB color value to HSL. Conversion formula
* adapted from http://en.wikipedia.org/wiki/HSL_color_space.
* Assumes r, g, and b are contained in the set [0, 255] and
* returns h, s, and l in the set [0, 1].
*
* @param Number r The red color value
* @param Number g The green color value
* @param Number b The blue color value
* @return Array The HSL representation