Skip to content

Instantly share code, notes, and snippets.

View saethlin's full-sized avatar
🦀

Ben Kimock saethlin

🦀
View GitHub Profile
@saethlin
saethlin / clippy_noooo.rs
Created May 25, 2017 02:12
clippy is kill
╰ ➤ cargo clippy
/home/ben/.cargo/bin/cargo-clippy: symbol lookup error: /home/ben/.cargo/bin/cargo-clippy: undefined symbol: _ZN5rustc4util5ppaux89_$LT$impl$u20$core..fmt..Display$u20$for$u20$rustc..ty..sty..TraitRef$LT$$u27$tcx$GT$$GT$3fmt17h0ad16e3ee81d6918E
╰ ➤ cargo install clippy --force
Updating registry `https://github.com/rust-lang/crates.io-index`
Installing clippy v0.0.134
Compiling dtoa v0.4.1
Compiling lazy_static v0.2.8
Compiling unicode-xid v0.0.4
Compiling itoa v0.3.1
@saethlin
saethlin / error.rs
Created May 25, 2017 18:17
rustc pls
error[E0277]: the trait bound `std::ffi::OsString: std::borrow::Borrow<str>` is not satisfied
--> src/echo.rs:12:52
|
12 | if let Some(val) = state.variables.get(key) {
| ^^^ the trait `std::borrow::Borrow<str>` is not implemented for `std::ffi::OsString`
|
= help: the following implementations were found:
<std::ffi::OsString as std::borrow::Borrow<std::ffi::OsStr>>
@saethlin
saethlin / window.rs
Last active July 11, 2017 04:11
rust xcb Window
pub struct Window {
connection: xcb::base::Connection,
window: xcb::xproto::Window,
foreground: xcb::Drawable,
pub width: u16,
pub height: u16,
}
impl Window {
pub fn new(width: u16, height: u16) -> Self {
@saethlin
saethlin / main.rs
Created July 22, 2017 18:53
Rust-XCB demo
extern crate xcb; // Make sure you add xcb to your Caro.toml dependencies
fn main() {
// First thing you have to do is get a connection. You can pass an argument
// but if you just leave it as None you'll connect to the display device you're currently on
let (connection, screen_num) = xcb::Connection::connect(None).unwrap();
let setup = connection.get_setup();
let screen = setup.roots().nth(screen_num as usize).unwrap();
@saethlin
saethlin / gist:d6e6d4a202d7d74d16029e00b0594a8b
Created August 6, 2017 22:11
Python stdlib import-all timer (Windows)
Measure-Command {python -c "import string, re, difflib, textwrap, unicodedata, stringprep, rlcompleter, struct, codecs, datetime, calendar, collections, collections.abc, heapq, bisect, array, weakref, types, copy, pprint, reprlib, enum, numbers, math, cmath, decimal, fractions, random, statistics, itertools, functools, operator, pathlib, os.path, fileinput, stat, filecmp, tempfile, glob, fnmatch, linecache, shutil, macpath, pickle, copyreg, shelve, marshal, dbm, sqlite3, zlib, gzip, bz2, zipfile, tarfile, csv, configparser, netrc, xdrlib, plistlib, hashlib, hmac, secrets, os, io, time, argparse, getopt, logging, logging.config, logging.handlers, getpass, platform, errno, ctypes, threading, multiprocessing, concurrent, concurrent.futures, sched, queue, dummy_threading, _thread, _dummy_thread, socket, ssl, select, selectors, asyncio, asyncore, asynchat, signal, mmap, email, json, mailcap, mailbox, mimetypes, base64, binhex, binascii, quopri, uu, html, html.parser, html.entities, xml, xml.etree.ElementTree, xml.
function datatype,var, flag0, descriptor=desc, help=hlp, Tname = tname
;+
; NAME:
; DATATYPE()
;
; PURPOSE:
; Returns the data type of a variable.
;
; EXPLANATION:
; This routine returns the data type of a variable in a format specified
error[E0277]: the trait bound `({float}, ndarray::ArrayBase<ndarray::OwnedRepr<_>, ndarray::Dim<[usize; 1]>>): std::ops::Fn<()>` is not satisfied
--> src/star.rs:76:73
|
76 | let (flux_quiet, integrated_ccf) = limb_integrals.zip(profiles).fold(
| ^^^^ the trait `std::ops::Fn<()>` is not implemented for `({float}, ndarray::ArrayBase<ndarray::OwnedRepr<_>, ndarray::Dim<[usize; 1]>>)`
error[E0277]: the trait bound `({float}, ndarray::ArrayBase<ndarray::OwnedRepr<_>, ndarray::Dim<[usize; 1]>>): std::ops::FnOnce<()>` is not satisfied
--> src/star.rs:76:73
|
76 | let (flux_quiet, integrated_ccf) = limb_integrals.zip(profiles).fold(
@saethlin
saethlin / Cargo.toml
Created September 6, 2017 23:31
Demonstration of thread-safety enforced by Rust's type system
[package]
name = "typedemo"
version = "0.1.0"
authors = ["saethlin <[email protected]>"]
[dependencies.cpython]
version = "0.1"
features = ["extension-module"]
[lib]
@saethlin
saethlin / constant_fold.rs
Last active September 15, 2017 17:45
Matching on box attempt
enum ExprNode {
Number(f64),
Variable(CString),
BinaryOperation(char, Box<ExprNode>, Box<ExprNode>),
FunctionCall(CString, Vec<Box<ExprNode>>),
IfElse(Box<ExprNode>, Box<ExprNode>, Box<ExprNode>),
ForLoop(Box<ExprNode>, Box<ExprNode>, Option<Box<ExprNode>>, Box<ExprNode>),
}
if let (ExprNode::Number(l), ExprNode::Number(r)) = (*lhs, *rhs) {
@saethlin
saethlin / parens.rs
Last active September 16, 2017 03:47
Valid Parentheses
pub struct Solution {}
impl Solution {
pub fn is_valid(s: &str) -> bool {
let mut num_open_seen = 0;
for (i, c) in s.chars().enumerate() {
let maybe_last_open = s.split_at(i)
.0
.chars()
.rev()