Skip to content

Instantly share code, notes, and snippets.

@oyd11
oyd11 / batt.sh
Created September 30, 2024 12:01
screenrc with battery bar
#!/usr/bin/env bash
# display battery percentage, and AC/DC status via ~[AC] _[DC], C(harging) F(ull) D(ischarging)
# Works - on Lenovo Thinkpad
set -u
# or call
# upower -d
# detail text info
#!/usr/bin/env bash
set -u # stop unset
set -e # stop error
target_db=-18
volume_range=3 # db
output_sr=48000 # match with input SR
#output_sr=24000 # some speech synths
output_folder="../n/"
@oyd11
oyd11 / screenrc
Created June 19, 2018 15:52
.screenrc ( should do a .dotfiles repo )
shell ${SHELL}
startup_message off
termcapinfo xterm* ti@:te@
defscrollback 10000 # default: 100
@oyd11
oyd11 / c_like_arrays.jl
Last active June 19, 2018 16:00
'raw' pointers to arrays - back and forth to Julia Arrays::
#!/usr/bin/env julia
# Julia 0.6 syntax
v = Float64.(1:10) # "Julia vector
p = pointer(v) # 'raw' c-like pointer to data
v1 = unsafe_wrap(Matrix{Float64}, p, (10,1), false) # get vector 'back'
m1 = unsafe_wrap(Matrix{Float64}, p, (2,5), false) # as Matrix
m2 = unsafe_wrap(Matrix{Float64}, p, (5,2), false) # another 'reshape()'
@oyd11
oyd11 / mkRepPlaylist.jl
Last active January 20, 2019 16:06
Spaced-repetition playlist creator for the "language survival kits" audio-phrasebooks at : http://fieldsupport.dliflc.edu
#!/usr/bin/env julia
# Poor-man's "spaced-repetition" playlist creator
# for audio playlists from http://fieldsupport.dliflc.edu ::
# "language survival kits"
# Julia 0.6 script:
if length(ARGS) < 1
error("missing Language arg, for example: 'tigrinya'")
@oyd11
oyd11 / string_macro_interpolate.jl
Last active February 18, 2018 15:42
unescape string interpolation, Julia 0.6
# see: https://stackoverflow.com/questions/39493808/macros-and-string-interpolation-julia
macro e_str(s)
esc(parse("\"$(escape_string(s))\""))
end
# for example :
"""create a Dict{Symbol,Any} capturing variables
Example:
```
a=1 ; b=11
d = @capture_dict(a,b)
> Dict{Symbol,Int64} with 2 entries:
> :a => 1 , :b => 11
```
"""
macro capture_dict(variables...)
@oyd11
oyd11 / branch-juggling.js
Created February 13, 2018 15:33
(real) useless git branch juggling
'use strict'
/////
let child_process = require('child_process')
// execSync: from stackoverflow advice:
// https://stackoverflow.com/questions/32874316/node-js-accessing-the-exit-code-and-stderr-of-a-system-command
function systemSync(cmd) {
console.log("exec: ", cmd)
try {
@oyd11
oyd11 / symbol_dict.jl
Created February 7, 2018 14:38
Julia, convert dictionary keys to Symbols, recursively
# Julia 0.6 syntax:
# create a dictionary with 'Symbol' keys instead of 'String' keys
# sometimes after serializing from a JSON:
module Misc
f_helper(x) = x
f_helper(d::Dict) = Dict(Symbol(k) => f_helper(v) for (k, v) in d)
symbol_dict(d::Dict) = f_helper(d)
@oyd11
oyd11 / same-type.cpp
Created January 28, 2018 11:03
same-type created by KobiKaiKai - https://repl.it/@KobiKaiKai/same-type
#include <iostream>
template<typename T>
bool is_same_type(T a,T b) {
return true;
}
template<typename T, typename S>
bool is_same_type(T a,S b) {
return false;