Skip to content

Instantly share code, notes, and snippets.

@kestein
kestein / main.rs
Created March 9, 2016 21:02
Rust conditional compile blocks
#![feature(stmt_expr_attributes)] // Need this in order to put the #[cfg] around a block
fn main() {
#[cfg(not(windows))] // Applies to the entire block OR the line directly after it
{
println!("HAHA, WINDOWS NERD");
println!("Richard Stallman > Bill Gates");
}
println!("All done.");
}
@kestein
kestein / runtime-static.rs
Created August 16, 2016 15:13
Lel, make things static at runtime
let x = vec![String::from("asdf1234"), String::from("fdsa4312")];
let mut y: Vec<&'static str> = Vec::new();
for e in x {
unsafe {
let r = mem::transmute(&e as &str);
mem::forget(e);
y.push(r);
}
}
@kestein
kestein / Private_Crates.md
Last active September 7, 2024 17:59
Linking to a private repo in Cargo.toml

Under the dependencies section, put

<crate name>={git="ssh://[email protected]/<organization>/<reponame>.git"}

It is pretty similar to a github repo's ssh cloning link, however the : is replaced with a / and ssh:// is prepended to the URL.

[email protected]:my-organization/my-repo.git vs ssh://[email protected]/my-organization/my-repo.git

The SSH URL needs to be used because Cargo is currently unable to handle the authentication prompt that comes up when an HTTPS link is used.
Make sure that the matches the crate name in the target repo's Cargo.toml. The repo name will not override what is in the Cargo.toml if it is a different value.

@kestein
kestein / 4chan.go
Created April 22, 2018 14:32
Launch a thread with the specified subject on any 4chan board
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
"os/exec"
@kestein
kestein / json_bootstrap.py
Created May 4, 2018 14:12
The basics for reading in a json file since I use it a lot
import sys
import json
with open(sys.argv[1], "rb") as f:
for line in f:
j = json.loads(line.strip())