Skip to content

Instantly share code, notes, and snippets.

View honno's full-sized avatar
🛰️

Matthew Barber honno

🛰️
  • Hexegic
  • Southend-on-Sea
  • 19:36 (UTC +01:00)
View GitHub Profile
@ma-ric
ma-ric / flatten.py
Created May 21, 2015 15:50
Python; recursive flatten of nested iterables, with proper handling of string elements
#!/usr/bin/env python3
def flatten(t):
"""
Generator flattening the structure
>>> list(flatten([2, [2, "test", (4, 5, [7], [2, [6, 2, 6, [6], 4]], 6)]]))
[2, 2, "test", 4, 5, 7, 2, 6, 2, 6, 6, 4, 6]
"""
from collections.abc import Iterable
@tebeka
tebeka / gist:5426211
Created April 20, 2013 14:43
Serving dynamic images with Pandas and matplotlib (using flask)
#!/usr/bin/env python2
'''Serving dynamic images with Pandas and matplotlib (using flask).'''
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from cStringIO import StringIO
@pouyatafti
pouyatafti / moomin.c
Last active August 18, 2020 11:27
Linux process Moomin ASCII art (via ps x)
#include <string.h>
#include <unistd.h>
char *moomin[] = {
" . ,",
"ASCII art (c) Maija Haavisto (@DiamonDie)",
"",
" \"._.' `' mh/VK",
" `. `, `. .'",
" . .' `. `' ;",
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@tonyfast
tonyfast / 2021-09-20-pandas-one-liner.ipynb
Created September 20, 2021 17:02
pandas one liner demonstrating apply pandas Series patterns
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@rhettinger
rhettinger / mymax10e.py
Created November 18, 2021 01:50
Type annotated pure python implementation of the builtin max() function
'Emulate max() as fully as possible in pure Python.'
# https://stackoverflow.com/questions/69997857/implementation-of-max-function-in-python/69997876#69997876
# https://github.com/python/mypy/issues/7231
from typing import TypeVar, Any, Iterator, Iterable, Optional
from typing import Union, Protocol, Callable, cast, Tuple, overload
class SupportsGT(Protocol):
@dweinstein
dweinstein / template.txt
Created September 5, 2012 20:42
my org-mode template for exporting to LaTeX/PDF
#+TITLE: Template org-mode document for export to LaTeX/PDF
#+AUTHOR: David Weinstein
#+LaTeX_HEADER: \usepackage[left=1in,top=1in,right=1in,bottom=1.5in]{geometry}
#+LaTeX_HEADER: \usepackage{palatino}
#+LaTeX_HEADER: \usepackage{fancyhdr}
#+LaTeX_HEADER: \usepackage{sectsty}
#+LaTeX_HEADER: \usepackage{engord}
#+LaTeX_HEADER: \usepackage{cite}
#+LaTeX_HEADER: \usepackage{graphicx}
@dannvix
dannvix / mydft.py
Last active April 21, 2023 16:19
Intuitive impementation of discrete Fourier transform (and inverse DFT) in Python (without numpy)
#!/usr/bin/env python3
import math
# >> Discrete Fourier transform for sampled signals
# x [in]: sampled signals, a list of magnitudes (real numbers)
# yr [out]: real parts of the sinusoids
# yi [out]: imaginary parts of the sinusoids
def dft(x):
N, yr, yi = len(x), [], []
@xero
xero / python-logo-ascii.txt
Created August 31, 2012 16:02
python logo ascii art
..:77I777777777777777777777I. .
..?77777777777777777777777777777$+..
. ~7777777I7777777777777777777777777$~..
.7I7777...7777777777777777777777777$7+.
.?7777.. ..77777777777777777777777$$7.
.77777 777777777777777777777$$$$$I
.77777.. ...7777777777777777777$$$$$$$$
.7777777 .77$777777777777777777$$$$$$$$
.77777777777777777777777777777$$$$$$$$$$
.77777777777777777777777777$$$$$$$$$$$$$
@alces
alces / sudo_env_vars.md
Last active July 21, 2023 09:21
How to change environment passed to sudo command

By default, sudo on the Linux systems executes commands into a minimal environment. So, if you for example has some non-standard directories (such as /opt/groovy/bin) added to your PATH, a command running via sudo won't see any executable in these directories.

Normally, this strict sudo behavior can be changed by removing env_reset (or changing env_keep) variables in /etc/sudoers. But what can you do in case when you have only restricted sudo without write access to this file?

The following command passes a current value of PATH under a command run with sudo privileges:

sudo bash -c "export $PATH; which groovy"