Skip to content

Instantly share code, notes, and snippets.

@nixpulvis
nixpulvis / contract.rkt
Last active August 29, 2015 14:18
Simplest Contract System
#lang racket
;; A Contract is one of:
;; - Any -> Boolean
;; - Signature
;; A Signature is a (signature Contract Contract)
(struct signature (domain range))
@nixpulvis
nixpulvis / contract.rb
Created April 4, 2015 04:53
Simplest Contract System in Ruby
# A Contract is one of:
# - Proc (Any -> Boolean)
# - Hash { Contract => Contract }
def assert_predicate(predicate, value)
if predicate.(value)
value
else
fail "contract error"
end
@nixpulvis
nixpulvis / clone.rb
Created June 13, 2015 23:47
Clone/Pull All Repositories From GitHub
#!/usr/bin/env ruby
require 'pry'
require 'json'
json = JSON.parse(`curl https://api.github.com/users/nixpulvis/repos?per_page=100`)
json.each do |repo|
if File.exists?(repo['name'])
Dir.chdir(repo['name'])
print "Pulling #{repo['name']}... "
.text
.global _start
_start:
movl $foo,%edx
movl $string,%ecx
movl $1,%ebx
movl $4,%eax
int $0x80
movl $0,%ebx
@nixpulvis
nixpulvis / try_or.rs
Last active September 17, 2015 04:52
Try or Rust macro, for more generally treating Results as values.
macro_rules! try_or {
($expr:expr => $handler:expr) => (match $expr {
::std::result::Result::Ok(v) => v,
::std::result::Result::Err(e) => {
warn!("{}", e);
$handler
}
})
}
@nixpulvis
nixpulvis / quest1.java
Created January 30, 2012 23:40
infinate set (countability of rational numbers)
abstract class ATree {
Rational value;
ATree(Rational value){
this.value = value;
}
abstract Node expandOneLevel();
// returns the integer value of the node/leaf
public Double doubleValue(){
return this.value.toDouble();
@nixpulvis
nixpulvis / gist:1926289
Created February 27, 2012 19:03
Simple Ciclic Data
import tester.Tester;
class Star {
String name;
Movie movie;
Star(String name){
this.name = name;
}
Star(String name, Movie movie){
this.name = name;
@nixpulvis
nixpulvis / Hex -> Color
Created May 17, 2012 17:47
This if a function to convert hex strings into r, g, b color. This function returns multiple variables.
-- converts hex colors to 0-1 colors for use in World of Warcraft.
function V.HexToColor(hex)
local color = { }
if strlen(hex) == 6 or strlength(hex) == 8 then
for i = 1, 8, 2 do
if strsub(hex, i, i+1) == "" then print(strsub(hex, i, i+1)) break end
-- converting string to number 0-1
tinsert(color, tonumber(strsub(hex, i, i+1), 16)/255)
end
else
@nixpulvis
nixpulvis / gist:2779607
Created May 24, 2012 05:17
repositioning from child
mover:SetScript("OnDragStart", function()
local lastX, lastY = GetCursorPosition()
mover:SetScript("OnUpdate", function()
local x, y = GetCursorPosition()
xOff, yOff = x-lastX, y-lastY
lastX, lastY = x, y
for i = 1, frame:GetNumPoints() do
local point, relativeTo, relativePoint, xOffset, yOffset = frame:GetPoint(i)
@nixpulvis
nixpulvis / gist:2890564
Created June 7, 2012 18:20
Dynamic content require (for interpreted languages)
# returns an array of files that are required by the given file
def get_requirements( file )
requirements = Array.new
File.readlines("#{file}.rb").each do |line|
regex = /(?<=require.')(.*)(?=';)/ # matches the requirements in a file
requirement = line.match(regex)
if requirement
requirements << requirement.to_s
end
end