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
extern crate tokio_core; | |
extern crate futures_cpupool; | |
extern crate futures; | |
use std::time::Duration; | |
use std::thread; | |
use futures::stream::{self, Stream}; | |
use futures_cpupool::CpuPool; | |
use tokio_core::reactor::Core; |
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
#![feature(i128)] | |
#![feature(i128_type)] | |
use std::u128; | |
use std::net::{Ipv4Addr, Ipv6Addr}; | |
use ipnetwork::IpNetwork; | |
// Convert 128-bit number to ipv6 address. | |
fn decimal_to_ipv6(n: u128) -> Ipv6Addr { | |
Ipv6Addr::new( |
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
// curl -X POST --data-binary "@../massive.jpg" http://localhost:3001/uploads/xxx | |
// curl -X POST --data-binary "@../massive.jpg" http://localhost:3001/uploads/xxx --limit-rate 32k | |
'use strict' | |
const fs = require('fs') | |
const { EventEmitter } = require('events') | |
const express = require('express') | |
const PORT = 3001 |
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
// Since an Encoder and Decoder live as long as a Codec, I'd | |
// like for them both to share a reference to one instread | |
// of cloning it. | |
// | |
// And do I want refs or slices in this sort of situation? I seem to pick one at random. | |
// EXAMPLE | |
fn main() { |
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
// Middleware function creates a `ctx.render('homepage', { title, foo })` | |
// function on the koa context. | |
const reactRenderware = (root, _opts = {}) => { | |
const defaultOpts = () => ({ locals: {} }) | |
const { locals: globals, opts } = { ...defaultOpts(), ..._opts } | |
const { extname } = require('path') | |
const React = require('react') | |
const ReactDOMServer = require('react-dom/server') | |
const Master = require(path.join(root, 'master.jsx')) | |
return async (ctx, next) => { |
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
{ | |
console.log('=== body validation') | |
const body = { | |
uname: 'foo', | |
email: 'me@example.com', | |
pass1: 'secret', | |
pass2: 'secret', | |
} | |
const v = Validator.succeed(body) | |
.andThen(() => { |
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 { v, validate } from '.' | |
async function run() { | |
const body = { | |
uname: ' foo ', | |
pass1: 'secret', | |
pass2: 'secret', | |
nums: [1, 2, 3], | |
users: [{ uname: 'foo' }, { uname: 'bar' }], | |
a: { b: 42 }, |
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
const fs = require('fs') | |
const { join } = require('path') | |
module.exports = { crawlSync, crawlAsync } | |
function crawlSync(path) { | |
let cache = new Map() | |
const stats = fs.statSync(path) // <-- A | |
if (stats.isFile()) { |
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 { v, validate } from '.' | |
async function run() { | |
const body = { | |
uname: ' foo ', | |
pass1: 'secret', | |
pass2: 'secret', | |
nums: [1, 2, 3], | |
users: [{ uname: 'foo' }, { uname: 'bar' }], | |
a: { b: 42 }, |
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
map <c-p> previousTab | |
map <c-n> nextTab | |
map d removeTab | |
map u restoreTab | |
map <c-o> goBack | |
map <c-i> goForward | |
map <c-d> scrollPageDown | |
map <c-u> scrollPageUp |