Skip to content

Instantly share code, notes, and snippets.

Kenta Sato bicycle1885

Block or report user

Report or block bicycle1885

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View equilibrium.jl
using LinearAlgebra: qr
function equilibrium(Q::AbstractMatrix)
@assert size(Q, 1) == size(Q, 2)
R = qr(Q').R
n = size(Q, 1)
v = zeros(eltype(Q), n)
v[end] = 1
for i in n-1:-1:1
s = zero(eltype(Q))
@bicycle1885
bicycle1885 / par.jl
Created Jun 5, 2019
Parallel execution
View par.jl
macro par(expr)
thunk = esc(:(()->($expr)))
quote
local task = Task($thunk)
task.sticky = false
schedule(task)
task
end
end
View array1.jl
const a = (1, 2, 3, 4)
function func(b)
sum = 0
for i in 1:4
sum += a[i] * b[i]
end
return sum
end
View safenan.py
import types
class SafeNaN(types.ModuleType):
def __setattr__(self, attr, value):
if attr == "nan":
raise RuntimeError("cannot reassign 'nan'")
super().__setattr__(attr, value)
import sys
import numpy
@bicycle1885
bicycle1885 / callstack.jl
Created Feb 13, 2019
A macro to show the callstack inside a function call.
View callstack.jl
module CallStack
export @callstack
using Cassette
mutable struct CallState
depth::Int
end
View vimrc
" General
syntax enable
set nocompatible
set noswapfile
if executable("rg")
set grepprg=rg\ --vimgrep\ --no-heading
set grepformat=%f:%l:%c:%m,%f:%l:%m
endif
autocmd QuickFixCmdPost * copen
nnoremap <silent> <C-n> :cn<CR>
View rsvd.jl
# Randomized SVD
# --------------
#
# H. Li, G. C. Linderman, et al. "Algorithm 971: An Implementation of a
# Randomized Algorithm for Principal Component Analysis", ACM Transactions on
# Mathematical Software (TOMS), 2017
# DOI: https://doi.org/10.1145/3004053
#
# N. Halko, P. G. Martinsson, and J. A. Tropp, "Finding Structure with
# Randomness: Probabilistic Algorithms for Constructing Approximate Matrix
@bicycle1885
bicycle1885 / gencode.jl
Created Dec 3, 2017
Generated code from numbers.jl
View gencode.jl
quote
if p > p_end
@goto exit
end
##667 = (Automa.SizedMemory)(data)
if cs == 1
@goto state_case_1
else
if cs == 2
@goto state_case_2
View base64.jl
# License: MIT
module Base64
export
Base64EncodePipe,
base64encode
# Data buffer for pipes.
mutable struct Buffer
@bicycle1885
bicycle1885 / structure.jl
Created Jun 24, 2017
Biomolecular structure
View structure.jl
import NamedTuples: NamedTuples, @NT
# Atom
# ----
# NOTE: This must be synchronized with `AtomCoords`.
struct Atom
id::Int32
x::Float32
y::Float32
You can’t perform that action at this time.