Skip to content

Instantly share code, notes, and snippets.

View ricrogz's full-sized avatar

Ricardo Rodriguez ricrogz

View GitHub Profile
@ricrogz
ricrogz / .git_config
Last active June 14, 2020 20:59
Strip output of Jupyter notebooks on git add
[filter "strip_ipynb"]
clean = python3 strip_ipynb.py
@ricrogz
ricrogz / OpenSSL RSA encryption sample
Created October 27, 2019 05:19 — forked from superwills/OpenSSL RSA encryption sample
Base64 encoding and RSA encryption sample
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <openssl/rsa.h>
#include <openssl/engine.h>
#include <openssl/pem.h>
// I'm not using BIO for base64 encoding/decoding. It is difficult to use.
// Using superwills' Nibble And A Half instead
@ricrogz
ricrogz / _Very_big_int_in_cython.txt
Last active June 6, 2021 12:55
Use int128 (really LONG integers) in cython
Taken from https://stackoverflow.com/questions/27582001/how-to-use-128-bit-integers-in-cython
Basically, we make cython believe we will use 64 bit int to generate the .c file,
but by using a C header we will, in fact, define a 128 bit int (the definition
in the .h file does not match what we put into the pyx file).
Once Cython has generated the .c file, we can compile it with GCC without further trouble,
as GCC does support 128 bit ints
@ricrogz
ricrogz / py_real_obj_size.py
Last active October 14, 2017 23:14 — forked from bosswissam/pysize.py
Get Real size of objects in python
import sys
def get_size(obj, seen=None):
"""Recursively finds size of objects"""
size = sys.getsizeof(obj)
if seen is None:
seen = set()
obj_id = id(obj)
if obj_id in seen:
return 0
@ricrogz
ricrogz / timeout.sh
Last active April 15, 2017 09:31
Bash command timeout with warning on forced termination
# seen here: https://unix.stackexchange.com/questions/58304/is-there-a-way-to-call-a-command-with-a-set-time-limit-and-kill-it-when-that-tim
timeout() {
time=$1
# start the command in a subshell to avoid problem with pipes
# (spawn accepts one command)
command="/bin/sh -c \"$2\""
@ricrogz
ricrogz / smaller_primes.py
Last active March 25, 2017 12:02
Primes smaller than n
# Adapted from here: https://groups.google.com/forum/#!msg/comp.lang.python/dUOqrbnpKeI/LYzGiO0M8fEJ
def smaller_primes(n):
"""Given an integer n, compute a list of the primes <= n"""
if n < 2:
return []
sieve = list(range(3, n + 1, 2))
top = len(sieve)
@ricrogz
ricrogz / factorize.py
Last active March 25, 2017 11:51
Efficient factorization in python
# Seen here: http://stackoverflow.com/questions/16996217/prime-factorization-list
def factorize(n):
primfac = []
d = 2
while d*d <= n:
while (n % d) == 0:
primfac.append(d) # supposing you want multiple factors repeated
n //= d
@ricrogz
ricrogz / completion.py
Last active July 26, 2016 07:09
python: recursive command line completion
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
"""
USE UNDER YOUR OWN RESPONSIBILITY!!
IMPORTANT: options with sub-levels MUST end with spaces!!!
"""
@ricrogz
ricrogz / gist:2bc12679b7e881a457aaae216ef6d66e
Created April 19, 2016 07:50
Find the mean, min and max values in a column using awk
$ awk '{if(min==""){min=max=$1}; if($1>max) {max=$1}; if($1< min) {min=$1}; total+=$1; count+=1} END {print total/count, min, max}' FILE.DAT
@ricrogz
ricrogz / .screenrc
Last active August 29, 2015 14:25
Nice screen bottomline
#change the hardstatus settings to give an window list at the bottom of the
#screen, with the time and date and with the current window highlighted
startup_message off
hardstatus alwayslastline
#hardstatus string '%{= mK}%-Lw%{= KW}%50>%n%f* %t%{= mK}%+Lw%< %{= kG}%-=%D %d %M %Y %c:%s%{-}'
hardstatus string '%{gk}[ %{G}%H %{g}][%= %{wk}%?%-Lw%?%{=b kR}(%{W}%n*%f %t%?(%u)%?%{=b kR})%{= kw}%?%+Lw%?%?%= %{g}][%{Y}%l%{g}]%{=b C}[ %m/%d %c ]%{W}'
defscrollback 5000
autodetach on
idle 600 eval "screen cmatrix -f -o -u 10" "idle 0"