Skip to content

Instantly share code, notes, and snippets.

@jrraymond
jrraymond / main.rs
Created August 18, 2018 13:36
tarpc closure in server
/*
nightly-x86_64-unknown-linux-gnu
[dependencies]
serde = "^1.0"
tarpc = "0.12.0"
tarpc-plugins = "0.4.0"
*/
#![feature(plugin, use_extern_macros, proc_macro_path_invoc)]
#![plugin(tarpc_plugins)]
@jrraymond
jrraymond / lis.py
Created April 18, 2017 02:35
lisp parser
def lex(inp):
tkns = list()
acc = list()
for ch in inp:
if ch.isspace() and acc:
tkns.append(''.join(acc))
acc = list()
elif ch == '(' or ch == ')':
if acc:
@jrraymond
jrraymond / secret_santa.cpp
Created December 5, 2016 23:40
guessing who picked you in secret santa
#include <algorithm>
#include <iostream>
#include <vector>
std::vector<int> create_graph(int sz)
{
std::vector<int> graph;
graph.reserve(sz);
for (int i=0; i<sz; ++i)
4 workers, 15 cores each, another shell with 40 cores running at the same time.
2tags, 100k securities, 2.5k pvs
I: input - the size of data input to all the tasks
O: ouput - the size of data output from all tasks
SR: shuffle read - the size of data read from other partitions
SW: shuffle write - the size of data written to other partitions
baseline: read from data table and write back to another table
shuffle.partitions=200
collect: 5s, 2 stages, 220 tasks
runJob: 8s, 6 stages, 660 tasks
shuffle.partitions=60
collect: 5s, 2stages, 80 tasks
runJob: 8s, 6 stages, 240 tasks
collect:
stage 1 remains the same, 5s, 20 tasks, 1909.2MB input, 48.1MB shuffle write
@jrraymond
jrraymond / quickSelects.scala
Created October 22, 2016 19:41
quickSelect
import org.scalacheck.Properties
import org.scalacheck.Prop.{forAll, BooleanOperators}
import scala.util.Random
def quickSelect[A <% Ordered[A]](seq: Seq[A], n: Int, rand: Random = new Random): A = {
val pivot = rand.nextInt(seq.length);
val (left, right) = seq.partition(_ < seq(pivot))
if (left.length == n) {
seq(pivot)
} else if (left.length < n) {
total time = 132.70 secs (132702 ticks @ 1000 us, 1 processor)
run.img Main 427 1 0.0 0.0 98.2 97.6
render RayTracer 428 1 0.0 0.0 98.2 97.6
render.cs RayTracer 585 1 98.1 97.6 98.2 97.6
compare RayTracer 639 3971855 0.0 0.0 0.0 0.0
== Geometry3 638 1676386 0.0 0.0 0.0 0.0
wLights RayTracer 637 1871708 0.0 0.0 0.0 0.0
wAmbient RayTracer 636 1871708 0.0 0.0 0.0 0.0
wImgHt RayTracer 633 3840000 0.0 0.0 0.0 0.0
@jrraymond
jrraymond / colorPixel1.hs
Last active August 29, 2015 14:26
vectors_conundrum
type Point = (Float,Float)
type GridU = U.Vector Point
{- Explanation: colorPixel evaluates to the color of a pixel for a given world
- Antialiasing is tracing > 1 rays through each pixel and averaging the results.
- Soft shadows are shadows that do not have a hard edge, this requires sending multiple shadow rays to each light.
- Depth of field: only objects at a certain distance are in focus. To do this we send multiple rays though each antialising
- point with each base perturbed slightly. Objects are in focus if they are at the distance the view plane is at.
-
- Three arguments:
{-# LANGUAGE FlexibleContexts #-}
{- Construct recursive descent parsers for the following grammars -}
import Text.Parsec
(<||>) :: ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
p <||> q = try p <|> q
{- S -> + S S | - S S | a -}
data G1 = P1G1 G1 G1 | P2G1 G1 G1 | T1G1 deriving (Eq, Show)
g1 :: Stream s m Char => ParsecT s u m G1
@jrraymond
jrraymond / wescraper.py
Last active August 29, 2015 14:02
wescraper
import time, string
from scrapy.spider import BaseSpider
from scrapy.http import FormRequest
from scrapy.item import Item, Field
from scrapy.selector import HtmlXPathSelector
from selenium import webdriver
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.common.exceptions import NoSuchElementException