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
/* | |
The MIT License (MIT) | |
Copyright (c) 2010 Blixt | |
Permission is hereby granted, free of charge, to any person obtaining a copy of | |
this software and associated documentation files (the "Software"), to deal in | |
the Software without restriction, including without limitation the rights to | |
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | |
the Software, and to permit persons to whom the Software is furnished to do so, |
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 Waiter(context) { | |
if (context) { this.context = context; } | |
} | |
Waiter.prototype.failed = function (cb) { | |
if (this.result) { | |
if (!this.success) { cb.apply(this.context || this, this.result); } | |
} else { | |
if (!this.failedCbs) { this.failedCbs = []; } | |
this.failedCbs.push(cb); |
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
var procedural = require('procedural'); | |
var avatar = procedural('avatar') | |
// The block size is just visual, so it shouldn't affect randomization. | |
.doNotHash('blockSize') | |
// The username is needed to create a unique avatar for every user. | |
.takes('username') | |
// Size, in blocks. Different sizes will create different avatars. | |
.takes('size', function validate(avatar, blocks) { | |
// Ensure that size is a positive integer divisible by 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
var avatar = procedural('avatar') | |
.takes('username') | |
// Size, in blocks. | |
.takes('size', function validate(avatar, blocks) { | |
return typeof blocks == 'number' && blocks > 0; | |
}) | |
// The pixel size of a single (square) block. | |
.takes('blockSize', function validate(avatar, px) { | |
return typeof px == 'number' && px > 0; | |
}) |
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
package main | |
import ( | |
"fmt" | |
"sync" | |
"time" | |
) | |
// Dedupe will combine a bunch of concurrent calls with the same key (string) into just one. | |
// Example: |
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
import { useEffect, useRef, useState } from "react" | |
interface IO<T> { | |
setters: ((value: T) => void)[] | |
update: (value: T) => void | |
value: T | undefined | |
} | |
const store: { [name: string]: IO<any> | undefined } = {} |
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
package main | |
import ( | |
"bufio" | |
"fmt" | |
"io" | |
"io/ioutil" | |
"log" | |
"net/http" | |
"net/http/httptest" |
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
// Return a type with only the methods of T that return R. | |
type MethodsWithReturnType<T, R> = { | |
[P in keyof T]: T[P] extends () => infer RR ? (RR extends R ? P : never) : never | |
}[keyof T] | |
// Filter away all keys except methods that return void and | |
// return a new type with those methods returning booleans. | |
type VoidMethodsToBoolMethods<T> = { [P in MethodsWithReturnType<T, void>]: () => boolean } | |
// Our test input class: |
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
# -*- coding: utf-8 -*- | |
import sys | |
_last_status = None | |
_last_status_permille = 0 | |
def print_status(status=None, fraction=0): | |
global _last_status, _last_status_permille | |
permille = int(fraction * 1000) | |
if status != _last_status: |
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
# First, outside the Dockerfile: | |
tar --exclude ./static-large --exclude-from=.dockerignore -czf non-large.tar.gz ./* | |
# Then, in the Dockerfile: | |
COPY static-large $WORKDIR_PATH/static-large/ | |
ADD non-large.tar.gz $WORKDIR_PATH/ |