Skip to content

Instantly share code, notes, and snippets.

View robertfeldt's full-sized avatar

Robert Feldt robertfeldt

View GitHub Profile
@robertfeldt
robertfeldt / got_sw3_generate_text_example.jl
Created January 27, 2023 15:48
Example of generating text with GPT-SW3 from Julia
# Setup step 0: Build PyCall.jl for right Python binary
#
# Might be needed to ensure the right python is used, here for my homebrew
# installed python3 on a M1 MacBook Pro:
# ENV["PYTHON"] = "/opt/homebrew/bin/python3"
# using Pkg
# Pkg.build("PyCall")
# Setup step 1: Ensuring you have access to GPT-SW3 by setting up a token on Hugging Face
# a. login on HF: https://huggingface.co/login
@robertfeldt
robertfeldt / boxes_puzzle.jl
Created July 6, 2022 03:14
Checking the "Boxes puzzle" solution strategy via stochastic simulation
# Checking the "Boxes puzzle" solution strategy via stochastic simulation.
# [email protected] 2022
using Random # We need randperm below
# Fill N boxes by getting a random permutation of length N.
fillboxes(N) = randperm(N)
# Given a strategy, simulate its use by N people and return true iff strategy
# worked for them all.
@robertfeldt
robertfeldt / speeding_up_qgram_distances_with_precalculation_sorted_array_version_faster.jl
Created October 21, 2020 11:54
Optimized speeding up of StringDistances.jl qgram distances with precalculation of qgram counts (here in a sorted array of counts per qgram)
using StringDistances
function countdict(qgrams)
d = Dict{eltype(qgrams), Int32}()
for qg in qgrams
index = Base.ht_keyindex2!(d, qg)
if index > 0
d.age += 1
@inbounds d.keys[index] = qg
@inbounds d.vals[index] = d.vals[index][1] + 1
@robertfeldt
robertfeldt / speeding_up_qgram_distances_with_precalculation_sorted_array_version.jl.jl
Created October 21, 2020 08:06
Speeding up StringDistances.jl qgram distances with precalculation of qgram counts (here in a sorted array of counts per qgram)
using StringDistances
function countdict(qgrams)
d = Dict{eltype(qgrams), Int32}()
for qg in qgrams
index = Base.ht_keyindex2!(d, qg)
if index > 0
d.age += 1
@inbounds d.keys[index] = qg
@inbounds d.vals[index] = d.vals[index][1] + 1
@robertfeldt
robertfeldt / speeding_up_qgram_distances_with_precalculation.jl
Created October 20, 2020 09:36
Speeding up StringDistances.jl qgram distances with precalculation of qgram counts (here in count dict)
using StringDistances
function countdict(qgrams)
d = Dict{eltype(qgrams), Int32}()
for qg in qgrams
index = Base.ht_keyindex2!(d, qg)
if index > 0
d.age += 1
@inbounds d.keys[index] = qg
@inbounds d.vals[index] = d.vals[index][1] + 1
@robertfeldt
robertfeldt / dynamically_updating_VegaLite_from_Julia.jl
Created March 18, 2020 15:44
VegaLite frontend with data pushed over websocket from Julia backend
using HTTP, JSON
const VegaLiteWebsocketFrontEndTemplate = """
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<script src="https://cdn.jsdelivr.net/npm/vega@3"></script>
<script src="https://cdn.jsdelivr.net/npm/vega-lite@2"></script>
<script src="https://cdn.jsdelivr.net/npm/vega-embed@3"></script>
</head>
@robertfeldt
robertfeldt / multithreaded_optimization.jl
Last active January 4, 2020 13:19
MultiThreadedEvaluator testing and example scripts
if Threads.nthreads() < 2
exit("Multiple threads NOT found! Makes no sense to test this without them... Start as, for example: JULIA_NUM_THREADS=4 julia multithreaded_optimization.jl")
end
using BlackBoxOptim
# Functions to optimize. Should be thread-safe.
function rosenbrock(x)
sleep(0.01) # So that there is some benefit in the thread switching...
sum(i -> 100*abs2(x[i+1] - x[i]^2) + abs2(x[i] - 1), Base.OneTo(length(x)-1))
@robertfeldt
robertfeldt / fake_emsej_review_data.json
Last active September 30, 2019 14:55
EMSEJ Paper Review Data
{
"nodes": [
{
"name": "Submissions",
"color": "#C0C0C0"
},
{
"name": "Desk rejected",
"color": "#FF3333"
},
# Output when running this script:
# ICSE 2019 attendees per million capita:
# 1. Luxembourg, 15, 25.126
# 2. Canada, 330, 8.852
# 3. Sweden, 41, 4.078
# 4. Ireland, 16, 3.301
# 5. Switzerland, 27, 3.137
# 6. Singapore, 17, 2.897
# 7. Norway, 15, 2.777
# 8. Netherlands, 32, 1.868
using HypothesisTests
# Checked num downloads from each papers page in SpringerLink 2017-04-26 08:05 CET
OpenAccessPaperDownloads = [2400, 589] # says 2.4k downloads, approximates with 2400
NonOAPaperDownloads = [134, 126, 85, 104, 56, 228, 112]
println(pvalue(MannWhitneyUTest(OpenAccessPaperDownloads, NonOAPaperDownloads)))
# p-value is 0.055
# Executed 2017-04-26 08:10 CET on MacBook Pro 13" 2015 running Julia 0.5.1 with HypothesisTests version 0.5.1