Skip to content

Instantly share code, notes, and snippets.

@kidpixo
kidpixo / sumdigits_naturals_product.py
Created June 19, 2023 11:41
sumDigits naturals product
# first 10 naturals
nat = np.arange(1,10)
# multiply them
nat_df = pd.DataFrame(
columns=nat,
index=nat,
data=np.matmul(nat[:,np.newaxis],nat[:,np.newaxis].T))
def sumDigits(no):
return 0 if no == 0 else int(no % 10) + sumDigits(int(no / 10))
@kidpixo
kidpixo / relabels.py
Created May 4, 2023 12:58
colors: relabelling the classes using the first centroids values
#####
# colors: relabelling the classes using the first centroids values
# calculate all the class centers in data space
y = X.groupby(labels).mean().values
# position of the data feature used to sort lables
feature_index = find_nearest(700)
# here the sorting index
centroids_sorting_index = np.argsort(y[:, feature_index])
# here the sorting labels, not the index!!
@kidpixo
kidpixo / vimscratch.sh
Created March 15, 2023 12:45
Open a new vim file with syntaxt highlight set from cli. example : vimscratch python.
# open a new vim file with syntaxt highlight set at cli.
# example : vimscratch python
# default : open a new file directly skipping github.com/mhinz/vim-startify
alias vimscratch='_f() { if [ -z "$1" ]; then vim -c "let g:startify_disable_at_vimenter = 1"; else vim -c "let g:startify_disable_at_vimenter = 1" -c "set ft:$1" -c "set ft";fi }; _f'
@kidpixo
kidpixo / .gitconfig
Last active January 23, 2023 09:34
my .gitconfig
[core]
excludesfile = $HOME/.gitignore_global
editor = vim
# pager = delta
[filter "media"]
required = true
clean = git media clean %f
smudge = git media smudge %f
[push]
default = simple
@kidpixo
kidpixo / conda_update_all_envs.sh
Last active November 10, 2025 08:50
Update all conda enviroment, optionally using another executable like mamba and dry run option setting from cli.
# define CONDACOMMAND externally to overwrite this, I use conda or mamba
# default is to use mamba, a looooot faster
CONDACOMMAND=${1:-'mamba'}
# DRYRUNCONDACOMMAND : is set to anything, just print the commands
if [ -z $DRYRUNCONDACOMMAND ]
then
echo "DRYRUNCONDACOMMAND is unset, this is the real stuff"
DRYRUNCONDACOMMAND=''
else
@kidpixo
kidpixo / openback.sh
Last active July 12, 2022 09:13
small bash alias to open program from CLI and send to background
#!/bin/bash
alias open='xdg-open' # opening files with xdg-open on linux, on mac you don't need this.
# open 1 file and send the proces in background
function openback() {
if [ "$#" -lt 1 ]
then echo "openback : No input given"
else open $1 > /dev/null & disown
fi
}
@kidpixo
kidpixo / update_metakernel.py
Last active July 5, 2022 13:24
Write metakernel to custom location and update KERNELS. Optionally, create symlink to Kernels location.
# -*- coding: utf-8 -*-
"""This module contains code related to NAIF/SPICE.
"""
import pathlib
def update_metakernel(metakernel_path=pathlib.Path,
metakernel_version=None,
KPATH=None,
outdir=None,
symlink=None,
@kidpixo
kidpixo / link_to_tmp.sh
Last active June 28, 2022 20:07
quickly symlink current directory to /tmp/
@kidpixo
kidpixo / overload_division_dict.ipynb
Created June 16, 2022 12:10
extend python dict class to use overload division operator à la pathlib
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@kidpixo
kidpixo / extract_rpm.sh
Created May 6, 2022 09:57
rpm - yum install in user home for non-admins : unpack rpm and move executable, manpages etc to $USER home.
#!/bin/bash
# see : rpm - yum install in user home for non-admins
# http://unix.stackexchange.com/questions/61283/yum-install-in-user-home-for-non-admins
# Usage:
# 0. check your architecture
# uname -a
# Linux laser.pe.ba.dlr.de 3.10.0-514.21.1.el7.x86_64 #1 SMP Sat Apr 22 02:41:35 EDT 2017 x86_64 x86_64 x86_64 GNU/Linux
#
# 1. search a packet for your architecture.
# Example: gnu parallel for x86_64 architecture.