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 / 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 / double.s
Created October 14, 2011 20:18
Assembly output of GCC 4.2.1 for the "doubleThis" function
__Z11doubleThisd:
pushq %rbp
movq %rsp, %rbp
movsd %xmm0, -8(%rbp)
movsd -8(%rbp), %xmm0 # Directly copy the parameter into the FP register
addsd %xmm0, %xmm0 # Calculate x+x instead of 2x
leave
ret
@ziotom78
ziotom78 / double.cpp
Created October 14, 2011 20:15
Double a floating-point number (version without reference argument)
double
doubleThis(double x)
{
return x * 2;
}
@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