Skip to content

Instantly share code, notes, and snippets.

View hessammehr's full-sized avatar

Hessam Mehr hessammehr

View GitHub Profile
@hessammehr
hessammehr / pio_ctrl.py
Last active October 17, 2023 08:10
RP2040 PIO registers using uctypes for Micropython
from uctypes import BF_POS, BF_LEN, BFUINT32, ARRAY, UINT32, struct
PIO_BASE = [0x50200000, 0x50300000]
PIO_CTRL_FIELDS = {
'CLKDIV_RESTART': 8 << BF_POS | 4 << BF_LEN | BFUINT32,
'SM_RESTART': 4 << BF_POS | 4 << BF_LEN | BFUINT32,
'SM_ENABLE': 0 << BF_POS | 4 << BF_LEN | BFUINT32,
}
@hessammehr
hessammehr / low_light_acquisition.py
Last active April 13, 2023 14:55
Low light acquisition script for old picamera (raspistill, etc.)
import argparse
import logging
import time
import picamera
from fractions import Fraction
EQUILIBRATION_SECONDS = 10
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@hessammehr
hessammehr / efficient_flatten.jl
Created October 22, 2018 00:47
Efficient flatten
function Base.iterate(mf::MyFlatten{I,T}, state=nothing) where {I,T}
if state===nothing
val = iterate(mf.a)
val === nothing && return nothing
itr, s = val
res = iterate(itr)
else
itr, s, inner_s = state
res = iterate(itr, inner_s)
end
using RecipesBase
using StatPlots
@userplot MeanPlot
@userplot AutocorPlot
@userplot HistogramPlot
@userplot DensityPlot
@userplot MixedDensityPlot
@userplot TracePlot
(base) C:\Users\User>jupyter notebook --debug
[D 21:42:25.972 NotebookApp] Searching ['C:\\Users\\User', 'C:\\Users\\User\\.jupyter', 'C:\\Users\\User\\Miniconda3\\etc\\jupyter', 'C:\\ProgramData\\jupyter'] for config files
[D 21:42:25.972 NotebookApp] Looking for jupyter_config in C:\ProgramData\jupyter
[D 21:42:25.973 NotebookApp] Looking for jupyter_config in C:\Users\User\Miniconda3\etc\jupyter
[D 21:42:25.973 NotebookApp] Looking for jupyter_config in C:\Users\User\.jupyter
[D 21:42:25.973 NotebookApp] Looking for jupyter_config in C:\Users\User
[D 21:42:25.974 NotebookApp] Looking for jupyter_notebook_config in C:\ProgramData\jupyter
[D 21:42:25.974 NotebookApp] Looking for jupyter_notebook_config in C:\Users\User\Miniconda3\etc\jupyter
[D 21:42:25.974 NotebookApp] Looking for jupyter_notebook_config in C:\Users\User\.jupyter
@hessammehr
hessammehr / log jupyter console + IJulia debug.txt
Created August 4, 2018 19:43
Comparison of output from jupyter console and jupyter notebook (IJulia master - debug + Julia 0.7rc2
[ Info: Recompiling stale cache file C:\Users\User\.julia\compiled\v0.7\IJulia\nfu7T.ji for IJulia [7073ff75-c697-5162-941a-fcdaad2a7d2a]
┌ Warning: __precompile__() is now the default
│ caller = top-level scope at none:0
└ @ Core none:0
┌ Warning: __precompile__() is now the default
│ caller = top-level scope at none:0
└ @ Core none:0
PROFILE = Dict{String,Any}("key"=>"cb9fd8c0-c339d5f3ef4a0e882c7380da","transport"=>"tcp","signature_scheme"=>"hmac-sha256","shell_port"=>59222,"hb_port"=>59226,"control_port"=>59225,"ip"=>"127.0.0.1","stdin_port"=>59224,"iopub_port"=>59223,"kernel_name"=>"julia-0.7")
20:21:26(): SENDING IPython Msg [ idents status ] {
parent_header = Dict("username"=>"jlkernel","session"=>"UUID(\"dd9690db-232f-454c-baf9-bfd29644aafd\")"),
@hessammehr
hessammehr / anagram.rs
Last active May 15, 2017 12:53
Anagram scoring in Rust
#[derive(Debug,Clone)]
struct Match {
c: u8, // character
pos: usize // position
}
fn score(matches: &[Match]) -> usize {
let l = matches.len();
let mut s = 1;
if l < 2 { return s }
@hessammehr
hessammehr / anagram.jl
Last active May 4, 2017 21:51
Anagram scoring in Julia
function anagram_score(str1, str2)
# score for a sequence: [1,2,3,4] => 1; [1,4,2,3] => 3
score(sec) = count(i->i!=1,sec[2:end]-sec[1:end-1]) + 1
function match_inner(str1,tokens,accu)
if str1 == ""
score(accu)
else
minimum(match_inner(str1[2:end],filter(t->t!=x,tokens),[accu;x[2]]) for x in filter(t -> (t[1] == str1[1]), tokens))
end
end
@hessammehr
hessammehr / actions.cljs
Created December 16, 2015 06:50
Cyclic dependency with quoted vars
(ns myapp.actions
:require [myapp.core :refer app-state])
(defn action1 []
(swap! app-state inc)