Skip to content

Instantly share code, notes, and snippets.

@edwardw
edwardw / PasswordManager.purs
Created Mar 8, 2020
PureScript Run is fun
View PasswordManager.purs
-- https://haskell-explained.gitlab.io/blog/posts/2019/07/28/polysemy-is-cool-part-1/
module PasswordManager where
import Prelude
import Data.Map (Map)
import Data.Map as M
import Data.Maybe (Maybe(..))
import Data.Tuple (Tuple(..))
import Node.Crypto.Hash (Algorithm(..), base64)
@edwardw
edwardw / adapter.rs
Last active Dec 29, 2019
AsyncRead adapter
View adapter.rs
//# bytes = "0.5"
//# futures = "0.3"
//# tokio = { version = "0.2", features = ["stream", "io-util"] }
//# tokio-util = { version = "0.2", features = ["codec"] }
mod adapter {
use futures::io as fio;
use std::{
pin::Pin,
task::{Context, Poll},
};
@edwardw
edwardw / Cargo.toml
Created Dec 20, 2019
Cycle a Rust iterator a given number of times
View Cargo.toml
[package]
name = "cycle_n"
version = "0.1.0"
authors = ["whoever"]
edition = "2018"
[dependencies]
[dev-dependencies]
criterion = "0.3"
@edwardw
edwardw / ClassHierarchy.java
Last active Dec 21, 2016
Determine java class hierarchies programmatically
View ClassHierarchy.java
import java.io.File;
import java.util.Set;
import javax.annotation.processing.*;
import javax.lang.model.*;
import javax.lang.model.element.*;
import javax.tools.*;
import com.sun.source.tree.*;
import com.sun.source.util.*;
@edwardw
edwardw / issue22077.patch
Last active Aug 29, 2015
A fix for #22077 on top of #22338
View issue22077.patch
diff --git a/src/librustc_typeck/check/assoc.rs b/src/librustc_typeck/check/assoc.rs
index 2f3bd5d..5a319a6 100644
--- a/src/librustc_typeck/check/assoc.rs
+++ b/src/librustc_typeck/check/assoc.rs
@@ -9,31 +9,35 @@
// except according to those terms.
use middle::infer::InferCtxt;
-use middle::traits::{self, FulfillmentContext, Normalized, MiscObligation,
- SelectionContext, ObligationCause};
@edwardw
edwardw / gist:7587876
Created Nov 21, 2013
Boot to Rust in OS X
View gist:7587876

Booting to Rust by Eric Holk! It is just mind-bogglingly cool. What else can I say? His enhancement to Rust has been landed so it is time for me to try that out, in OS X. The setup of the toolchain could be a little bit challenging.

First and foremost, check out the latest Rust with win64 calling convention contributed by Eric Holk and build it.

Then prepare the cross linker.

$ wget http://ftpmirror.gnu.org/binutils/binutils-2.23.2.tar.gz
$ tar xvzf binutils-2.23.2.tar.gz
$ cd binutils-2.23.2
$ mkdir dist
@edwardw
edwardw / rust_tasks_and_macros.md
Last active Dec 15, 2015
Go Concurrency Challenge in Rust
View rust_tasks_and_macros.md

An adaption of Leah Hanson's solution using Rust macros. The original go challenge goes here.

Compiled with Rust 0.5.

use core::task::spawn;
use core::pipes::{stream,Port,Chan,SharedChan};

macro_rules! compute_and_send(
    ($inp:expr, $port:ident) => (
@edwardw
edwardw / gist:5036535
Created Feb 26, 2013
Install octave-forge miscellaneous package in homebrew octave
View gist:5036535

There are some mysterious errors when trying to install miscellaneous package from octave-forge:

error: variable length array of non-POD element type 'Array<octave_idx_type>'

etc. This happens to homebrew-ed octave 3.6.4.

The issue seems to have something to do with clang, the default compiler homebrew uses to install octave. The solution for now is to use gcc instead:

$ export CXX=llvm-g++-4.2 
@edwardw
edwardw / gist:4138639
Created Nov 24, 2012
Install numpy/scipy on mountain lion
View gist:4138639

Scipy Superpack is kind nice, but it seems to be inactive for a while and I want every thing under my complete control. So I went on installing them myself under homebrew-ed python.

Prerequisite

$ brew install python
$ brew install gfortran swig

Scipy/Numpy

@edwardw
edwardw / gist:3780436
Created Sep 25, 2012
Double negation in gitignore
View gist:3780436

Usually .gitignore is used to exempt certain files and directories from being reported by git status. The name .gitignore itself also suggests such usage. But when one does some experiments in sandbox directory, only a small portion of files are worth being version controlled. Instead of telling git what to exclude, it is more convenient to tell it what to include. Spotted such a .gitignore pattern today and it goes like this:

# Ignore all
*

# Except
.gitignore

# Include js directory