Skip to content

Instantly share code, notes, and snippets.

View joelhoro's full-sized avatar

Joel Horowitz joelhoro

  • New York
View GitHub Profile
@joelhoro
joelhoro / python.json
Created September 3, 2024 00:23
Python snippets
{
// Place your snippets for python here. Each snippet is defined under a snippet name and has a prefix, body and
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the
// same ids are connected.
// Example:
"Set pandas options": {
"prefix": "pdoptions",
"body": [
"import pandas as pd"
from colored import fg, bg, attr
white = bg('white') + " "
black = bg('black') + " "
blue = bg('blue') + " "
s = \
"""
wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww
wwwwwwwwwwwwwwwwwwwBBwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww
@joelhoro
joelhoro / runwithlogging.sh
Created June 28, 2020 19:27
Run file and redirect output to logfile w pid in its name
#!/bin/bash
basedir="/home/joel/processes/log"
export PYTHONUNBUFFERED=1
logfile=$(date +%H%M%S.%N)
oldname="$basedir/log-$logfile.log.tmp"
#echo "Old name: $oldname"&
@joelhoro
joelhoro / jupyter_javascript_snippet.js
Created January 30, 2020 04:04 — forked from craigsdennis/jupyter_javascript_snippet.js
Run Python code from JavaScript in a Jupyter notebook
// %%javascript
window.executePython = function(python) {
return new Promise((resolve, reject) => {
var callbacks = {
iopub: {
output: (data) => resolve(data.content.text.trim())
}
};
Jupyter.notebook.kernel.execute(`print(${python})`, callbacks);
});
@joelhoro
joelhoro / mongo_test.py
Created January 19, 2020 21:16
Insert data in mongo collection
from pymongo import MongoClient
client = MongoClient()
db = client['joel']
data = [
{'name': 'Joel', 'country': 'Belgium'},
{'name': 'Arnaud', 'country': 'Belgium'},
{'name': 'Robert', 'country': 'France'},
]
@joelhoro
joelhoro / logit.sh
Created January 18, 2020 15:58
Logit function in bash
ROOTPATH=/tmp
logit() {
local label=$1
shift
local filename="$ROOTPATH/$label-`date +%Y%m%d.%H%M%S`.log"
echo "Logging '$@' to $filename"
$@ > $filename
}
@joelhoro
joelhoro / pandas.py
Last active January 4, 2023 10:29
Pandas dataframe with bootstrap styling
#!/usr/bin/env python
# coding: utf-8
# In[1]:
data = [
{"name": "Argentina", "year": 2005, "continent": "South America", "form": "Republic", "gdp": 181.357, "oil": 1.545, "balance": 4.699},
{"name": "Argentina", "year": 2006, "continent": "South America", "form": "Republic", "gdp": 212.507, "oil": 1.732, "balance": 7.167},
{"name": "Australia", "year": 2012, "continent": "Australasia", "form": "Constitutional monarchy", "gdp": 1542.055, "oil": 22.596, "balance": -62.969},
from email.message import Message
from email.generator import Generator
from email import generator
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
from email import encoders
import os
class MimeMessage():