I hereby claim:
- I am jsanders on github.
- I am jsanders (https://keybase.io/jsanders) on keybase.
- I have a public key whose fingerprint is A954 10AF 97B2 2125 1A92 9C8E CFAA B7C4 D2CF 612A
To claim this, I am signing this object:
| class IO[A] private (run0: => A) { | |
| def run = run0 | |
| def flatMap[B](f: A => IO[B]): IO[B] = { | |
| IO(f(run).run) | |
| } | |
| def map[B](f: A => B): IO[B] = flatMap(a => IO(f(a))) | |
| } |
I hereby claim:
To claim this, I am signing this object:
| extern crate bignum; | |
| extern crate time; | |
| use std::rand::task_rng; | |
| use std::iter::{count,range_step_inclusive}; | |
| use std::num::{Zero,One}; | |
| use bignum::{BigUint,RandBigInt,ToBigUint}; | |
| // Find all prime numbers less than n | |
| fn small_primes(bound: uint) -> ~[uint] { |
| // Modular exponentiation by squaring | |
| fn mod_exp(base: &BigUint, exponent: &BigUint, modulus: &BigUint) -> BigUint { | |
| let (zero, one): (BigUint, BigUint) = (Zero::zero(), One::one()); | |
| let mut result = one.clone(); | |
| let mut baseAcc = base.clone(); | |
| let mut exponentAcc = exponent.clone(); | |
| while exponentAcc > zero { | |
| // Accumulate current base if current exponent bit is 1 | |
| if (exponent & one) == one { |
| // Find all prime numbers less than n | |
| fn small_primes(bound: uint) -> ~[uint] { | |
| // num is considered prime as long as primes[num] is true | |
| // Start with all evens besides 2 filtered out | |
| let mut primes = std::vec::from_fn(bound+1, |num| num == 2 || num & 1 != 0); | |
| // Start at 3 and step by 2 because we've already filtered multiples of 2 | |
| for num in count(3u, 2).filter(|&num| primes[num]).take_while(|&num| num * num <= bound) { | |
| // Mark prime num's multiples non-prime | |
| // We can start at num^2 because smaller non-primes have already been eliminated |
| if Rails.env.development? | |
| require 'active_record/connection_adapters/postgresql_adapter' | |
| class ActiveRecord::ConnectionAdapters::PostgreSQLAdapter | |
| def __explain_analyze(sql, command, *args) | |
| meth = "#{command}_without_explain_analyze".to_sym | |
| if /\A\s*SELECT/i.match(sql) | |
| newsql = "EXPLAIN ANALYZE #{sql}" | |
| plan = send(meth, newsql, *args).map { |row| row['QUERY PLAN'] }.join("\n") | |
| Rails.logger.debug("\e[1m\e[31mQUERY PLAN FOR: #{sql.strip};\n#{plan}\e[0m") |
| // Compile with `g++ -framework GLUT glut_hello_world.cpp` | |
| #include <GLUT/glut.h> | |
| void display(void) { } | |
| int main(int argc, char** argv) { | |
| glutInit(&argc, argv); | |
| glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); |
| fn flip<T>(f: ~fn(a: T, b: T)) -> ~fn(a: T, b: T) { | |
| |a, b| { f(b, a) } | |
| } | |
| fn hello_world(hello: &str, world: &str) { | |
| println!("{:s}, {:s}!", hello, world) | |
| } | |
| #[test] | |
| fn test_flip() { |
| use std::rt::io::{Reader, Writer}; | |
| use std::rt::io::net::ip::{Ipv4Addr,SocketAddr}; | |
| use std::rt::io::net::tcp::TcpStream; | |
| use std::str; | |
| trait ToUintSafe { | |
| fn to_uint_safe(&self) -> Option<uint>; | |
| } | |
| impl ToUintSafe for int { |
| # Extended Euclidean GCD algorithm | |
| # Outputs k, u, and v such that ua + vb = k where k is the gcd of a and b | |
| def egcd(a, b) | |
| u_a, v_a, u_b, v_b = [ 1, 0, 0, 1 ] | |
| while a != 0 | |
| q = b / a | |
| a, b = [ b - q*a, a ] | |
| u_a, v_a, u_b, v_b = [ u_b - q*u_a, v_b - q*v_a, u_a, v_a ] | |
| # Each time, `u_a*a' + v_a*b' = a` and `u_b*a' + v_b*b' = b` | |
| end |