Skip to content

Instantly share code, notes, and snippets.

@phagenlocher
phagenlocher / lazy.py
Last active March 6, 2024 13:59
Lazy Evaluation in Python (https://youtu.be/KniIeHiEzdo)
class Lazy:
def __init__(self, fun, *args, **kwargs):
self.fun = fun
self.args = args
self.kwargs = kwargs
self.executed = False
self.value = None
# Binary Operators
def __binary__(self, binfun, other):
@iexa
iexa / python-with-tcl.rb
Last active October 22, 2024 12:40
MacOS homebrew python 3.8.6 with tcl-tk (properly)
class Python < Formula
desc "Interpreted, interactive, object-oriented programming language"
homepage "https://www.python.org/"
url "https://www.python.org/ftp/python/3.8.6/Python-3.8.6.tar.xz"
sha256 "a9e0b79d27aa056eb9cce8d63a427b5f9bab1465dee3f942dcfdb25a82f4ab8a"
head "https://github.com/python/cpython.git"
license "Python-2.0"
revision 1
bottle do
@jnolis
jnolis / app.R
Last active August 20, 2019 01:28
Code for the my-classroom Shiny app
library(shiny)
library(dplyr)
library(ggplot2)
library(babynames)
size <- 25
colors <- c("F" = "#DE94AF", "M" = "#6C939F", "X" = "#D4C62A")
ui <- fluidPage(
@nijicha
nijicha / install_nodejs_and_yarn_homebrew.md
Last active July 25, 2025 09:02
Install NVM, Node.js, Yarn via Homebrew
@jakesherman
jakesherman / try_except.py
Created September 10, 2017 12:27
Try/except decorator in Python
def try_except(func):
"""Try/Except decorator - takes as input a function, and outputs
a modified version of that function whose first argument is how
many times you want to re-run the function if any exception is
raised.
"""
def try_except_function(num_tries, *args, **kwargs):
"""Modified version of func - see docstring for try_except().
"""
for i in range(num_tries):
@ululh
ululh / LDApredict.py
Last active February 1, 2023 09:32
LDA (Latent Dirichlet Allocation) predicting with python scikit-learn
# derived from http://scikit-learn.org/stable/auto_examples/applications/topics_extraction_with_nmf_lda.html
# explanations are located there : https://www.linkedin.com/pulse/dissociating-training-predicting-latent-dirichlet-lucien-tardres
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.decomposition import LatentDirichletAllocation
import pickle
# create a blank model
lda = LatentDirichletAllocation()
@pocin
pocin / .zshrc
Last active April 22, 2024 15:54
Use conda+pyenv to manage python
# $ brew install pyenv #pay attention to caveats ($ brew info pyenv)
# $ brew install pyenv-virtualenv
# this goes into .zshrc
export PYENV_ROOT=/usr/local/var/pyenv
if which pyenv > /dev/null; then eval "$(pyenv init -)"; fi
if which pyenv-virtualenv-init > /dev/null; then eval "$(pyenv virtualenv-init -)"; fi
@mpneuried
mpneuried / Makefile
Last active August 29, 2025 08:17
Simple Makefile to build, run, tag and publish a docker containier to AWS-ECR
# import config.
# You can change the default config with `make cnf="config_special.env" build`
cnf ?= config.env
include $(cnf)
export $(shell sed 's/=.*//' $(cnf))
# import deploy config
# You can change the default deploy config with `make cnf="deploy_special.env" release`
dpl ?= deploy.env
include $(dpl)
@chew-z
chew-z / .zshrc
Created August 27, 2016 09:54
Lazy loading virtualenv in zsh
# virtualenvwrapper
# lazy loading saves on shell startup time
workon() {
[ -z "$PROJECT_HOME" ] && {
unset -f workon;
export WORKON_HOME=$HOME/.virtualenvs;
export PROJECT_HOME=$HOME/Documents/Python;
source /usr/local/bin/virtualenvwrapper.sh
}
workon "$@"
@lckarssen
lckarssen / git-log-to-tikz.rb
Last active December 17, 2022 22:08 — forked from hauspie/git-log-to-tikz.rb
Extract git history to tikz picture
#!/usr/bin/env ruby
# A small ruby script to extract a git history to a tikz picture
# Author: Michael Hauspie <Michael.Hauspie@lifl.fr>
# Author: Lennart C. Karssen <lennart@karssen.org>
#
# Not clean code, not always working well, but does its job in most of
# the cases I needed :)
#
# LCK: Added some ideas from this tex.stackexchange answer: