Skip to content

Instantly share code, notes, and snippets.

@rexso
rexso / xkb-no-colemak
Last active September 22, 2016 07:44
Modified Colemak layout for Norwegian keyboards
// Add to /usr/share/X11/xkb/symbols/no
partial alphanumeric_keys
xkb_symbols "colemak" {
// Colemak layout - http://colemak.com/
include "no(basic)"
name[Group1]= "Norwegian (Colemak)";
@rexso
rexso / valueFromPath.js
Last active October 29, 2015 10:08
JavaScript function used solve a string path of an Object
function valueFromPath(object, path, separator) {
if("object" == typeof object && "string" == typeof path) {
var node = object;
if("string" != typeof separator || !separator.length) {
separator = "/";
}
for(var segment; path && (segment = path.split(separator)[0]); path = path.slice(segment.length + separator.length)) {
if("object" == typeof node) {
@rexso
rexso / dmd-build.sh
Last active October 28, 2015 14:40
Bash script for automatically building and installing dmd, druntime, phobos and optionally dub
#!/bin/bash
command -v make > /dev/null 2>&1 && MAKE=make || true
command -v g++ > /dev/null 2>&1 && GPP=g++ || true
if [[ $MAKE = "" ]]; then
echo "Failed to detect make. Please install make before proceeding"
exit 1
fi
@rexso
rexso / objArrUniqKeys.js
Created October 16, 2015 14:31
JS Function to filter array of objects
function objArrUniqKeys(arr, key) {
if(arr instanceof Array) {
var keys = [];
return arr.filter(function(elem, idx, arr) {
if(typeof elem == "object") {
if(elem.hasOwnProperty(key) && keys.indexOf(elem[key]) == -1) {
keys.push(elem[key]);
return true;
}
}
@rexso
rexso / ObserverArray.js
Last active October 1, 2015 09:26
JavaScript class extending Array with event observers
(function() {
"use strict";
function toArray(array) {
return Array.prototype.slice.call(array);
}
function watchProperty(context, property, callback, thisArg) {
var path = property, descriptor, writable, getter, setter, value;
@rexso
rexso / E.js
Last active August 29, 2015 14:27
Generic JavaScript DOM Element Creator
(function() {
function dom(value, context) {
return typeof value == "string" ? _.$(value, context) :
(value instanceof _ ? value.dom :
(value instanceof HTMLElement ? value : null));
}
function _(selector, options) {
if(selector instanceof _) {
return selector;
@rexso
rexso / base64.min.js
Last active August 31, 2015 12:30
JavaScript Base64 encoder/decoder (minified)
var base64={table:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",decode:function(t,e,r){function a(t){if(-1==(t=d.indexOf(t.charAt(0))))throw"invalid characater detected in base64.decode";return t}if(!(t=""+t).length)throw"invalid string length in base64.decode";var h,n,i=[],c=t.length,s=0,d=e?this.table.substr(0,62)+"-_":this.table;if(0==c||c%4&&!r)throw"invalid base64 string detected in base64.decode";for(c%4&&r?(s=4-c%4,c-=4):"="==t.charAt(c-1)&&(s="="==t.charAt(c-2)?2:1,c-=4),n=0;c>n;)h=a(t[n++])<<18|a(t[n++])<<12|a(t[n++])<<6|a(t[n++]),i.push(String.fromCharCode(h>>16,h>>8&255,255&h));switch(s){case 1:h=a(t[n++])<<18|a(t[n++])<<12|a(t[n++])<<6,i.push(String.fromCharCode(h>>16,h>>8&255));break;case 2:h=a(t[n++])<<18|a(t[n++])<<12,i.push(String.fromCharCode(h>>16))}return i.join("")},encode:function(t,e,r){function a(t){if((t=t.charCodeAt(0))>255)throw"invalid character detected in base64.encode";return t}if(!(t=""+t).length)throw"invalid string length in base64.encode";var h,n,i=[],c=t
@rexso
rexso / base64.js
Last active August 31, 2015 12:29
JavaScript Base64 encoder/decoder
var base64 = {
table: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/',
decode: function(str, urlSafe, autoPad) {
if(!(str = ('' + str)).length) {
throw 'invalid string length in base64.decode';
}
var b10, i, arr = [], len = str.length, padding = 0, table = (urlSafe ? this.table.substr(0, 62) + '-_' : this.table);
function charByte(c) {
(function(){
function ℓ(c){return(c.toLowerCase()==c);}
String.prototype.ℛ=function(e,s){return this.replace(e,s.length>1?s:function(m){return(ℓ(m[0])?s:s.toUpperCase());});};
function omgz0rify(s) {
return s
.ℛ(/s/ig,'z') // s -> z
.ℛ(/v/ig,'w') // v -> w
.ℛ(/o/ig,'0') // o -> 0
.ℛ(/ae/ig,'æ') // ae -> æ
@rexso
rexso / 12-mouse-rat.conf
Created January 22, 2015 20:53
X11 Configuration for Cyborg R.A.T.7 Mouse
# This configuration will enable the R.A.T.7 Mouse under X11 on GNU/Linux,
# by disabling the mode-selector button (recognized as buttons 13, 14 and 15).
# Add this configuration to /etc/X11/xorg.conf.d/12-mouse-rat.conf, and restart X.
# Good luck! :)
Section "InputClass"
Identifier "R.A.T.7 Mouse"
MatchProduct "Saitek Cyborg R.A.T.7 Mouse"
MatchDevicePath "/dev/input/event*"
Option "Buttons" "12"