Skip to content

Instantly share code, notes, and snippets.

View antfu's full-sized avatar

Anthony Fu antfu

View GitHub Profile
@Splagoon
Splagoon / time.kt
Created November 11, 2014 18:50
Time magics with Kotlin
import java.util.Date
import kotlin.concurrent.*
fun at(date: Date, func: () -> Unit) {
val waitTime = date.getTime() - Date().getTime()
thread {
Thread.sleep(waitTime)
func()
}
}
@antfu
antfu / swap.md
Created April 11, 2019 22:45
Create swap
@Zhenmao
Zhenmao / README.MD
Created January 20, 2018 10:06
Donut Chart with Labels and Missing Values D3.js V4
type ParseResult = {
success: boolean,
data: any,
source: string
}
type ParseFailed = {
suceess: false,
data: any,
source: string
//Task: Find the greatest common divisor for an array of integers
//Tags: array, gcd
let arr = [6, 9, 21]
let gcd = function(a, b) {
a = Math.abs(a)
b = Math.abs(b)
while (a != b) {
if (a > b) a -= b
const bypass = [
// function names to avoid logging
];
const collapsed = [
// function names to groupCollapsed
];
module.exports = function(babel) {
const { types: t } = babel;
const wrapFunctionBody = babel.template(`{
@vladimirtsyupko
vladimirtsyupko / gist:10964772
Created April 17, 2014 08:32
Git force pull to overwrite local files
git fetch --all
git reset --hard origin/master
git pull origin master
@antfu
antfu / doc-table.md
Last active October 14, 2023 20:09
Doc Table in Markdown

Example

Name

Description


@pbojinov
pbojinov / README.md
Last active December 8, 2023 21:09
Two way iframe communication- Check out working example here: http://pbojinov.github.io/iframe-communication/

Two way iframe communication

The main difference between the two pages is the method of sending messages. Recieving messages is the same in both.

Parent

Send messages to iframe using iframeEl.contentWindow.postMessage Recieve messages using window.addEventListener('message')

iframe

@reimund
reimund / dict2xml.py
Last active December 25, 2023 06:09
Simple dictionary to xml serializer.
"""
Simple xml serializer.
@author Reimund Trost 2013
Example:
mydict = {
'name': 'The Andersson\'s',
'size': 4,