Skip to content

Instantly share code, notes, and snippets.

import json
import ast
import os
def get_functions_from_source(filepath):
"""
Parses a Python file and returns a list of functions with their line numbers.
Each item is a tuple: (function_name, start_line, end_line).
"""
functions = []
@alhoo
alhoo / logger.py
Last active March 6, 2025 07:06
Json logger
import json
import logging
import traceback
import sys
import pickle
import base64
from datetime import datetime, date, time, timedelta
class JSONEncoder(json.JSONEncoder):
def default(self, obj):
def print_traceback(e):
"""
Prints a formatted traceback of the given exception, including filename, line number, function name, code line,
and local variables for each frame in the traceback stack.
Args:
e (Exception): The exception object for which the traceback should be printed.
Returns:
None
<!DOCTYPE html>
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script>
<script src="https://rawgit.com/lmcnulty4/d3dragSelector/master/dragSelector.js"></script>
<style>
.selector {
fill: blue;
fill-opacity: 0.3;
stroke: blue;
import datetime
import json
def dateconverter(o):
if isinstance(o, datetime.datetime):
return o.__str__()
def json_dumps(data):
return json.dumps(data, default=dateconverter)
%%javascript
IPython.notebook.kernel.execute('nb_name = "' + IPython.notebook.notebook_name + '".replace(".ipynb", "")')
---
from IPython.core.display import display, HTML
display(HTML("<style>.container { width:100% !important; </style>"))
%matplotlib inline
from matplotlib import pyplot as plt
%pylab inline
@alhoo
alhoo / zshrc
Last active June 28, 2019 11:00
function json_double_escape () {
printf '%s' "$1"|python -c 'import json,sys,re; print(re.subn(r"\\", r"\\\\", json.dumps(sys.stdin.read(), ensure_ascii=False))[0])'
}
function command_exec_handler() {
STARTTIME=$(date --iso-8601=seconds)
SECONDS=0
eval $1;
EXIT_VALUE="$?"
CMD=$(json_double_escape $1)
@alhoo
alhoo / backups
Last active April 21, 2019 10:15
$ cat bin/backups.sh
#!/usr/bin/env bash
# sudo apt-get install rdiff-backup
BACKUPS="$HOME/backups"
rdiff-backup --exclude $BACKUPS \
--exclude $HOME/VirtualBox\ VMs \
--exclude $HOME/Downloads \
$HOME $BACKUPS
from IPython.core.display import display, HTML
display(HTML("<style>.container { width:100% !important; }</style>"))
%pylab inline
pylab.rcParams['figure.figsize'] = (20, 16)
from collections import Counter
from glob import glob
from datetime import datetime, timedelta
#!/usr/bin/env bash
N=30
DRYRUN=false
WORKDIR=/home/lasse/Desktop
HISTORY=__HISTORY
HISTORY_DIR=$WORKDIR/$HISTORY/$(date +%Y%m%d)
if [ "$1" != "" ]; then N=$1; fi