Skip to content

Instantly share code, notes, and snippets.

View amacneil's full-sized avatar
🦊
Foxglove

Adrian Macneil amacneil

🦊
Foxglove
View GitHub Profile
async function foo() {
const userId = 42;
const user = await User.findById(userId);
return user.name;
}
function foo() {
const userId = 42;
async function foo() {
throw new Error('oops!');
}
function foo() {
return new Promise((resolve, reject) => {
reject(new Error('oops!'));
});
}
async function foo() {
return 42;
}
function foo() {
return new Promise((resolve, reject) => {
resolve(42);
});
}
app.get('/', async (ctx) => {
const sessionId = ctx.get('session-id');
const session = await Session.findById(sessionId);
const user = await User.findById(session.userId);
ctx.body = `Hello, ${user.name}!`;
});
app.get('/', (req, res, next) => {
const sessionId = req.get('session-id');
Session.findById(sessionId).then((session) => {
return User.findById(session.userId);
}).then((user) => {
res.send(`Hello, ${user.name}!`);
}).catch((err) => next(err));
});
app.get('/', (req, res, next) => {
const sessionId = req.get('session-id');
Session.findById(sessionId, (err, session) => {
if (err) {
return next(err);
}
User.findById(session.userId, (err, user) => {
if (err) {
const express = require('express');
const app = express();
app.get('/', (req, res) => {
res.send('Hello!');
});
contract VCStartup {
string public name = 'VC Startup';
string public symbol = '%';
uint8 public decimals = 6;
uint constant totalShares = 100000000;
// percent owned by each shareholder
mapping (address => uint) public balanceOf;
// array of owners
@amacneil
amacneil / json.py
Last active March 18, 2021 03:24
Safely JSON-encode objects in your Django template
from django.core.serializers.json import DjangoJSONEncoder
from django.template import Library
from json import dumps as json_dumps
register = Library()
@register.filter
def json(data):
"""
#!/bin/bash
set -ex
apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
echo "deb https://apt.dockerproject.org/repo ubuntu-trusty main" > /etc/apt/sources.list.d/docker.list
apt-get update
apt-get install -y linux-image-extra-$(uname -r) docker-engine
docker run -d -v bitcoin_data:/data --name bitcoin --net host --restart always amacneil/bitcoin
reboot