Skip to content

Instantly share code, notes, and snippets.

View akaihola's full-sized avatar
🌇
Working from home

Antti Kaihola akaihola

🌇
Working from home
  • Wärtsilä Oyj
  • Espoo, Finland
View GitHub Profile
@luochen1990
luochen1990 / venv-py37.nix
Last active March 29, 2024 12:18
Nix Script to simulate FHS environment with python3 & pip & venv
#!/usr/bin/env -S bash -c 'nix-shell --pure $0 -A env'
# Usage:
# 1. run directly to enter bash (inside venv): `./venv-py37.nix`
# 2. build a standalone executable: `nix bundle -f ./venv-py37.nix` #this not works yet since it cause nested `unshare -U` call
# 3. run bash with extra arguments: `nix run -f ./venv-py37.nix '' -- -c 'python --version'`
# More:
# 1. commit id of nixpkgs can be found here: https://lazamar.co.uk/nix-versions/?channel=nixpkgs-unstable&package=python3
let
@adisbladis
adisbladis / podman-shell.nix
Last active April 29, 2024 14:50
Use podman within a nix-shell
{ pkgs ? import <nixpkgs> {} }:
let
# To use this shell.nix on NixOS your user needs to be configured as such:
# users.extraUsers.adisbladis = {
# subUidRanges = [{ startUid = 100000; count = 65536; }];
# subGidRanges = [{ startGid = 100000; count = 65536; }];
# };
@bbarker
bbarker / PythonTyping.md
Created November 7, 2017 16:13
Using mypy in tests

The following test uses mypy to check the correctness of Python code using typing, largely introduced in 3.5 and 3.6. The two tests check all package code and all test code in the tests directory, respectively. Testing frameworks such as 'nose2' will automatically run the tests and will fail if any typing error is detected (see step #3 below for more on this).

Steps to use

  1. Add the file below to your tests directory, which should be at the top-level in your repository alongside your module directory.
  2. Modify the first line in __init__ that sets self.pkgname to match your library's package name. This assumes one package per repo, so the test would need to be changed if this isn't how the repo structure works.
@TimSC
TimSC / eertree.py
Last active February 9, 2023 01:12
Implementation of eertree, a palindromic tree in python.
#!/bin/python
#Based on: EERTREE: An Efficient Data Structure for Processing Palindromes in Strings
#by Mikhail Rubinchik and Arseny M. Shur https://arxiv.org/pdf/1506.04862.pdf
#Useful: https://medium.com/@alessiopiergiacomi/eertree-or-palindromic-tree-82453e75025b#.ofgt2r7xn
#Port of https://github.com/zimpha/algorithmic-library/blob/master/string-utility/eertree.cc
#to python by TimSC. zimpha kindly allowed me to release this code under the CC0 license.
from __future__ import print_function
@waylonflinn
waylonflinn / ipynb_output_filter.py
Last active May 25, 2018 17:45
Make ipython notebook files place nice with git. Remove output from notebooks when doing diffs and commits.
#! /usr/bin/env python
# this script filters output from ipython notebooks, for use in git repos
# http://stackoverflow.com/questions/18734739/using-ipython-notebooks-under-version-control
#
# put this file in a `bin` directory in your home directory, then run the following commands:
#
# chmod a+x ~/bin/ipynb_output_filter.py
# echo -e "*.ipynb \t filter=dropoutput_ipynb" >> ~/.gitattributes
# git config --global core.attributesfile ~/.gitattributes
# git config --global filter.dropoutput_ipynb.clean ~/bin/ipynb_output_filter.py
@vontrapp
vontrapp / punch.py
Last active December 22, 2015 22:29 — forked from jimparis/punch.py
#!/usr/bin/python
import ctypes
import ctypes.util
import os
import re
null_re = re.compile('^\0*$')
c_off_t = ctypes.c_int64
@wangtzINT
wangtzINT / core.py
Created March 9, 2012 21:28 — forked from kracekumar/core.py
parallelpip demo 中文版
#! -*- Coding: utf-8 -*-
from gevent import monkey
monkey.patch_all()
import gevent
import time
from envoy import run
from sys import exit, argv
import subprocess
import pip
@irae
irae / _Stay_standalone.md
Last active January 29, 2024 12:38 — forked from kylebarrow/example.html
Stay Standalone: Prevent links in standalone web apps opening Mobile Safari

#Stay Standalone

A short script to prevent internal links to a "webapp" added to iPhone home screen to open in Safari instead of navigating internally.