Skip to content

Instantly share code, notes, and snippets.

@Yogu
Yogu / find.js
Created February 7, 2014 13:54
Recursively find string in DOM
function find(object, search, cache, path) {
if (!cache)
cache = [];
if (!path)
path = '';
if (cache.indexOf(object) >= 0)
return;
cache.push(object);
for (var key in object) {
@Yogu
Yogu / rtc.js
Created September 30, 2014 12:02
Simple RTCDataChannel setup
var RTCPeerConnection = window.mozRTCPeerConnection || window.webkitRTCPeerConnection || window.RTCPeerConnection;
var RTCSessionDescription = window.mozRTCSessionDescription || window.webkitRTCSessionDescription || window.RTCSessionDescription;
var RTCIceCandidate = window.mozRTCIceCandidate || window.webkitRTCIceCandidate || window.RTCIceCandidate;
var RTC_CONFIGURATION = {"iceServers": [{"url": "stun:stun.l.google.com:19302"}]};
var MEDIA_CONSTRAINTS = {optional: [{internalSctpDataChannels: true},{DtlsSrtpKeyAgreement: true}]};
function errorCallback(error) {
console.log(error);
}
import org.joda.time.LocalDate;
import org.joda.time.Years;
public class DateTest {
public static void main(String[] args) {
LocalDate start = LocalDate.parse("2012-01-28"); // leap year
LocalDate end = LocalDate.parse("2013-01-27");
LocalDate end2 = LocalDate.parse("2013-01-28");
System.out.println(end.isBefore(start.plus(Years.ONE))); // true
System.out.println(end2.isBefore(start.plus(Years.ONE))); // false
<script>
window.onbeforeunload = function() {
return "confirm";
}
var i = 0;
setInterval(function() {
document.getElementById('display').innerHTML = i++;
}, 100);
@Yogu
Yogu / block-texture.png
Last active January 1, 2017 17:50
blockstate-info
block-texture.png
@Yogu
Yogu / block-texture.png
Last active July 26, 2017 21:48
blockstates-extended
block-texture.png
type max avg
native 116 16
native 109 19
native 123 17
native 194 16
native 125 19
native 118 17
native 141 17
native 126 17
native 132 16
interval cycles total time median latency median runtime 99% percentile latency 99% percentile runtime 99.9% percentile latency 99.9% percentile runtime maximum latency maximum runtime
500000 20000 00:00:10 8005 937 21275 2343 31436 28750 41410 51509
500000 40000 00:00:20 15080 1770 17790 1979 24525 2500 37257 3542
500000 80000 00:00:40 15175 1719 18188 2031 24735 2760 46518 5364
500000 160000 00:01:20 15055 1770 17672 1980 23859 2500 46035 4323
500000 320000 00:02:40 15269 1719 17935 2031 23190 2448 32124 4010
500000 640000 00:05:20 15193 1770 17692 1979 20731 2448 34344 3958
500000 1280000 00:10:40 15232 1770 17576 1979 22202 2240 50918 31146
500000 2560000 00:21:20 15086 1770 17600 1979 19680 2344 48288 4167
500000 5120000 00:42:40 15064 1770 17537 1979 19592 2395 47834 12864
@Yogu
Yogu / format-message.d.ts
Last active September 11, 2018 15:10
format-message typings (outdated, see this PR: https://github.com/format-message/format-message/pull/206)
declare module 'format-message-parse' {
namespace parse {
export type AST = Element[]
export type Element = string | Placeholder
export type Placeholder = Plural | Styled | Typed | Simple
export type Plural = [string, 'plural' | 'selectordinal', number, SubMessages]
export type Styled = [string, string, string | SubMessages]
export type Typed = [string, string]
export type Simple = [string]
@Yogu
Yogu / socket-keeper.ts
Last active March 19, 2020 23:51
max-age for keep-alive in node
import { injectable } from 'inversify';
import { Logger } from 'log4js';
import { Socket } from 'net';
import Timer = NodeJS.Timer;
export interface KeepaliveOptions {
/**
* The maximum time in milliseconds an unused socket will be kept alive before it will be closed
*
* This should be set to a smaller value than the server's keepalive timeout to avoid a race condition