Skip to content

Instantly share code, notes, and snippets.

View kozross's full-sized avatar

Koz Ross kozross

View GitHub Profile
# I have the following Gawk invocation, which correctly only prints certain fields of a file in a comma-separated list
#
# gawk -F ',' -v NLINES=$(wc -l < members.csv) 'NR > 1 { printf("%s", $4) } NR != nlines && NR > 1 { printf(",") }' members.csv
#
# I'm trying to translate this into an actual script, and I have the following:
#!/usr/bin/gawk -f
FS = ","
NLINES = system("wc -l <" ARGV[1])
const lookup_table = sparse(vcat(collect.(repeated.(1:9, binomial.(8, 0:8)))...),
vcat(map(x -> collect(1:x), binomial.(8, 0:8))...),
vcat(collect.(Permutations.(0:8))...)) #Permutations is a custom iterator I define earlier
#= I have the following sauce code: =#
module TruthTable
import Base.size, Base.getindex, Base.linearindexing
export Table, random
immutable Table
p :: Int
unpack :: BitVector
end
# I have the following bit of code
using Format
type MinimaxNode
id :: Int
min_node :: Bool
val :: Int
children :: Vector{MinimaxNode}
end
function f(old, # what type is this?
# I have the following sauce code:
import Iterators
type MinimaxNode
id :: Int
min_node :: Bool
val :: Nullable{Int}
children :: Vector{MinimaxNode}
end
ERROR: MethodError: Cannot `convert` an object of type Int64 to an object of type Type{Int64}
This may have arisen from a call to the constructor Type{Int64}(...),since type constructors fall back to convert methods.
in copy!(::Array{Type{Int64},1}, ::TruthTable.TableIndex) at ./abstractarray.jl:479
in collect(::TruthTable.TableIndex) at ./array.jl:273
in eval_user_input(::Any, ::Base.REPL.REPLBackend) at ./REPL.jl:64
in macro expansion at ./REPL.jl:95 [inlined]
in (::Base.REPL.##3#4{Base.REPL.REPLBackend})() at ./event.jl:68
\ This example is straight from Starting Forth.
HERE 5 CELLS ALLOT BASE !
: limit ( index -- addr ) CELLS [ BASE @ ] LITERAL + ;
DECIMAL
\ Is there a way to avoid the first line (i.e. dumping the address into a 'scratch variable')?
\ My initial thinking was something like:
: limit ( index -- addr ) CELLS [ HERE 5 CELLS ALLOT ] LITERAL + ;
-- I have the following table schemata in SQLite
CREATE TABLE experiments (
id integer not null primary key autoincrement,seed integer not null,
gens integer not null check (gens > 0),
keep_every integer not null check (keep_every > 0),
cluster_size integer not null check (cluster_size > 0),
search_width integer not null check (search_width > 0),
table_size integer not null check (table_size > 2)
);
;;;; My init.el
;;; Ensuring all my packages are installed
;; set up the packaging system
(require 'package)
(add-to-list 'package-archives '("gnu" . "http://elpa.gnu.org/packages/"))
(add-to-list 'package-archives '("melpa" . "http://melpa.milkbox.net/packages/"))
(package-initialize)
#!/usr/bin/gawk -f
BEGIN {
# set up tracker for which epoch we're in
epoch = -1
# set up counter for how many entries we've seen
counter = 0