Skip to content

Instantly share code, notes, and snippets.

#lang typed/racket
(define num-update
(lambda (#:main [main : Number 0] #:reserve [reserve : Number 1])
(list main reserve)))
(print (num-update))
(print (num-update #:main 2))
(print (num-update #:reserve 2))
@kejadlen
kejadlen / foo.rs
Created August 29, 2017 02:07
Custom deserialization of JSON w/Serde
fn deserialize_images<'de, D>(de: D) -> Result<Vec<Image>, D::Error>
where D: serde::Deserializer<'de>
{
let value: serde_json::Value = serde::Deserialize::deserialize(de)?;
let object = value
.as_object()
.ok_or(serde::de::Error::custom("expected an object of images"))?;
let images = object
.iter()
.flat_map(|(k, v)| match (k.as_ref(), v) {
import Data.List
pairs xs = zip xs (tail xs)
repeatingPairs xs = filter (\(x,y) -> x == y) $ pairs xs
hasRepeatingPairs :: String -> Bool
hasRepeatingPairs xs = any (\pair -> length (elemIndices pair rps) >= 2) rps
where rps = repeatingPairs xs
class Turing
def initialize(file, tape=nil)
@tape = Hash.new('_')
@head = 0
# initialize tape
tape.split(//).each_with_index {|c,i| @tape[i] = c } if tape
# read program instructions
@program = Hash[
extern crate rand;
use std::collections::HashMap;
use std::io::{self, Read};
struct Markov {
rng: rand::ThreadRng,
seed: String,
freqs: HashMap<String, Vec<String>>,
}
// You come upon a column of four floors that have been entirely sealed off from the rest of the
// building except for a small dedicated lobby. There are some radiation warnings and a big sign
// which reads "Radioisotope Testing Facility".
struct Facility<'a> {
floors: Vec<Floor<'a>>,
}
struct Floor<'a>(Vec<Item<'a>>);
❯ cargo test
Compiling git2 v0.6.0 (file:///.../git2-rs)
error: borrowed value does not live long enough
--> src/config.rs:560:23
|
560 | for entry in &cfg.entries(None).unwrap() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ temporary value created here
...
564 | }
| - temporary value only lives until here
extern crate rand;
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
enum Nationality {
Dane,
Brit,
Swede,
Norwegian,
German,
}
use std::env::args;
use std::fs::{read_dir, File};
use std::io::prelude::*;
use std::path::PathBuf;
fn main() {
let dirs = args().skip(1);
let paths = dirs.flat_map(|dir| {
read_dir(&dir)
.expect(&format!("unable to read dir {}", dir))
@kejadlen
kejadlen / main.rb
Last active July 19, 2016 15:42
Cleaning Alfred workflows
#!/usr/bin/env ruby
require 'tempfile'
plist = ARGF.read
Tempfile.create('info.plist') do |f|
f << plist
f.flush
vars = `/usr/libexec/PlistBuddy -c "Print :variablesdontexport" #{f.path}`