Skip to content

Instantly share code, notes, and snippets.

View toastal's full-sized avatar
🚪
Offer alt mirror so I can delete my account w/ MS GitHub finally

toastal

🚪
Offer alt mirror so I can delete my account w/ MS GitHub finally
View GitHub Profile
var str1 = '0100100001100101011011000110110001101111001000000101011101101111011100100110110001100100';
var str2 = '0111000001101100011001010110000101110011011001010010000001110100011000010110110001101011001000000111010001101111001000000110110101100101';
var str3 = '011011000110100101100110011001010010000001110010011010010110011101101000011101000010000001101110011011110111011100100000011010010111001100100000011011000110111101101110011001010110110001111001';
var binStr2ASCII = (str) => {
return str.match(/[01]{8}/g).map(x => String.fromCharCode(parseInt(x, 2))).join('');
};
var testStrs = [str1, str2, str3];
@toastal
toastal / gist:01c2387456ad2e6385f4
Last active October 18, 2021 07:54
Open All Links In a New Tab
// Open all links on a page in new tab -- for MBW
// Requires ECMAScript 6's `Set()` for getting unique urls
// I'm too lazy to write a `uniq` function nor do I want to pull in a 3rd party lib
// Works in Firefox 25+, Chrome 38+, Opera 25+, Safari 7.1+, Internet Explorer 11+
new Set(
Array.prototype.filter.call(document.querySelectorAll('a[href],area[href]'), function(acc, el) {
el.href[0] !== '#' && acc.push(el)
return acc
}, [])
).forEach(function(href) {
@toastal
toastal / urlParser.js
Last active October 18, 2021 08:16
Ramda URL Parser
// requires Ramda (http://ramdajs.com/)
// urlParser : String -> Object
;urlParser = (function(document, R) {
"use strict";
const {fromPairs, pipe, reduce, replace, split} = R;
let parser = document.createElement("a");
// searchToKeyVal : String -> Object
@toastal
toastal / .vimrc
Last active October 18, 2021 08:15
if !1 | finish | endif
if has('vim_starting')
set nocompatible " Be iMproved
" Required:
set runtimepath+=~/.vim/bundle/neobundle.vim/
endif
;; User behaviors
;; -----------------------------
;; Behaviors are stored as a set of diffs that are merged together
;; to create the final set of functionality that makes up Light Table. You can
;; modify these diffs to either add or subtract functionality.
;;
;; Behaviors are added to tags, objects with those tags then automatically gain
;; whatever logic the behavior imparts. To see a list of user-level behaviors,
;; start typing a word related to the functionality you want in between the square
;; brackets (e.g. "theme").
# Prefix to Ctrl-a like `screen`
set -g prefix C-a
bind C-a send-prefix
unbind C-b
set -sg escape-time 1
set -g base-index 1
setw -g pane-base-index 1
# Mouse works as expected
@toastal
toastal / recursive-multisort.js
Last active October 18, 2021 08:11
Recursive Mulitsort
let data =
[ [{value: 0}, {value: 3}, {value: "c"}]
, [{value: 2}, {value: 1}, {value: "a"}]
, [{value: 1}, {value: 2}, {value: "b"}]
, [{value: 1}, {value: 3}, {value: "b"}]
];
let sorter = [[1, false], [2, false]];
@toastal
toastal / tail-recursive-closest.js
Last active October 18, 2021 08:09
Tail-Recursive `Element.prototype.closest` Polyfill
/*
* Element.matches()
* https://developer.mozilla.org/en-US/docs/Web/API/Element/matches
* The Element.matches() method returns true if the element would be selected
* by the specified selector string; otherwise, returns false.
*
* Prefixed Support: Android 2.2, Internet Explorer 9, Edge 12, Safari 5.0
* Unprefixed Support: Chrome 34, Firefox 34, Safari 7.1, iOS Safari 8.0
*/
@toastal
toastal / 0-param-lodash-original-to-be-refactored.js
Last active October 18, 2021 08:08
Object to Query String Refactors
// Well the string building is pretty dopey with the `+=` append on
// a forEach instead of a map, but that slice on the last char sends
// shivers of cringe up my spine.
_.mixin({
param: function(obj) {
var param = "";
_.forEach(obj, function(val, key) {
param += key + "=" + val + "&";
});
(into [:dl]
(map #(vector %1 %2) (cycle [:dt :dd]) (flatten (vec (clojure.walk/stringify-keys {:test "me" :foo "bar"})))))
;=> [:dl [:dt "test"] [:dd "me"] [:dt "foo"] [:dd "bar"]]