Skip to content

Instantly share code, notes, and snippets.

@clarksun
clarksun / debug_log_filter.py
Created December 22, 2017 09:30 — forked from bdarnell/debug_log_filter.py
Python logging filter for per-module debug logging
# A simple log filter to turn debug logging on and off on a per-module
# basis, when using tornado-style logging. Note that this works based
# on the module where the log statement occurs, not the name passed to
# logging.getLogger(), so it works even with libraries write directly
# to the root logger.
#
# One drawback to this approach (as opposed to using distinct
# per-module loggers and setting their levels appropriately) is that
# logger.isEnabledFor(DEBUG) will return true even when called from a
# module where debug output is not enabled, so modules that perform
@clarksun
clarksun / pastebin.lua
Last active January 11, 2018 00:47 — forked from tdlm/pastebin.lua
PasteBin shortcut for Hammerspoon
-- View your api_dev_key here: http://pastebin.com/api
local PASTEBIN_API_DEVELOPER_KEY = ""
-- Generate your api_user_key here: http://pastebin.com/api/api_user_key.html
local PASTEBIN_API_USER_KEY = ""
-- This makes a paste public or private, public = 0, unlisted = 1, private = 2
local PASTEBIN_API_PASTE_PRIVATE = "1"
--[[
@clarksun
clarksun / sentiment.py
Last active March 6, 2018 08:20 — forked from bbengfort/sentiment.py
An end-to-end demonstration of a Scikit-Learn SVM classifier trained on the positive and negative movie reviews corpus in NLTK.
import os
import time
import string
import pickle
from operator import itemgetter
from nltk.corpus import stopwords as sw
from nltk.corpus import wordnet as wn
from nltk import wordpunct_tokenize
@clarksun
clarksun / periodic.py
Created July 17, 2018 02:27 — forked from akaIDIOT/periodic.py
Call something periodically using asyncio
import asyncio
def call_periodic(interval, callback, *args, **kwargs):
# get loop as a kwarg or take the default one
loop = kwargs.get('loop') or asyncio.get_event_loop()
# record the loop's time when call_periodic was called
start = loop.time()
def run(handle):
@clarksun
clarksun / UploadDirS3.py
Created October 25, 2018 06:35 — forked from feelinc/UploadDirS3.py
Upload folder contents to AWS S3
#!/usr/bin/python
import os
import sys
import boto3
# get an access token, local (from) directory, and S3 (to) directory
# from the command-line
local_directory, bucket, destination = sys.argv[1:4]
@clarksun
clarksun / pex.md
Created November 24, 2018 09:43 — forked from simeonf/pex.md
Creating a PEX from a python script

So you want to create a pex that packages your script and its dependencies?

Ok - first to make our script! Call it foo.py:

import requests

if __name__ == '__main__':
  req = requests.get("https://raw.githubusercontent.com/pantsbuild/pex/master/README.rst")
  print req.text.split("\n")[0]
@clarksun
clarksun / GPG and git on macOS.md
Created June 6, 2019 06:58 — forked from danieleggert/GPG and git on macOS.md
How to set up git to use the GPG Suite

GPG and git on macOS

Setup

No need for homebrew or anything like that. Works with https://www.git-tower.com and the command line.

  1. Install https://gpgtools.org -- I'd suggest to do a customized install and deselect GPGMail.
  2. Create or import a key -- see below for https://keybase.io
  3. Run gpg --list-secret-keys and look for sec, use the key ID for the next step
  4. Configure git to use GPG -- replace the key with the one from gpg --list-secret-keys
@clarksun
clarksun / go-os-arch.md
Created August 2, 2019 01:19 — forked from asukakenji/0-go-os-arch.md
Go (Golang) GOOS and GOARCH

Go (Golang) GOOS and GOARCH

All of the following information is based on go version go1.8.3 darwin/amd64.

A list of valid GOOS values

(Bold = supported by go out of the box, ie. without the help of a C compiler, etc.)

  • android
  • darwin
@clarksun
clarksun / iterm2-recv-zmodem.sh
Created December 16, 2019 06:58 — forked from dalei2019/iterm2-recv-zmodem.sh
iterm2 recv zmodem clone from matthew@mastracci.com
#!/bin/bash
# Author: Matt Mastracci (matthew@mastracci.com)
# AppleScript from http://stackoverflow.com/questions/4309087/cancel-button-on-osascript-in-a-bash-script
# licensed under cc-wiki with attribution required
# Remainder of script public domain
osascript -e 'tell application "iTerm2" to version' > /dev/null 2>&1 && NAME=iTerm2 || NAME=iTerm
if [[ $NAME = "iTerm" ]]; then
FILE=$(osascript -e 'tell application "iTerm" to activate' -e 'tell application "iTerm" to set thefile to choose folder with prompt "Choose a folder to place received files in"' -e "do shell script (\"echo \"&(quoted form of POSIX path of thefile as Unicode text)&\"\")")
else
@clarksun
clarksun / iterm2-send-zmodem.sh
Created December 16, 2019 06:58 — forked from dalei2019/iterm2-send-zmodem.sh
iterm2 send zmodem clone from matthew@mastracci.com
#!/bin/bash
# Author: Matt Mastracci (matthew@mastracci.com)
# AppleScript from http://stackoverflow.com/questions/4309087/cancel-button-on-osascript-in-a-bash-script
# licensed under cc-wiki with attribution required
# Remainder of script public domain
osascript -e 'tell application "iTerm2" to version' > /dev/null 2>&1 && NAME=iTerm2 || NAME=iTerm
if [[ $NAME = "iTerm" ]]; then
FILE=`osascript -e 'tell application "iTerm" to activate' -e 'tell application "iTerm" to set thefile to choose file with prompt "Choose a file to send"' -e "do shell script (\"echo \"&(quoted form of POSIX path of thefile as Unicode text)&\"\")"`
else