Skip to content

Instantly share code, notes, and snippets.

View mightyguava's full-sized avatar

Yunchi Luo mightyguava

View GitHub Profile
@mightyguava
mightyguava / Author.kt
Last active January 24, 2020 17:08
Example of sqlc generated code for the authors example
package com.example.testmodule
import java.sql.Connection
import java.sql.SQLException
data class Author(val id: Long, val name: String, val bio: String?);
const val createAuthor = """-- name: CreateAuthor :one
INSERT INTO authors (
name, bio
@mightyguava
mightyguava / gist:785d26308beff1321297c798e907a92b
Created March 29, 2019 21:34
misk.web.ssl.PemSslClientServerTest deadlock jstack
2019-03-29 20:52:14
Full thread dump OpenJDK 64-Bit Server VM (11.0.2+9 mixed mode):
Threads class SMR info:
_java_thread_list=0x00007fcb140093e0, length=34, elements={
0x00007fcb58017800, 0x00007fcb5811f000, 0x00007fcb58123000, 0x00007fcb58135800,
0x00007fcb58137800, 0x00007fcb5813a000, 0x00007fcb5813c000, 0x00007fcb5819d000,
0x00007fcb581aa000, 0x00007fcb58ac3000, 0x00007fcb58ae6000, 0x00007fcb58ae1000,
0x00007fcb04bb9000, 0x00007fcb04bbb000, 0x00007fcb04c67000, 0x00007fcb04c68000,
0x00007fcb04c69800, 0x00007fcb04c6b800, 0x00007fcb04c6d800, 0x00007fcb04c78000,
@mightyguava
mightyguava / promisify-callback-hell.js
Created March 15, 2017 15:33
Demystifying Async Programming in Javascript - Promisify callback hell
getUserData()
.then(getUserData)
.then(doMoreStuff)
.then(getEvenMoreUserData)
.then(doEvenMoreStuff)
.then(getYetMoreUserData)
.then(doYetMoreStuff);
@mightyguava
mightyguava / co-error-solution.js
Created March 12, 2017 19:26
Demystifying Async Programming in Javascript - co() error solution
function co(generator) {
return new Promise((resolve, reject) => {
const g = generator();
function onResolve(value) {
let ret;
try {
ret = g.next(value);
} catch (e) {
@mightyguava
mightyguava / co-error-challenge.js
Created March 12, 2017 19:20
Demystifying Async Programming in Javascript - co() error challenge
function deferred(val) {
return new Promise((resolve, reject) => resolve(val));
}
function deferReject(e) {
return new Promise((resolve, reject) => reject(e));
}
co(function* asyncAdds() {
console.log(yield deferred('We are starting!'));
@mightyguava
mightyguava / co-simple-solution.js
Last active March 12, 2017 19:18
Demystifying Async Programming in Javascript - co() simple solution
function co(generator) {
return new Promise((resolve, reject) => {
const g = generator();
function next(nextVal) {
const ret = g.next(nextVal);
if (ret.done) {
return resolve(ret.value);
}
@mightyguava
mightyguava / co-simple-challenge.js
Last active March 12, 2017 19:19
Demystifying Async Programming in Javascript - co() simple challenge
function deferred(val) {
return new Promise((resolve, reject) => resolve(val));
}
co(function* asyncAdds() {
console.log(yield deferred(1)); // 1
console.log(yield deferred(2)); // 2
console.log(yield deferred(3)); // 3
return 4;
}).then(function (result) {
@mightyguava
mightyguava / fetchJson-async-await.js
Created March 12, 2017 19:11
Demystifying Async Programming in Javascript - fetchJson async await
async function () {
var user = await fetchJson('/api/user/self');
var interests = await fetchJson('/api/user/interests?userId=' + self.id);
var recommendations = await Promise.all(
interests.map(i => fetchJson('/api/recommendations?topic=' + i)));
render(user, interests, recommendations);
}();
@mightyguava
mightyguava / generator-error-propagation-solution.js
Created March 12, 2017 19:04
Demystifying Async Programming in Javascript - Generator internals error propagation
function adder(initialValue) {
let state = 'initial';
let done = false;
let sum = initialValue;
let lastSum;
let temp;
function go(input, err) {
let result;
@mightyguava
mightyguava / generator-internals-reverting-adder.js
Created March 12, 2017 18:58
Demystifying Async Programming in Javascript - Generator internals reverting adder
function* adder(initialValue) {
let sum = initialValue;
let lastSum = initialValue;
let temp;
while (true) {
try {
temp = sum;
sum += yield sum;
lastSum = temp;
} catch (e) {