Skip to content

Instantly share code, notes, and snippets.

@mkows
mkows / git-extract-dir-notes.sh
Last active Sep 29, 2021
git - extract a directory into a separate repository
View git-extract-dir-notes.sh
# using:
# - git filter-branch OR
# - git filter-repo
# extract folder into a new repo
git clone git@github.com:__ORG__/__PROJECT__.git __LOCAL_ALIAS_DIR__
cd __LOCAL_ALIAS_DIR__
git co -b main
@mkows
mkows / gist:60203538829f52f43834940c19f492f4
Created Oct 30, 2020
Handle jsonc (json with comments) with jq
View gist:60203538829f52f43834940c19f492f4
# brew install jsmin
cat file-with-comments.jsonc | jsmin | jq 'keys'
@mkows
mkows / kill-8080
Last active Oct 13, 2020
Kill process on port (8080)
View kill-8080
PROCESS_PHRASE="*:8080 (LISTEN)"
PROCESS_LINE=`lsof -Pn | grep "$PROCESS_PHRASE"`
if [[ -n $PROCESS_LINE ]]; then
PROCESS_ID=`awk '{print $2}' <<< $PROCESS_LINE`
echo "Killing process id=$PROCESS_ID ('$PROCESS_LINE')"
else
echo "No matching process found for '$PROCESS_PHRASE'"
fi
@mkows
mkows / py-on-mac.md
Last active Jul 6, 2021
Using python3 on MacOS
View py-on-mac.md

Prioritize Homebrew's python3 over default MacOS python2:

export PATH="/usr/local/opt/python/libexec/bin:$PATH"

Install python3 with Homebrew:

brew install python
@mkows
mkows / server-cors.py
Created Jul 31, 2019
Allow CORS with python Simple HTTP Server – for Python 3
View server-cors.py
'''
Based on https://gist.github.com/enjalot/2904124 (in Python 2) -> quick-migrated to Python 3
Usage: python server-cors
'''
import http.server as httpserver
class CORSHTTPRequestHandler(httpserver.SimpleHTTPRequestHandler):
def send_head(self):
"""Common code for GET and HEAD commands.
@mkows
mkows / macos-random.md
Created Apr 11, 2019
MacOS random notes
View macos-random.md

dyld: Library not loaded

Problem

When running tig

$ tig
dyld: Library not loaded: /usr/local/opt/readline/lib/libreadline.7.dylib
  Referenced from: /usr/local/bin/tig
  Reason: image not found
View gist:d6a6726b1cbea64574746366290506ce
echo '{"yo":"boo", "so":"no"}' | python -m json.tool
{
"so": "no",
"yo": "boo"
}
@mkows
mkows / load-resource.scala
Created Nov 5, 2018 — forked from banjeremy/load-resource.scala
scala: load files from resources directory
View load-resource.scala
def loadResource(filename: String) = {
val source = scala.io.Source.fromURL(getClass.getResource(filename))
try source.mkString finally source.close()
}
@mkows
mkows / init-git.sh
Created Jun 22, 2018
Initialize git repository in a current dir (with .gitignore, README.md)
View init-git.sh
#!/bin/bash
# Usage: ./init-git.sh
# NOTE: Run within your project directory
# .gitignore
cat > .gitignore << EOF
target/
.DS_Store
.idea
.idea_modules
@mkows
mkows / .travis.yml
Created Dec 18, 2017
TravisCI: Specify custom MongoDB version
View .travis.yml
# e.g. for MongoDB 2.6
#
# Follows MongoDB for Ubuntu installation https://docs.mongodb.com/v2.6/tutorial/install-mongodb-on-ubuntu/
# note: `--allow-downgrades` flag for apt-get install may be required
language: scala
scala: 2.11.11
jdk: openjdk8