Skip to content

Instantly share code, notes, and snippets.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
#!/usr/bin/python
"""
Copyright (c) 2009 Simeon Franklin
MIT Licensed: see http://www.opensource.org/licenses/mit-license.php
pydelatt.py - Strips attachments from maildir format mail
files. Sample usage:
$ find ./Maildir -mtime +120 -size +3M | xargs -ix pydelatt.py -v 'x'
>>> def outer():
... x = 1
... def inner():
... print x
... return inner # inner hasn't run yet
>>> f = outer() # f is inner now, but no print statement has run
>>> f()
1
@simeonf
simeonf / snippet.py
Created May 9, 2016 18:08
First cell in my IPython Notebook to add hidden cells with a "Show" button.
# hideme
import IPython.core.display as di
di.display_html("""<script>$(function() {
$("div.code_cell:contains('hideme')").hide();
$("div.code_cell:contains('showme')").hide();
$(".showme").remove();
$("div.code_cell:contains('showme')").before('<button class="showme">Show Answer</button>');
$(".showme").click(function(){$(this).next().show();});
"""
Open a .csv of article listings and print a .csv of article listings including url.
Sample .csv content:
"Slain with Ax and Pistol", San Francisco Call, May 28, 1896, 1.
Sample run:
$ python3 article.py article.csv
@simeonf
simeonf / pex.md
Last active July 5, 2024 06:19
Creating a PEX from a python script

So you want to create a pex that packages your script and its dependencies?

Ok - first to make our script! Call it foo.py:

import requests

if __name__ == '__main__':
  req = requests.get("https://raw.githubusercontent.com/pantsbuild/pex/master/README.rst")
  print req.text.split("\n")[0]
@simeonf
simeonf / example.py
Created January 23, 2025 07:41
Script with inline dependencies
# /// script
# dependencies = [
# "rich",
# ]
# ///
from rich import print
print("Hello, [bold magenta]World[/bold magenta]!", ":vampire:", locals())
@simeonf
simeonf / menu.txt
Created April 16, 2025 02:02
ChatGPT breakfast cafe
ChatGPT Breakfast Cafe Menu
Sunrise Scramble
Fluffy scrambled eggs with diced ham, cheddar cheese, and fresh herbs, served with crispy hash browns. $8
Buttermilk Pancakes
Three fluffy buttermilk pancakes served with your choice of toppings: maple syrup, berries, or chocolate chips. $6
Avocado Toast
Sourdough toast topped with smashed avocado, cherry tomatoes, feta cheese, and a sprinkle of everything bagel seasoning. $9
Classic Breakfast Burrito
A warm flour tortilla filled with scrambled eggs, crispy bacon, cheddar cheese, and salsa, served with a side of sour cream and salsa verde. $10