Skip to content

Instantly share code, notes, and snippets.

@huytd
huytd / co-in-15-lines.js
Last active May 25, 2016 10:10
Re-implement tj/co in 15 lines
function run(fn) {
var pointer = fn();
var next = function(result) {
if (result.value.then && typeof result.value.then === 'function') {
result.value.then(function(data) {
var out = pointer.next(data);
if (!out.done) next(out);
});
} else {
var out = pointer.next(result.value);
@qcam
qcam / hardcore-rpc.md
Last active August 30, 2016 00:53
[HARDCORE] RPC.md

What's RPC?

In distributed computing, a remote procedure call (RPC) is when a computer program causes a procedure (this is what it differs from REST) to execute in another address space (commonly on another computer on a shared network), which is coded as if it were a normal (local) procedure call, without the programmer explicitly coding the details for the remote interaction.

There are multiple implementation of RPC: ONC RPC, JSON-RPC, XML-RPC, gRPC, SOAP, etc.

How RPC works?

  1. The client calls the client stub. The call is a local procedure call, with parameters pushed on to the stack in the normal way.
  2. The client stub packs the parameters into a message and makes a system call to send the message. Packing the parameters is called marshalling.
@huydx
huydx / simple_regex.go
Last active August 30, 2016 01:18
simple_regex.go
package main
import (
"fmt"
)
func match(regex string, text string) bool {
if string(regex[0]) == "^" {
return matchhere(regex[1:], text)
}
@t-mat
t-mat / x11-get-clipboard-text.cpp
Created November 26, 2012 02:02
X11: クリップボードからUTF-8テキストを取得する
// g++ -std=c++0x x11clipboard.cpp -lX11
// http://tools.suckless.org/sselp
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include <string>
#include <climits>
std::string getClipboardText() {
std::string result;
Display* d = XOpenDisplay(nullptr);
;; PDF
(pdf-tools-install)
(add-to-list 'auto-mode-alist '("\\.pdf\\'" . pdf-view-mode))
(setq pdf-annot-activate-created-annotations t)
(add-hook 'pdf-view-mode-hook (lambda()
(linum-mode -1)
(pdf-view-midnight-minor-mode 1)
(evil-local-mode -1)
(setq bookmark-default-file (concat (file-name-directory (directory-file-name (file-name-directory (buffer-file-name)))) "bookmark"))
))

Looking into the Future

futures-rs is the library which will hopefully become a shared foundation for everything async in Rust. However it's already become renowned for having a steep learning curve, even for experienced Rustaceans.

I think one of the best ways to get comfortable with using a library is to look at how it works internally: often API design can seem bizarre or impenetrable and it's only when you put yourself in the shoes of the library author that you can really understand why it was designed that way.

In this post I'll try to put down on "paper" my understanding of how futures work and I'll aim to do it in a visual way. I'm going to assume you're already somewhat familiar with Rust and why futures are a useful tool to have at one's disposal.

For most of this post I'll be talking about how things work today (as of September 2017). At the end I'll touch on what's being proposed next and also make a case for some of the changes I'd like to see.

If you're interested in learning more ab

@wavded
wavded / promise.js
Last active May 6, 2021 13:25
Promise A+ Implementation
"use strict"
var Promise = function () {
this.state = 'pending'
this.thenables = []
}
Promise.prototype.resolve = function (value) {
if (this.state != 'pending') return
this.state = 'fulfilled'
@bluecube
bluecube / XClipboard.cpp
Created March 28, 2014 15:50
Clipboard under X11
#include "Agui/Clipboard/XClipboard.hpp"
#include <X11/Xatom.h>
#include <stdio.h>
#include <sys/select.h>
#include <unistd.h>
#include <assert.h>
#include <algorithm>
#include <iostream>
// Most of the code here is adapted from the example at
@robertklep
robertklep / gist:5124355
Created March 9, 2013 14:41
X11 keylogger
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <netdb.h>
#include <string.h>
#include <netinet/in.h>
#include <X11/X.h>
#include <X11/Xlib.h>
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
@friggeri
friggeri / haiku
Created October 6, 2011 07:30
random heroku-like name generator
haiku = ->
adjs = [
"autumn", "hidden", "bitter", "misty", "silent", "empty", "dry", "dark",
"summer", "icy", "delicate", "quiet", "white", "cool", "spring", "winter",
"patient", "twilight", "dawn", "crimson", "wispy", "weathered", "blue",
"billowing", "broken", "cold", "damp", "falling", "frosty", "green",
"long", "late", "lingering", "bold", "little", "morning", "muddy", "old",
"red", "rough", "still", "small", "sparkling", "throbbing", "shy",
"wandering", "withered", "wild", "black", "young", "holy", "solitary",
"fragrant", "aged", "snowy", "proud", "floral", "restless", "divine",