View _js-useful.js
function isBetween(num, range) {
// returns true if number is within range
// range is array [lowernum, highernum]
let [min, max] = range;
let rez = num >= min && num <= max;
// console.log('isBetween:', rez, num, range.join('-'));
return rez;
}
function isOverlap(range1, range2) {
// depends on isBetween
View _js-primesBetween.js
function primesBetween(min, max) {
// inclusive
// collect all possible dividends
let dividends = [];
for (let i=min; i<=max; i++) // inclusive
dividends.push(i);
// console.log('dividends:', dividends);
View _javascript-findBinary.js
function findBinary(arr, num, ixmin=0, ixmax) {
// arr MUST be sorted!!! and only numbers!!! duh! see: https://en.wikipedia.org/wiki/Binary_search_algorithm
// ixmin and ixmax are programtic use only, meaning devuser should NEVER supply value for it
if (ixmax === undefined) ixmax = arr.length;
let ixmid = Math.floor((ixmax-ixmin)/2) + ixmin;
let elmid = arr[ixmid];
if (elmid === num) return elmid;
View _ff-addon-getTxtForCode.js
function getTxtForCode(aErrorCode) {
Cu.import('resource://gre/modules/ctypes.jsm');
let kernel = ctypes.open('kernel32');
const IFDEF_UNICODE = true;
// types for FormatMessage
let DWORD = ctypes.uint32_t;
let LPCVOID = ctypes.voidptr_t;
let CHAR = ctypes.char;
let WCHAR = ctypes.jschar;
View _js-findClosestLocale.js
// rev3 - https://gist.github.com/Noitidart/110c2f859db62398ae76069f4a6c5642
/**
* Selects the closest matching locale from a list of locales.
*
* @param aLocales
* An array of available locales
* @param aMatchLocales
* An array of prefered locales, ordered by priority. Most wanted first.
* Locales have to be in lowercase.
* @return the best match for the currently selected locale
View _es6-BFS-DFS.js
// getChildren(win) - returns array of windows that are child to `win`
// isTrue(win) - just a random callback
function recurseDFS(win) {
// depth first
let coll = [];
coll.push(isTrue(win));
let children = getChildren(win);
for (let child of children) {
coll.push(...recurseDFS(child));
View x11-keylogger.c
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <signal.h>
#include <string.h>
#include <unistd.h> // for usleep() only
#include <sys/time.h>
#include <sys/types.h>
#include <time.h>
View gist:80d00ae9147f1ab917099d43fbb012e9
Cu.import('resource://gre/modules/ctypes.jsm');
var objc = ctypes.open(ctypes.libraryName('objc'));
// BASIC TYPES
var CHAR = ctypes.char;
var ID = ctypes.voidptr_t;
var SEL = ctypes.voidptr_t;
var BOOL = ctypes.signed_char;
var NSUINTEGER = ctypes.unsigned_long;
View _webext-storageCall.js
// rev2 - https://gist.github.com/Noitidart/bcb964207ac370d3301720f3d5c9eb2b
var _storagecall_pendingset = {};
var _storagecall_callid = 1;
function storageCall(aArea, aAction, aKeys, aOptions) {
// because storage can fail, i created this, which goes until it doesnt fail
// aAction - string;enum[set,get,clear,remove]
// aKeys -
// if aAction "clear" then ignore
// if aAction "remove" then string/string[]
View _c++-parseLsof.cpp
#include <string.h>
#include "json.hpp" // https://github.com/nlohmann/json/tree/develop/src
using json = nlohmann::json;
json parseLsof(std::string str) {
json rez = json::array();
json headers{ json::array() };
// [ {name:'BLAH', min:0, max:0} ] // min max are indexes (1 col padding exclusive) (pad can be on both sides if in middle, or if first entry one on right, or if last entry then one on left)
bool hdone = false; // header_done