Skip to content

Instantly share code, notes, and snippets.

@jakewilliami
jakewilliami / option.jl
Created Sep 20, 2021
Rust Options in Julia
View option.jl
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}
View rgb2xterm256.jl
# 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!
View subtrial.ts
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!
View fixationcross.ts
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'
View nztm2longlat.jl
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)
View nztm2longlat.py
import sys, math
def nztm2longlat(X, Y):
a = 6378137
f = 1 / 298.257222101
phizero = 0
lambdazero = 173
Nzero = 10000000
Ezero = 1600000
kzero = 0.9996
View ISI_recording.py
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()
View text-box-timer-gorilla.ts
import gorilla = require('gorilla/gorilla');
// Initialise the timer
var stateTimer: gorilla.GorillaTimerSequence;
// Add variable to determine delay
var allowedTime: number = 2000; // set original timer to 2 seconds (2000 milliseconds)
// check if textbox is selected
if ($(document.activeElement).attr("type") == "text" || $(document.activeElement).attr("type") == "textarea") {
View image_array.py
from PIL import Image # this is used to create the images
import glob # this is used for reading the directory (folder) of images
import random # this is used to choose 25 unique random images
from math import ceil, floor
distractors = glob.glob("Distractor/*") # this is where you need to put your path to directory
cars = glob.glob("Cars/*")
faces = glob.glob("Faces/*")
hf_pareidolia = glob.glob("Highface pareidolia/*")
lf_pareidolia = glob.glob("Lowface pareidolia/*")
View sudoku.jl
mutable struct Sudoku{T <: Integer} <: AbstractMatrix{T}
A::AbstractMatrix{T} where {T <: Integer}
function Sudoku(A::AbstractMatrix{T}) where {T <: Integer}
size(A, 1) == size(A, 2) || throw(error("Sodokus must be square; received matrix of size $(size(A, 1))×$(size(A, 2))."))
isequal(sqrt(size(A, 1)), isqrt(size(A, 1))) || throw(error("Sudokus must be able to split into equal boxes (e.g., a 9×9 Sudoku has three 3×3 squares). Size given is $(size(A, 1))×$(size(A, 2))."))
new{T}(A)
end
# fill in blank sudoku if needed
Sudoku(::Type{T}, n::Int) where {T <: Integer} = new{T}(fill(zero(T), n, n))