This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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[ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| extern crate rand; | |
| use std::collections::HashMap; | |
| use std::io::{self, Read}; | |
| struct Markov { | |
| rng: rand::ThreadRng, | |
| seed: String, | |
| freqs: HashMap<String, Vec<String>>, | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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>>); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ❯ 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| extern crate rand; | |
| #[derive(Clone, Copy, Debug, Eq, PartialEq)] | |
| enum Nationality { | |
| Dane, | |
| Brit, | |
| Swede, | |
| Norwegian, | |
| German, | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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}` |