Skip to content

Instantly share code, notes, and snippets.

@geberl
geberl / alfred_unmount_media.applescript
Last active November 4, 2015 21:30
Alfred AppleScript to unmount a drive based on its name.
on alfred_script()
tell application "Finder"
eject disk "media"
end tell
end alfred_script
@geberl
geberl / alfred_mount_samba_location.applescript
Last active November 4, 2015 21:29
Alfred AppleScript to mount a samba location as a drive.
on alfred_script()
tell application "Finder"
open location "smb://192.168.1.101/media"
end tell
end alfred_script
@geberl
geberl / alfred_toggle_hidden_files.applescript
Last active November 4, 2015 21:32
Alfred AppleScript to toggle showing hidden files in OS X. Script from workflow https://github.com/shrop/alfred2-hidden-files.
on alfred_script(q)
set v to do shell script "echo $(defaults read com.apple.finder AppleShowAllFiles)"
if v is "True" then
do shell script "defaults write com.apple.finder AppleShowAllFiles FALSE"
else
do shell script "defaults write com.apple.finder AppleShowAllFiles TRUE"
end if
do shell script "killall Finder"
tell application "System Events" to set frontmost of process "Finder" to true
end alfred_script
@geberl
geberl / regex_neg_lookbehind.swift
Created January 4, 2018 08:13
Finding unescaped spaces in path strings via Regular Expression negative look-behind
//: Playground - noun: a place where people can play
import Foundation
var path = "/abc/def ghi/jkg\\ lmn/opq"
let reEscapedSpaces = "^.*\\\\ .*$" // simple
let reUnescapedSpaces = "^.*(?<!\\\\) .*$". // negative look-behind
if path.range(of: reUnescapedSpaces, options: .regularExpression) != nil {
@geberl
geberl / radar_chart.py
Created September 21, 2018 09:58
A 12-axis radar chart in Python (conda/miniconda) via numpy/pandas/matplotlib
#!/usr/bin/python
"""
Installation: Get the *Miniconda* Python Distribution - not the Python distrubution from python.org!
- https://conda.io/miniconda.html
Then install modules:
- `cd ~/miniconda3/bin`
- `./conda install numpy pandas matplotlib`
@geberl
geberl / header_check.py
Created September 21, 2018 11:02
Get all HTTP headers sent by a host at some port over http/https
#!/usr/local/bin/python3
import http.client
def get_all_headers(host, port, url, connection='https'):
"""
This can be used to test if your web server leaks any info it should rather keep for itself
Examples:
@geberl
geberl / CountryFlag.jsx
Created November 8, 2018 13:48
React component to get the unicode flag character for a country code; doesn't work on Windows because the flag symbols are missing there
import React from "react"
export default class CountryFlag extends React.PureComponent {
constructor(props) {
super(props)
this.state = {
countryCode: props.countryCode ? props.countryCode : "???",
fontSize: props.fontSize ? props.fontSize : 24
}
@geberl
geberl / github_api_example.py
Created February 7, 2019 12:55
Query the GitHub API via the github3 Python module for repo info, own user info, other user info
#! /usr/bin/python
# -*- coding: utf-8 -*-
from github3 import login
# https://github3.readthedocs.io/en/latest/index.html#more-examples
def enter_2fa_code():
# Source: https://github3.readthedocs.io/en/latest/examples/two_factor_auth.html
#! /usr/bin/python3
# -*- coding: utf-8 -*-
import datetime
import json
from urllib.parse import urlencode
from urllib.request import Request, urlopen
class DockerImageInfo(object):
#! /usr/bin/python
# -*- coding: utf-8 -*-
"""
Documentation:
- Docker Engine API: https://docs.docker.com/develop/sdk/
- Docker SDK for Python: https://docker-py.readthedocs.io/en/stable/
"""
import docker