Skip to content

Instantly share code, notes, and snippets.

@rylev
rylev / crates.rb
Created March 1, 2019 15:22
Script for downloading the most popular crates and finding how many times they use the unsafe keyword.
require "open-uri"
require "json"
PAGE_SIZE=100
NUM_PAGES=2
crates = []
(1..NUM_PAGES).each do |page|
res = JSON.parse(URI.parse("https://crates.io/api/v1/crates?page=#{page}&per_page=#{PAGE_SIZE}").read)
puts res
crates += res["crates"].map {|c| {name: c["name"], repo: c["repository"]} }
@rylev
rylev / rainbow.a
Created March 21, 2017 09:47
Rainbows on Atari 2600
PROCESSOR 6502; set processor
INCLUDE "vcs.h" ; include helpful stuff
INCLUDE "macro.h" ; include helpful stuff
Seg Code ; set code segment
ORG $F000 ; code should start at 0xF000
BGColor equ $81 ; Reserve space at 0x81
Start
@rylev
rylev / example.ts
Last active March 17, 2017 13:15
TypeScript
function divide(num1: number | undefined, num2: number | undefined): number | 'no!' | undefined {
if (num1 === undefined || num2 === undefined) { return }
// num1 and num2 now have type number
if (num2 === 0) { return 'no!'}
return num1 / num2
}
@rylev
rylev / gist:7725524
Created November 30, 2013 22:40
Binary Addition with logic gates
class Array
def second
self[1]
end
end
class Integer
def one?
raise "Not Binary" unless self == 1 || self == 0
self == 1
end
@rylev
rylev / plan.md
Last active December 25, 2015 17:39
Plan proposal for the next Elixir Users Group.

Intro to FP and Elixir

##Targeted Audience

The targeted audience are both beginners to functional programming who have experience in programming with at least one imperative style language. The content may also be appealing to those who have programmed in other functional programming languages (e.g. Haskell, Clojure, F#, etc.) or even Erlang programmers, but the content will not be specifically geared towards them.

@rylev
rylev / gist:6685033
Created September 24, 2013 13:49
Enforcing arity like a boss
def foo(args)
raise ArgumentError unless args.count == 2 && args.keys.include? :bar
# your code goes here
end
@rylev
rylev / dot_strings_parser.rb
Created November 12, 2012 18:09
A simple ruby class that parses .strings files (used in OSX and iOS for translations) and coverts it to a Ruby hash.
class DotStringsParser
REGEX_QUOTED = /\"((\\\"|[^\"])+)\"/
REGEX_KEY_VALUE = /#{REGEX_QUOTED}\s*=\s*#{REGEX_QUOTED}/
def initialize
@hash = {}
end
def convert_to_array(line)
@rylev
rylev / example.rs
Created November 27, 2014 00:15
Compiler Bug Error
use std::io::File; use std::io::FileMode::Open;
use std::io::FileAccess::{Write,ReadWrite};
use std::io::IoResult;
use std::fmt::{Show,Formatter,Error};
const MAX_DATA: uint = 512;
const MAX_ROWS: uint = 100;
struct Field {
@rylev
rylev / monadfun.scala
Last active August 29, 2015 14:07
An explanation of the map function in Scala.
/* Map */
class Future[A] {
map[B](someMapFunction: A => B): Future[B]
}
// Mapping lets you convert any Future of some type A to a Future of some type B
// For instance you can go from Future[String] to Future[Int]
val myFutureString : Future[String] = Future("some String")
=erl_crash_dump:0.2
Fri Sep 26 14:40:25 2014
Slogan: init terminating in do_boot ()
System version: Erlang R16B01 (erts-5.10.2) [source] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]
Compiled: Tue Sep 3 19:23:51 2013
Taints:
Atoms: 4761
=memory
total: 10782344
processes: 3969496