Skip to content

Instantly share code, notes, and snippets.

View floer32's full-sized avatar

Michael Floering floer32

  • 16:18 (UTC -07:00)
View GitHub Profile
@floer32
floer32 / stash_dropped.md
Last active October 9, 2019 23:00 — forked from joseluisq/stash_dropped.md
How to recover a dropped stash in Git?

How to recover a dropped stash in Git?

1. Find the stash commits:

git log --graph --oneline --decorate $( git fsck --no-reflog | awk '/dangling commit/ {print $3}' )

This will show you all the commits at the tips of your commit graph which are no longer referenced from any branch or tag – every lost commit, including every stash commit you’ve ever created, will be somewhere in that graph.

@floer32
floer32 / python_test_impact_analysis.md
Last active March 28, 2019 21:40
Note on Python TIA (Test Impact Analysis)

Question:

What could I try for doing Test Impact Analysis for Python projects?

Answer:

There are a few libraries out there you could try. Here are some entrypoints:

@floer32
floer32 / _preserve_ipython_history_TLDR.diff
Last active April 18, 2019 17:41
preserve ipython history between docker-compose runs (for local/development usage). diff is only approximately two lines
diff --git a/local.yml b/local.yml
index b587373..73684bf 100644
--- a/local.yml
+++ b/local.yml
@@ -3,6 +3,7 @@ version: '2'
volumes:
#...
+ ipython_data_local: {}
services:
@floer32
floer32 / owasp-risk-rating.html
Created September 20, 2017 15:13 — forked from ErosLever/owasp-risk-rating.html
This is a quick and dirty OWASP Risk Rating Calculator. (demo: https://tinyurl.com/OwaspCalc )
<!-- access this at: https://cdn.rawgit.com/ErosLever/f72bc0750af4d2e75c3a/raw/owasp-risk-rating.html -->
<html><head>
<style>
#main{
width: 1200px;
}
table {
width: 98%;
font-size: small;
text-align: center;
@floer32
floer32 / docstring_for_tests.py
Last active September 21, 2019 21:12
simple HOWTO docstring to paste at top of test packages/modules, i.e. on teams less familiar with pytest
""" Tests for `foo` package.
uses pytest. pytest resources:
* Docs: https://docs.pytest.org/en/latest/
* Book! https://pragprog.com/book/bopytest/python-testing-with-pytest
also uses `responses`, for mocking HTTP exchanges with `requests` library:
* https://github.com/getsentry/responses
@floer32
floer32 / remove_punc.py
Last active September 21, 2019 21:12 — forked from kissgyorgy/remove_punc.py
Python: Remove punctuation from string (quickly)
#http://stackoverflow.com/questions/265960/best-way-to-strip-punctuation-from-a-string-in-python
import re, string
table = string.maketrans("","")
regex = re.compile('[%s]' % re.escape(string.punctuation))
def test_re(s): # From Vinko's solution, with fix.
return regex.sub('', s)
def test_trans(s):
@floer32
floer32 / SanitizedString.py
Last active September 6, 2017 17:53
(OLD; newer version is here: https://github.com/hangtwenty/presswork/blob/master/presswork/text/clean.py ) I wanted to "ensure" strings had been sanitized (avoid running redundantly). This is ONLY ONE type of sanitization, removing control chars (BESIDES NEWLINES), because that is what my current project needed. But I thought the design could be…
""" throw your strings to SanitizedString and "ensure" they have been sanitized, such as removing control characters.
SanitizedString will avoid running redundantly, by checking type of the input (good for Very Big Strings)
>>> hello = SanitizedString(chr(0) + "hello")
>>> assert hello == "hello"
>>> assert chr(0) not in hello
>>> assert SanitizedString(hello) == hello
at time of writing there is only one sanitization filter in use:
@floer32
floer32 / _fix_pip_import_error.md
Last active June 24, 2022 10:44
fix that pesky "ImportError: No module named packaging.version" problem. Or more generally, if you need to fix pip using pip, just make sure you do "python -m pip" instead of straight-up "pip".

It can come up while installing anything really. I'm not sure exactly which versions of pip are affected, I know I had 1.5.6 and it was affected.

These examples are grabbed from my system level Python, but of course you should use a virtualenv.

  Running setup.py install for simplegeneric
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/Library/Python/2.7/site-packages/setuptools/__init__.py", line 12, in <module>
        import setuptools.version
@floer32
floer32 / sonarqube and gradle and analysis mode.md
Last active March 22, 2018 16:52
little note regarding sonarqube and gradle

SonarQube not "uploading"? Be careful about sonar.analysis.mode=issues (or, if using Gradle, systemProp.sonar.analysis.mode=issues). This analysis mode seems required for some purposes (some plugins maybe?), but it was making Gradle not generate the report or upload it to SonarQube server. I haven't figured out the details yet but I wanted to leave this memo...

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>colorPalette</key>
<dict>
<key>ArchiveExpectationsBarBottomColor</key>
<dict>
<key>a</key>
<real>0.20000000000000001</real>