Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env bash
compgen -c | sort | uniq | sort -R | tail -n 1
using Dates
function findfirst_tuesday(d::Date)
fd = dayofweek(firstdayofmonth(d))
return Tuesday - fd + 1 + 7(fd > Tuesday)
end
findfirst_tuesday(m::Month, y::Year) = findfirst_tuesday(Date(m, y))
function penultimate_tuesday_date(m::Month, y::Year)
ft = findfirst_tuesday(m, y) # first Tuesday
# This was my version of Formatting.jl's `format(..., comma = true)`
# I did this for fun, not having a look at Formatting.jl's version
# It looks like this is how they did it:
# https://github.com/JuliaIO/Formatting.jl/blob/master/src/cformat.jl#L77-L93
# Quite different to how I did it...probably benchmarks better though
function format_number(n::String, delim::Union{Char, S}) where {S <: AbstractString}
len = length(n)
io = IOBuffer()
for (i, c) in enumerate(reverse(n))
@jakewilliami
jakewilliami / option.jl
Created September 20, 2021 04:07
Rust Options in Julia
struct Some{T}
val::T
function Some{T}(val::T) where {T}
isnothing(val) && error("Cannot have some of nothing")
return new{T}(val)
end
end
Some(val::T) where {T} = Some{T}(val)
struct Option{T}
# Ported from https://gist.github.com/MicahElliott/719710
# Credit goes to Micah Elliott
using Colors
using OrderedCollections
CLUT = Tuple{String, String}[ # color look-up table
# 8-bit, RGB hex
# Primary 3-bit (8 colors). Unique representation!
function takeFirst<T>(arr: T[]) {
const firstVal: T = arr[0];
arr.splice(0, 1);
return firstVal;
}
SM.addState(State.SubTrial, {
onEnter: (machine: stateMachine.Machine, blockStruct: BlockStruct) => {
if (blockStruct.trialArrayURLs.length === 0) {
// then we need to initialise another trial!
SM.addState(State.FixationCross, {
onEnter: (machine: stateMachine.Machine, blockStruct: BlockStruct) => {
gorilla.populate('#gorilla', 'fixation', {});
$('#gorilla')
.delay(beforeFixationDelay)
.queue(function () {
$('.fixation-cross').show();
gorilla.refreshLayout();
$(this).dequeue();
})// end queue for '#gorilla'
function nztm2longlat(X::T, Y::T) where T <: Number
a = 6378137
f = 1 / 298.257222101
ϕ0 = 0
λ0 = 173
N0 = 10000000
E0 = 1600000
k0 = 0.9996
N, E = Y, X
b = a * (1 - f)
import sys, math
def nztm2longlat(X, Y):
a = 6378137
f = 1 / 298.257222101
phizero = 0
lambdazero = 173
Nzero = 10000000
Ezero = 1600000
kzero = 0.9996
import random
# f = open(experiment_path + '/' + 'subject-' + str(subject_nr) + '-auxiliary.csv', 'a') # this will create an auxiliary datafile for participant (`subject_nr` is a predefined variable)
f = open(logfile, 'a') # this will append to the log file (`logfile` is a predefined variable)
f.write('ISI,\n')
for ISI in [[1900, 2000, 2100][random.randint(0, 2)] for _ in range(100)]:
f.write(str(ISI) + ',\n')
f.close()