Skip to content

Instantly share code, notes, and snippets.

Avatar

Simon Kornblith simonster

View GitHub Profile
View gist:5643f2935576498078dae166e4373c29
.-"-._( ) )
/ , , 66\
`======\ )_\\=\_o)=
`~~"~ `"
View inverse_hash.jl
using Compat
# Original C version at https://naml.us/post/inverse-of-a-hash-function/
function inverse_hash(key::UInt64)
local tmp::UInt64
# Invert key = key + (key << 31)
tmp = key-(key<<31)
key = key-(tmp<<31)
View gist:e22e50cd52b7dffcf5a4db2b8ea4cce0

To the members of the MIT community:

We are writing to inform you of plans to upgrade the MIT campus network, and in particular to upgrade MIT to the next generation of Internet addressing. (Please note that no action is required on your part.)

Machines on the Internet are identified by addresses. The current addressing scheme, called IPv4, was specified around 1980, and allowed for about 4 billion addresses. That seemed enough at the time, which was before local area networks, personal computers and the like, but the Internet research community recognized around 1990 that this supply of addresses was inadequate, and put in place a plan to replace the IPv4 addresses with a new address format, called IPv6. IPv6 uses a 128-bit address scheme and is capable of 340 undecillion addresses (340 times 10^36, or 340 trillion trillion trillion possible IP addresses). This stock of addresses allows great flexibility in how addresses are assigned to hosts, for example allowing every host to use a range of addresses to

View gist:f2cc51584ae5f8709e70
if (platform == "win") {
libc = ctypes.open("Ws2_32.dll");
var dnsapi = ctypes.open("Dnsapi.dll");
var DNS_RECORD = new ctypes.StructType("DNS_RECORD");
DNS_RECORD.define([{"pNext":DNS_RECORD.ptr}, {"pName":ctypes.char.ptr}, {"wType":ctypes.unsigned_short},
{"wDataLength":ctypes.unsigned_short}, {"DW":ctypes.unsigned_long}, {"dwTtl":ctypes.unsigned_long},
{"dwReserved":ctypes.unsigned_long}, {"pNameHost":ctypes.char.ptr}]);
var DnsQuery = dnsapi.declare("DnsQuery_A", ctypes.winapi_abi, ctypes.int, ctypes.char.ptr, ctypes.unsigned_short,
ctypes.unsigned_long, ctypes.voidptr_t, DNS_RECORD.ptr, ctypes.voidptr_t);
@simonster
simonster / gist:b1b4cc2ad0daa8e20a99
Last active Aug 29, 2015
missingness sum benchmark
View gist:b1b4cc2ad0daa8e20a99
immutable CheapMulBool
x::Bool
end
immutable Negated{T}
x::T
end
immutable BitWrapper
x::Vector{Uint64}
end
Base.getindex(x::BitWrapper, i) = CheapMulBool(!Base.unsafe_bitgetindex(x.x, i))
View alist.jl
immutable AListWrapper{Name}; end
immutable AList{Keys<:(AListWrapper...),Types} <: Associative
v::Types
end
macro alist(args...)
keys = Array(Any, length(args))
values = Array(Any, length(args))
for i = 1:length(args)
if !Base.Meta.isexpr(args[i], :(=>))
@simonster
simonster / divinverse.jl
Last active Aug 29, 2015
Faster vectorized integer division
View divinverse.jl
import Base.rem, Base.div, Base.divrem
unsigned_type(::Int8) = Uint8
unsigned_type(::Int16) = Uint16
unsigned_type(::Int32) = Uint32
unsigned_type(::Int64) = Uint64
unsigned_type(::Int128) = Uint128
immutable SignedMultiplicativeInverse{T<:Signed}
divisor::T
multiplier::T
View gist:6195af68c6df33ca965d
function iain_magic(n::Int)
# Odd-order magic square
# http://en.wikipedia.org/wiki/Magic_square#Method_for_constructing_a_magic_square_of_odd_order
M = zeros(Int, n, n)
for I = 1:n, J = 1:n # row, column
@inbounds M[I,J] = n*((I+J-1+(n >> 1))%n) + ((I+2J-2)%n) + 1
end
return M
end
View h5dump test.jld
HDF5 "test.jld" {
GROUP "/" {
DATASET "ComplexImmutable" {
DATATYPE "/_types/3"
DATASPACE SCALAR
DATA {
(0): {
{
1,
2.2
View gist:7c8c753a06ce164e817f
|-------|----------------------|------------------|------------|-------------|-------------|-----------------|-----------------|
| Row # | proc | (nsamples,ncoef) | time_julia | time_matlab | time_octave | matlab_relative | octave_relative |
| 1 | "filt SOSFilter" | (256,2) | 0.00210658 | 0.0901177 | 0.00722314 | 42.7792 | 3.42885 |
| 2 | "filt SOSFilter" | (256,4) | 0.00258519 | 0.0925957 | 0.00938837 | 35.8177 | 3.63159 |
| 3 | "filt SOSFilter" | (256,8) | 0.00363507 | 0.0985003 | 0.0133466 | 27.0972 | 3.67161 |
| 4 | "filt SOSFilter" | (256,16) | 0.00600978 | 0.109797 | 0.0212647 | 18.2697 | 3.53835 |
| 5 | "filt SOSFilter" | (1024,2) | 0.00705921 | 0.0935538 | 0.0125278 | 13.2527 | 1.77467 |
| 6 | "filt SOSFilter" | (1024,4) | 0.00867183 | 0.0966722 | 0.0192736 | 11.1478 | 2.22256
You can’t perform that action at this time.