Skip to content

Instantly share code, notes, and snippets.

@Kirens
Kirens / Variable-case-adjuster
Last active August 29, 2015 14:16
Turns a string into CamelCase, eg. "A string into CamelCase" -> "aStringIntoCamelCase"
var stringToCamelCase = function(string){
if(typeof string !== 'string')throw "Must be string";
//first character to lower case
string = string.charAt(0).toLowerCase() + string.slice(1);
//capitalize first letter after whitespace
return string.replace(/\s(\w)/g,function(){
return arguments[1].toUpperCase();
},'g');
@Kirens
Kirens / ftps.sh
Last active August 29, 2015 14:26
FTPS for debian wheezy on raspberry pi
#!/bin/sh
#automation of vsftpd installation as instructed by Justin Ellingwood @ DigitalOcean
#https://www.digitalocean.com/community/tutorials/how-to-configure-vsftpd-to-use-ssl-tls-on-an-ubuntu-vps
function pwd_prompt {
[ -z "$1" ] && return 1
local PWD1="1"
local PWD2="2"
@Kirens
Kirens / main.ws
Last active April 10, 2016 17:17
Whitespace countdown 10...0
| . . . . . . .
|.
. . . . .
| .
| .
. | . . . . . . .
| .
. | . . . .
| . . . | .
|.
@Kirens
Kirens / interpreter.bf
Created April 28, 2016 08:39
Brainf**k interpreter writen in Befunge. Code and Input is separated at NUL, ETX or EOT
v
0
v+1 p0\$\ < INTERPRETER PART + - < > . , b [ ]
>:~:5`#v_ $$$ 001p 00 > :0g :!#v_ :1-!#v_ :3-!#v_ :5-!#v_ :6-!#v_ :4-!#v_ :2-!#v_ :9-!#v_ :7-!#v_ :8-!#v_@ ] [
$ >176*+-:#v_ 1^CHAR + + @ $ $ $ $ $ $ $ $ >$ :1 >\1-: !#v_ :0g :8-!#v_ :7-!#v_ v
$ v_ #: #- #1 #< 2^CHAR , 1 \ \ \ \ \ \ \ \ @ v+1\$< v_v#:-1\$<
>1-:#v_ 3^CHAR - \ : : : 1 : : : ^ < < $# \$<
>1-:#v_ 4^CHAR . ^ p1\ +1 g1:< : v_@ + 1 ~ £ 1 [ v -1<]
>:: #v_$ 5^CHAR < ^ p1\ -1 g1< 1 g \ g > 1+
@Kirens
Kirens / Extension.js
Last active October 14, 2017 13:26
Tiny code snippets extending functionallity of JavaScript objects I tend to need a lot.
/**
* This callback is displayed as part of the Requester class.
* @callback criteria~fn
* @param {char} c The current char
* @param {Object} mem An object shared between the calls
*/
/**
* Reads a string into a new one, as long as some criteria is satisfied
* @this String
* @param {criteria~fn} fn function defining the criteria
@Kirens
Kirens / killScript.sh
Created January 31, 2017 15:19
This line kills all bash scripts matching a string
ps -eo pid,cmd | grep "[S]CRIPT_NAME" | grep -oP "^[^0-9]*\K[0-9]*" | xargs kill
@Kirens
Kirens / chrome
Last active November 26, 2018 20:57
Test of js engine optimization. V8 will produce machine-code of well-used functions. This unfortunately doesn't seem to run as well in Firefox
> var fTst = (v)=>((v - lomagic) & ~v & himagic)!=0;
himagic = 0x80808080;
lomagic = 0x01010101;
var fls = [], dt = [], a = 0x500000;
for(let i=0; i<20*a; i++){
if(fTst(i))fls.push(i);
if(i%a==0)dt.push(+new Date);
}//00000000
dt.map((v,i)=>v-dt[i-1])
@Kirens
Kirens / group.js
Created September 4, 2017 22:39
Google Apps script for spreadsheet that groups values in rows
/**
* Groups values in rows
*/
function group(vals, test, between){
vals = purify(vals);
test = purify(test);
if(vals.length!=test.length) throw "Vals ("+vals.length+") and Test ("+test.length+") must be of same size";
b = [-Infinity].concat( purify(between) ).concat([Infinity]);
@Kirens
Kirens / maybe.js
Created December 30, 2017 18:17
Maybe monad for JavaScript
const Just = function(v) {
if(!isJust(this)) return new Just(v);
this.value = v;
Object.freeze(this);
};
Just.prototype.bind = function(fn) {
let result = fn(this.value);
if(!isMaybe(result)) throw "Bind function not evaluating to Maybe";
@Kirens
Kirens / procedure.md
Created January 13, 2018 14:27
Deploying a NixOS server on DigitalOcean

Prerequisites

We'll use NixOps to deploy, so we need to install it

nix-env -i nixops

And to deploy on DigitalOcean we need to have an account and create an API access token for it.