Skip to content

Instantly share code, notes, and snippets.

View jepio's full-sized avatar
🏠
Working from home

Jeremi Piotrowski jepio

🏠
Working from home
View GitHub Profile
@jepio
jepio / cputimer.h
Last active August 29, 2015 14:04
C/C++ structs for wall-clock timing code execution.
#ifndef __CPU_TIMER_H__
#define __CPU_TIMER_H__
#include <time.h>
struct CpuTimer {
struct timespec start;
struct timespec stop;
};

Inkscape Tips

Copy part of an object

  1. Draw a rectangle covering everything you want to copy
  2. Press Ctrl+A to select all objects
  3. Object > Clip > Set
  4. Only the parts that were covered will be left

Center objects on page

  1. Select all objects you want to center
@jepio
jepio / Makefile
Last active August 29, 2015 14:04
A C socket server and a Python socket client.
CFLAGS += -Wall -Wextra -g -std=gnu99
all: server
clean:
rm -f server
@jepio
jepio / 2d_arrays.c
Last active August 29, 2015 14:04
2D arrays in C (I always forget this)
// Static
int arr[3][5] = {0};
printf("%d\n", arr[2][4]);
// Dynamic noncontiguous
int i;
int **arr = (int **) malloc(sizeof(int*)*3);
for ( i = 0 ; i < 3 ; ++i )
arr[i] = (int *) malloc(sizeof(int)*5);
arr[2][4] = 0;
@jepio
jepio / Makefile
Last active August 29, 2015 14:04
A daemon to show notification if battery is low.
CC = gcc
NOTIFY += $(shell pkg-config --cflags --libs libnotify)
.PHONY: clean
battery_daemon: battery_daemon.c
$(CC) -o $@ $(NOTIFY) $(CFLAGS) $<
clean:
rm -rf battery_daemon
@jepio
jepio / pyroot-numpy.py
Last active April 14, 2018 22:20
Copy TGraph data to numpy array and back.
"""
Example of interfacing numpy to pyroot. Additionally, the great package
root_numpy implements interfaces between various pyroot objects and numpy
through a cython extension module.
"""
import numpy as np
import ROOT
data = ROOT.TGraph("filename")
# Create buffers
@jepio
jepio / progress_timer.py
Last active August 29, 2015 14:05
Printing an updating line of text to stdout.
"""Updating timer that shows progress."""
import time
i = 0
while i < 1:
print("Completed: {:6.2%}".format(i), end='\r', flush=True)
i += 1/10000 # update by 1 permil
time.sleep(1/1000) # 1 ms
print()
@jepio
jepio / flatten.py
Last active August 29, 2015 14:05
An advanced (kind of) generator example.
def flatten(iterable):
try:
if isinstance(iterable, (str, bytes)): # are recursively iterable
raise TypeError # could've just as well been yield iterable, then else is needed
for item in iterable:
yield from flatten(item)
## alternative (py2):
# for nested in flatten(item):
# yield nested
except TypeError:
@jepio
jepio / ring.erl
Last active August 29, 2015 14:05
A process chain that sends a message back to starting process.
-module(ring).
-export([start/2, listen/1]).
%% listen to pings and forward to Pid
listen(Pid) ->
receive
ping ->
Pid ! ping,
listen(Pid)
end.
import numpy as np
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit
from scipy.stats import norm
a = np.array([[1, 3, 5], [2, 4, 6]])
## keyword args can be in any order
xdata = np.array(a, order='F', dtype=np.float32, ndmin=3) # fortran data order
xdata.resize(6)
print xdata