This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function fc2int(fc) { | |
const codes = '0123456789ABCDEFGHJKLMNPQRSTUVWXY'; | |
fc = fc.toUpperCase().match(new RegExp(`[${codes}]`, 'g')); | |
return -1 + fc | |
.map((a, i) => (codes.indexOf(a) + 1) * Math.pow(codes.length - 1, i)) | |
.reduce((a, b) => a + b); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Simple more advanced arguments parsing than builtin tools like getopts or a simple while/case looping over the arguments | |
# | |
# Features include handling of: | |
# - multiple grouped shorthands (f.i. -abc becoming -a -b -c), | |
# - equal sign value assignment (f.i. --arg=value becoming --arg value, and also -a=value becoming -a value) | |
# - dashless value assignment (f.i. arg=value becoming arg value) | |
# | |
# The only dependencies are bash (for arrays) and expr (included in coreutils) (for regexp matching and extraction) which are likely available everywhere (even in a busybox or on a mac!) | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
This isn't supposed to be pretty or ever be used in production code (don't even think about it), but has proven useful for quick debugging when working with reflections. | |
*/ | |
// Example Method with some more interesting modifiers | |
Method meth = Arrays.stream(data.getClass().getDeclaredMethods()).filter(m -> "getChronology".equals(m.getName())).toArray()[0]; | |
// Should return "isSynthetic, isPublic, isVolatile" | |
String modifiers = Arrays.stream(Modifier.class.getDeclaredMethods()) | |
.map(m -> { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let oauthToken = document.cookie.match(/auth-token=([0-9a-z]+);/)[1]; | |
const updateChatColor = function (chatColor) { | |
fetch('https://gql.twitch.tv/gql', { | |
method: 'POST', | |
body: JSON.stringify({ | |
query: | |
`mutation Chat_UpdateChatColor(\$input: UpdateChatColorInput!) { | |
updateChatColor(input: \$input) { | |
user { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function fetchPage(link, callback) { | |
var xhr = new XMLHttpRequest(); | |
xhr.open('get', link); | |
xhr.onreadystatechange = function () { | |
if (xhr.readyState == 4 && xhr.status == 200) | |
callback.call(xhr, xhr); | |
}; | |
xhr.send(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function () { | |
var S4 = function (n, d) { | |
return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1) + (n > 1 ? (d || '') + S4(n - 1, d) : ''); | |
}; | |
return (String.fromCharCode(97 + Math.floor(Math.random() * 26)) + S4().substring(1) + S4(5, '-') + S4(2)); | |
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* GenericObject / objectify.js | |
* | |
* Creating new objects with neat setters and getters over again is annoying, so let's automate it. | |
* | |
* @author Alexander Schulz (alex@nope.bz) | |
*/ | |
var Objectify = (function () { | |
"use strict"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Recurses through an object to search for an identifier. | |
* Identifier is a RegExp. | |
* Returns either the first match or false. | |
*/ | |
function search (obj, term) { | |
for (var k in obj) { | |
if (obj.hasOwnProperty(k)) { | |
if (k == term) return k; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Twig REPL hack | |
* | |
* Arnaud Le Blanc <arnaud.lb@gmail.com> | |
*/ | |
require 'vendor/twig/twig/lib/Twig/Autoloader.php'; | |
Twig_Autoloader::register(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Cache () { | |
"use strict"; | |
if (this.constructor != Cache) throw new TypeError("Constructor Cache requires 'new'"); | |
/* | |
A dumb, simple cache, to make access to cross-pageload variables easy and manageable. | |
All cache times are in milliseconds. | |
*/ | |
var storage = window['localStorage']; |
NewerOlder