Skip to content

Instantly share code, notes, and snippets.

@raybellis
raybellis / random.js
Last active March 15, 2022 21:17
Emulation of java.util.Random in Javascript
class UInt48 {
constructor(n) {
if (n instanceof UInt48) {
Object.assign(this, n);
} else if (typeof n === 'number') {
let w0 = n & 0xffff;
n /= 0x10000;
let w1 = n & 0xffff;
n /= 0x10000;
@lukaseder
lukaseder / CallDefaultMethodThroughReflection.java
Created March 28, 2018 09:56
Correct Reflective Access to Interface Default Methods in Java 8, 9, 10
// Compile on JDK 9 or 10 with javac -source 1.8 -target 1.8 CallDefaultMethodThroughReflection.java
// Blog post here: https://blog.jooq.org/2018/03/28/correct-reflective-access-to-interface-default-methods-in-java-8-9-10
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodHandles.Lookup;
import java.lang.invoke.MethodType;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
@jimmywarting
jimmywarting / readme.md
Last active April 21, 2024 15:32
Cors proxies
Exposed headers
Service SSL status Response Type Allowed methods Allowed headers
// paste in your console
speechSynthesis.onvoiceschanged = function() {
var msg = new SpeechSynthesisUtterance();
msg.voice = this.getVoices().filter(v => v.name == 'Cellos')[0];
msg.text = Object.keys(window).join(' ');
this.speak(msg);
};
@remojansen
remojansen / class_decorator.ts
Last active September 14, 2023 14:54
TypeScript Decorators Examples
function logClass(target: any) {
// save a reference to the original constructor
var original = target;
// a utility function to generate instances of a class
function construct(constructor, args) {
var c : any = function () {
return constructor.apply(this, args);
}
@leodutra
leodutra / bitwise-hacks.js
Last active October 30, 2023 02:37
Fast Int Math + Bitwise Hacks For JavaScript
// http://michalbe.blogspot.com.br/2013/03/javascript-less-known-parts-bitwise.html
// http://jsperf.com/bitwise-vs-math-object
// http://united-coders.com/christian-harms/results-for-game-for-forfeits-and-the-winner-is/
// https://mudcu.be/journal/2011/11/bitwise-gems-and-other-optimizations/
// https://dreaminginjavascript.wordpress.com/2009/02/09/bitwise-byte-foolish/
// http://jsperf.com/math-min-max-vs-ternary-vs-if/24
"use strict";
var PI = Math.PI;
@willurd
willurd / web-servers.md
Last active April 25, 2024 09:21
Big list of http static server one-liners

Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.

Discussion on reddit.

Python 2.x

$ python -m SimpleHTTPServer 8000
@tcr
tcr / gist:4416956
Last active November 29, 2017 03:38
Make a callable() object in all browsers and Node.js
if (!Object.__proto__) {
var sandbox = function () {
// create an <iframe>
var iframe = document.createElement("iframe");
iframe.style.display = "none";
document.documentElement.appendChild(iframe);
return frames[frames.length - 1];
}
var iframe = sandbox();
@abernier
abernier / Readme.md
Last active April 24, 2024 08:33
Link anatomy