Skip to content

Instantly share code, notes, and snippets.

Nelson Elhage nelhage

Block or report user

Report or block nelhage

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@nelhage
nelhage / main.go.c
Last active Sep 5, 2019
A Go/C polyglot
View main.go.c
// \
/*
#include <stdio.h>
int main() {
printf("Hello, World from C!\n");
return 0;
}
#if 0
//*/
View gist:44da26d0b93a038cdc0a577783a52e1e
https://www.dropbox.com
https://drive.google.com
https://aws.amazon.com
https://cloud.google.com
https://hangouts.google.com/
https://www.salesforce.com
https://www.bitfinex.com
https://www.coinbase.com/
https://gemini.com/
https://bitbucket.org
View float.cc
#include <stdio.h>
#include <math.h>
#include <stdint.h>
static float rt(float x) {
volatile double g = static_cast<double>(x);
return static_cast<float>(g);
}
int main() {
View optional.cc
#include <thread>
#include <experimental/optional>
#include <atomic>
#include <shared_mutex>
#include <mutex>
#include <iostream>
#include <vector>
using namespace std;
@nelhage
nelhage / README.md
Created Apr 26, 2018
Experience report: Trying to map an `FnMut` over a binary tree in Rust
View README.md

This story is simplified from an attempt to write an AST walker for a toy compiler, but the essential facts are unchanged.

I am fairly new to Rust (but an experienced C++ programmer) and am trying to write a program to map an FnMut over a binary tree. I start with a simple tree definition, and try to write what seems to me to be the straightforward code:

use std::rc::Rc;
@nelhage
nelhage / cxx-move-semantics.cc
Created Nov 27, 2017
Which of these compile?
View cxx-move-semantics.cc
#include <memory>
using namespace std;
void accept_val(unique_ptr<int> i);
void accept_ref(unique_ptr<int> &i);
void accept_cref(const unique_ptr<int> &i);
void accept_rref(unique_ptr<int> &&i);
int main(int argc, char **argv) {
@nelhage
nelhage / acha_senate.txt
Created Jun 12, 2017
AHCA Senate Call Script
View acha_senate.txt
My name is Nelson Elhage. I'm a constituent of the Senator's in zip
code 94102.
I’m calling to express deep concern that Senate Republicans are
threatening to call for a vote on the ACA repeal without any public
hearings, and are keeping the text of the bill hidden from the public.
I urge the Senator to use every procedural tool at her disposal to
stop business as usual in the Senate and prevent this bill from
passing. I urge her to withhold consent when the bill comes to the
View gist:13d160fa4d956d989862ed9c28735ddb
$ ruby -e 'puts ("".split(" ")).inspect'
[]
$ perl -MData::Dumper -E 'say Dumper([split(" ", "")])'
$VAR1 = [];
$ python -c 'print "".split(" ")'
['']
# https://play.golang.org/p/qErK71KCsF
View gist:b469808c2ea040cf24a29c711e97fd1c
BootCurrent: 0001
Timeout: 2 seconds
BootOrder: 0001,0017,0000,0018,0019,001A,001B,001C,0021
Boot0000* Windows Boot Manager HD(1,GPT,d72d73a1-3247-41ca-af0b-cd5af1642048,0x800,0x100000)/File(\EFI\Microsoft\Boot\bootmgfw.efi)WINDOWS.........x...B.C.D.O.B.J.E.C.T.=.{.9.d.e.a.8.6.2.c.-.5.c.d.d.-.4.e.7.0.-.a.c.c.1.-.f.3.2.b.3.4.4.d.4.7.9.5.}....................
Boot0001* ubuntu HD(1,GPT,d72d73a1-3247-41ca-af0b-cd5af1642048,0x800,0x100000)/File(\EFI\ubuntu\grubx64.efi)
Boot0010 Setup FvFile(721c8b66-426c-4e86-8e99-3457c46ab0b9)
Boot0011 Boot Menu FvFile(126a762d-5758-4fca-8531-201a7f57f850)
Boot0012 Diagnostic Splash Screen FvFile(a7d8d9a6-6ab0-4aeb-ad9d-163e59a7a380)
Boot0013 Lenovo Diagnostics FvFile(3f7e615b-0d45-4f80-88dc-26b234958560)
Boot0014 Startup Interrupt Menu FvFile(f46ee6f4-4785-43a3-923d-7f786c3c8479)
View rusthash_time_prealloc.rs
use std::collections::hash_set::HashSet;
use std::vec::Vec;
use std::time::{Instant,Duration};
use std::env;
const SAMPLE_INTERVAL : usize = 1000;
fn duration_ns(d : Duration) -> i64 {
return (d.as_secs() as i64) * 1000000000 + (d.subsec_nanos() as i64);
}
You can’t perform that action at this time.