Skip to content

Instantly share code, notes, and snippets.

@caindy
caindy / parallel_download.rb
Created April 17, 2012 20:09
quick hack to download some course materials
require 'hpricot'
require 'open-uri'
require 'parallel'
overall_start_time = Time.now
uri = "http://www.stanford.edu/class/cs193p/cgi-bin/drupal/downloads-2010-fall"
puts "Downloading #{uri}"
doc = Hpricot(open(uri))
pdfs = doc/"//a[@href*=pdf]"
@caindy
caindy / BSIView.h
Last active December 30, 2015 12:59
Found this solution on stackoverflow
#import <UIKit/UIKit.h>
@interface BSIView : UIView
@end
@caindy
caindy / uuid.ex
Last active August 29, 2015 13:56
Elixir module to create unique identifiers of specified length, with serialization to and from strings. Put here to solicit feedback on coding style/correctness, as I am new to Elixir.
defmodule Hello.Util.UUID do
def new(byte_count // 16) do
dividend = div(byte_count, 16)
remainder = rem(byte_count, 16)
cnt = case remainder do
r when r === 0 -> dividend
_ -> dividend + remainder
end
make cnt, byte_count, <<>>

For example, one of the many current day standards that was dismissed immediately is the WWW (one could hardly imagine more of a mess).

But the functionality plus more can be replaced in our "ideal world" with encapsulated confined migratory VMs ("Internet objects") as a kind of next version of Gerry Popek's LOCUS.

The browser and other storage confusions are all replaced by the simple idea of separating out the safe objects from the various modes one uses to send and receive them. This covers files, email, web browsing, search engines, etc. What is left in this model is just a UI that can integrate the visual etc., outputs from the various encapsulated VMs, and send them events to react to. (The original browser folks missed that a scalable browser is more like a kernel OS than an App)

These are old ideas, but the vendors etc didn't get it ...

@caindy
caindy / FizzBuzz.fsx
Created June 2, 2014 08:57
F# FizzBuzz
let (|Fizz|_|) i =
if i % 3 = 0 then Some i
else None
let (|Buzz|_|) i =
if i % 5 = 0 then Some i
else None
let (|``Fizz Buzz``|_|) i =
match i with
@caindy
caindy / build.sh
Created July 15, 2014 19:01
Attempting to define symbol MONO using FAKE fsiargs in bash
#!/bin/bash
if [ ! -e packages/FAKE/tools/FAKE.exe ]; then
mono .nuget/NuGet.exe install FAKE -OutputDirectory packages -ExcludeVersion
fi
if [ ! -e packages/SourceLink.Fake/Tools/Fake.fsx ]; then
mono .nuget/NuGet.exe install SourceLink.Fake -OutputDirectory packages -ExcludeVersion
fi
if [ ! -e build.fsx ]; then
@caindy
caindy / actpat.fsx
Created August 3, 2014 18:40
highlighting the expressiveness of total single-case active pattern
open System.Numerics
let (|Rect|) (x: Complex) = (x.Real, x.Imaginary)
let (|Polar|) (x: Complex) = (x.Magnitude, x.Phase)
//conversion functions easily expressed in terms of active patterns
let toRect = function | Rect(r, i) -> (r, i)
let toPolar = function | Polar(m, p) -> (m, p)
//following two functions are equivalent, but the former reads better IMO
@caindy
caindy / bootstrapCanopyOSX.sh
Created September 8, 2014 13:12
bash script to bootstrap canopy on OSX
#! /bin/bash
if hash brew 2>/dev/null; then
echo "Found Homebrew"
else
echo >&2 "Please install Homebrew"
exit 1
fi
if hash fsharpi 2>/dev/null; then
@caindy
caindy / getOperator.fs
Last active August 29, 2015 14:11
The lines that use the (?) operator are compiler errors. I suspect this fails for the same reason that you cannot add operators in type extensions. I just don't know what that reason is...
[<AutoOpen>]
module Auto =
type Result<'s, 'f> =
| Success of 's
| Failure of 'f
open System
open System.Runtime.CompilerServices
open System.Collections.Generic
open Newtonsoft.Json.Linq