Skip to content

Instantly share code, notes, and snippets.

const ROMAN_MAP = {
'I': 1,
'V': 5,
'X': 10,
'L': 50,
'C': 100,
'D': 500,
'M': 1000
};
@behcet
behcet / bitwise-not.js
Last active December 14, 2017 06:19
javascript bitwise not operator
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators
function createBinaryString (nMask) {
// nMask must be between -2147483648 and 2147483647
for (var nFlag = 0, nShifted = nMask, sMask = ''; nFlag < 32;
nFlag++, sMask += String(nShifted >>> 31), nShifted <<= 1);
return sMask;
}
[-2, -1, 0, 1, 2].forEach(number => {
console.log(number + ' \t\t\t\t\t==>\t ' + ~number + ' \n' +
# Touchpad
# This option enables the bottom right corner to be a right button on clickpads
# and the right and middle top areas to be right / middle buttons on clickpads
# with a top button area.
# This option is only interpreted by clickpads.
Section "InputClass"
Identifier "Ignore clickpad buttons"
MatchDriver "synaptics"
Option "SoftButtonAreas" "0 0 0 0 0 0 0 0"
@behcet
behcet / fibonacci.js
Created June 14, 2017 23:09
Fibonacci closure
const fib = (function fib () {
var prev = [ 0, 0 ];
return () => {
let value = prev.shift() + Math.max(prev.find(i => i > -1), 1);
prev.push(value);
return value;
};
})();
function getAchievements (dom) {
return Array.prototype.map.call(dom.querySelectorAll('table.data div.Achievement'), function (a) {
return a.classList.value.match(/Achievement_(\d+)/).shift();
});
}
function removeOverlapping (ach1, ach2) {
var table = document.querySelector('table.data');
ach1.forEach(function (a) {
if (ach2.indexOf(a) < 0) {
function getShowHash (element) {
return Array.prototype.map.call(element.querySelectorAll('table.data tr'), function (row) {
var key = row.querySelector('.sortkey');
var city = row.querySelector('a[href*="City"]');
if (!key || !city) { return; }
key = key.textContent;
city = city.href.match(/\d+$/).pop();
return { city: city, key: key };
})
.filter(function (i) { return i; })
// remove duplicates
['such', 'wow',' amaze', 'wow', 'very', 'very'].filter(function (elem, index, src) {
return src.indexOf(elem, index+1) < 0;
})