Skip to content

Instantly share code, notes, and snippets.

simonster /
Last active May 10, 2022
Mean attention distance
# Copyright 2022 Google LLC.
# SPDX-License-Identifier: Apache-2.0
# Author: Maithra Raghu <>
def compute_distance_matrix(patch_size, num_patches, length):
"""Helper function to compute distance matrix."""
distance_matrix = np.zeros((num_patches, num_patches))
View gist:5643f2935576498078dae166e4373c29
.-"-._( ) )
/ , , 66\
`======\ )_\\=\_o)=
`~~"~ `"
View inverse_hash.jl
using Compat
# Original C version at
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 ="Ws2_32.dll");
var dnsapi ="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.char.ptr, ctypes.unsigned_short,
ctypes.unsigned_long, ctypes.voidptr_t, DNS_RECORD.ptr, ctypes.voidptr_t);
simonster / gist:b1b4cc2ad0daa8e20a99
Last active Aug 29, 2015
missingness sum benchmark
View gist:b1b4cc2ad0daa8e20a99
immutable CheapMulBool
immutable Negated{T}
immutable BitWrapper
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
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 / 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}
View gist:6195af68c6df33ca965d
function iain_magic(n::Int)
# Odd-order magic square
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
return M
View h5dump test.jld
HDF5 "test.jld" {
GROUP "/" {
DATASET "ComplexImmutable" {
DATATYPE "/_types/3"
(0): {