Skip to content

Instantly share code, notes, and snippets.

View edwinb-ai's full-sized avatar
:shipit:
Working out some ideas

Edwin Bedolla edwinb-ai

:shipit:
Working out some ideas
  • Utrecht, Netherlands
View GitHub Profile
@edwinb-ai
edwinb-ai / dbrownian.jl
Last active February 18, 2024 15:01
Brownian Dynamics with cell lists
using Random
using StaticArrays
using LinearAlgebra
using DelimitedFiles
using ThreadPools
using Printf
using CellListMap.PeriodicSystems
import CellListMap.PeriodicSystems: copy_output, reset_output!, reducer
struct Parameters
@edwinb-ai
edwinb-ai / clenshaw_curtis.py
Created September 24, 2023 14:52
This is an implementation of the Clenshaw-Curtis quadrature for solving definite integrals. It is a direct translation from the MATLAB code presented in (Trefethen, L. N. (2008). Is Gauss quadrature better than Clenshaw–Curtis?. SIAM review, 50(1), 67-87).
import numpy as np
from scipy.fft import fft
def clenshaw_curtis(f, a, b, n):
# Obtain Chebyshev points
x = np.cos(np.pi * np.arange(n + 1) / n)
# Rescale the points to the interval
scaled_x = ((a + b) + ((b - a) * x)) * 0.5
# Evalute the integrand
@edwinb-ai
edwinb-ai / blockjonsson.jl
Last active September 25, 2023 10:27
This is an implementation of the blocking method of Jonsson (PHYSICAL REVIEW E 98, 043304 (2018)) in Julia. It takes an array as input and will output the estimated error of the mean value using rigorous blocking arguments.
function blockjonsson(a::AbstractArray)
d = log2(length(a))
x = copy(a)
if (d - floor(d)) != 0
@info "Warning: Data size = $(floor(2^d)), is not a power of 2."
@info "Truncating data to $(2^floor(d))."
x = x[1:(2^round(Int, floor(d)))]
end
d = round(Int, floor(d))
n = 2^d
@edwinb-ai
edwinb-ai / sinft.jl
Created February 18, 2021 05:23
Fourier sine transform from Numerical Recipes
function four1!(data, nn, isign)
n = Int(2 * nn)
j = 1
for i = 1:2:n
if j > i
tempr = data[j]
tempi = data[j + 1]
data[j] = data[i]
data[j + 1] = data[i + 1]
@edwinb-ai
edwinb-ai / test-ubuntu-svm.def
Created January 25, 2021 18:56
Container Ubuntu 20.04
BootStrap: library
From: ubuntu:20.04
%post
export PATH=/julia-1.5.3/bin:$PATH
apt-get -y update
# install some basic tools
apt-get -y install curl tar gzip git
@edwinb-ai
edwinb-ai / test-svm.def
Created January 25, 2021 17:38
Singularity container
BootStrap: library
From: ubuntu:16.04
%post
export PATH=/julia-1.5.3/bin:$PATH
export LD_LIBRARY_PATH=/julia-1.5.3/lib:/julia-1.5.3/lib/julia:$LD_LIBRARY_PATH
export LC_ALL=C
apt-get -y update
@edwinb-ai
edwinb-ai / mnist.py
Last active June 20, 2020 23:18
Classify the MNIST dataset using RNN with LSTM blocks.
import tensorflow as tf
import tensorflow.keras as K
import numpy as np
# Load the MNIST data and show the shape, should be (60000, 28, 28)
mnist = K.datasets.mnist
(x_train, y_train), (x_test, y_test) = mnist.load_data()
print(x_train.shape)
@edwinb-ai
edwinb-ai / randomseed.py
Created February 25, 2020 18:30
Obtain a truly random seed from the system by using random files and entropy.
import os
import sys
def some_seed():
seed = int.from_bytes(os.urandom(7), sys.byteorder)
return seed
@edwinb-ai
edwinb-ai / alacritty.yml
Created November 21, 2019 21:36
Alacritty terminal config file
# Configuration for Alacritty, the GPU enhanced terminal emulator.
# Any items in the `env` entry below will be added as
# environment variables. Some entries may override variables
# set by alacritty itself.
#env:
# TERM variable
#
# This value is used to set the `$TERM` environment variable for
# each instance of Alacritty. If it is not present, alacritty will
@edwinb-ai
edwinb-ai / passwd_hash.py
Last active November 21, 2019 18:31
Hash passwords with SHA512 and very random numbers.
import hashlib, binascii, os
def hash_password(password):
"""Hash a password for storing."""
salt = hashlib.sha256(os.urandom(60)).hexdigest().encode("ascii")
pwdhash = hashlib.pbkdf2_hmac("sha512", password.encode("utf-8"),
salt, 100000)
pwdhash = binascii.hexlify(pwdhash)
return (salt + pwdhash).decode("ascii")