Skip to content

Instantly share code, notes, and snippets.

View ziotom78's full-sized avatar

Maurizio Tomasi ziotom78

View GitHub Profile
@ziotom78
ziotom78 / typecb
Created December 23, 2023 08:27
A Bash script that types what's inside the clipboard after some amount of time
#!/bin/bash
if [ "$1" == "" ]; then
cat <<EOF
Paste the contents of the keyboard as if they were typed using the keyboard
Usage: $(basename $0) WAIT_TIME
where WAIT_TIME is the delay, like "3s" (three seconds)
EOF
@ziotom78
ziotom78 / download_fmt_library.sh
Created March 31, 2021 08:44
Bash script to download the fmt library (C++)
#!/bin/bash
# Copyright (c) 2020 Maurizio Tomasi
#
# This Bash script downloads the "fmt" C++ library and installs it in
# the current directory.
FMT_VERSION="7.1.2"
download_file() {
@ziotom78
ziotom78 / scipy_rotations_test.py
Created August 10, 2020 18:06
Test the performance of scipy vs the rotation functions in litebird_sim
#!/usr/bin/env python3
# -*- encoding: utf-8 -*-
import numpy as np
from litebird_sim import all_compute_pointing_and_polangle
from scipy.spatial.transform import Rotation as R
def polangle_scipy(theta, phi, poldir):
cos_psi = np.clip(-np.sin(phi) * poldir[:, 0] + np.cos(phi) * poldir[:, 1], -1, 1)
@ziotom78
ziotom78 / julia_set_benchmark.nim
Last active May 2, 2020 07:13
Check Nim's implementation of the Complex64 types by computing Julia sets
# -*- encoding: utf-8 -*-
# Check different implementations of the algorithm to determine if a
# point z ∈ ℂ belongs to Julia set J_c
import complex
import math
import strformat
import times
@ziotom78
ziotom78 / numbahpix.py
Last active January 29, 2020 21:46
Comparison between Healpy functions and a Numba-based implementation
# -*- encoding: utf-8 -*-
import numpy as np
import math
from numba import njit, vectorize, int32, int64, float32, float64
@njit
def normalize_angle(ang):
result = ang
@ziotom78
ziotom78 / extract_bandpasses.jl
Created May 22, 2019 15:03
Save Strip bandpasses using Stripeline
import Stripeline
import DelimitedFiles
db = Stripeline.InstrumentDB()
for horn in keys(db.focalplane) |> collect |> sort
curdet = db.detectors[db.focalplane[horn].polid]
curdet.band == "W" && continue
response = curdet.bandshape
freqs = range(response.lowest_frequency_hz, response.highest_frequency_hz, length=response.num_of_frequencies) ./ 1e9
filename = "$(horn).txt"
@ziotom78
ziotom78 / README.txt
Last active August 29, 2015 14:11
A CSS style for Nim documentation
To compile the SASS files into "nimdocs.css", install SASS
gem install sass
and then run
sass -t compressed nimdocs.scss:nimdocs.css
Maurizio Tomasi
December 2014
@ziotom78
ziotom78 / mean_test.cpp
Created June 22, 2012 11:06
Mean calculation test
#include <iostream>
#include <vector>
template<typename T> T
mean_with_accumulator(const std::vector<T> & vec)
{
T acc = 0.0;
for(T cur_element : vec)
acc += cur_element;
@ziotom78
ziotom78 / doubleWithReference.s
Created October 14, 2011 20:25
Assembly code produced by GCC 4.2.1 for the "doubleThis" function (with reference parameter)
__Z24doubleThisRd:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -8(%rbp)
movq -8(%rbp), %rax
movsd (%rax), %xmm0 # Put in xmm0 the value pointed by RAX
addsd %xmm0, %xmm0 # Calculate x+x instead of 2x
leave
ret
@ziotom78
ziotom78 / doubleWithReference.cpp
Created October 14, 2011 20:20
Double a floating-point value (with reference parameter)
double
doubleThis(double & x)
{
return x * 2;
}