Skip to content

Instantly share code, notes, and snippets.

# solution for:
# https://stackoverflow.com/questions/12544056/how-to-i-get-the-current-ipython-notebook-name
#
# aimed at:
# IPython 4.3.0
'''
Library for getting the name of a Jupyter notebook from within an IPython
kernel launched for the notebook.
Probably doesn't work on OS X.
Usage:
@yingted
yingted / waitiing_connections.sh
Last active August 29, 2015 14:05
heroku postgresql waiting connections
waiter_list() {
hk psql -a r101-cedar -c "SELECT * FROM pg_stat_activity WHERE extract(epoch from now() - xact_start) > 60 * 10 AND state = 'idle in transaction'"
}
waiter_cancel() {
hk psql -a r101-cedar -c "SELECT pid, pg_cancel_backend(pid) FROM pg_stat_activity WHERE extract(epoch from now() - xact_start) > 60 * 10 AND state = 'idle in transaction'"
}
waiter_terminate() {
hk psql -a r101-cedar -c "SELECT pid, pg_terminate_backend(pid) FROM pg_stat_activity WHERE extract(epoch from now() - xact_start) > 60 * 30 AND state = 'idle in transaction'"
@yingted
yingted / lyrics.user.js
Created November 18, 2013 20:48
lyrics for Astral Radio player
// ==UserScript==
// @name lyrics for Astral Radio player
// @description Check http://proxy.amri.ca/ or https://en.wikipedia.org/wiki/Bell_Media_Radio for a list
// @namespace localhost
// @include http://player.chumfm.com/
// @version 0.1
// @grant GM_xmlhttpRequest
// ==/UserScript==
addEventListener("load",function(){
@yingted
yingted / inline_equation_preview.user.js
Created November 18, 2013 20:46
UW MapleTA inline equation preview
// ==UserScript==
// @name Inline equation preview
// @namespace localhost
// @description Inline equation preview for MapleTA equation editor
// @include https://maple-ta.uwaterloo.ca/mapleta/modules/*
// @version 0.1
// @grant none
// @require http://userscripts.org/scripts/source/68059.user.js
// ==/UserScript==
@yingted
yingted / sync-intel-backlight.service
Created September 15, 2013 16:59
See sync-intel-backlight.sh. Belongs to /etc/systemd/system/sync-intel-backlight.service.
[Unit]
Description=Sync Intel backlight interface to ACPI
After=-.mount
[Service]
ExecStart=/usr/local/bin/sync-acpi-intel.sh
@yingted
yingted / joshua_kalpin.py
Created September 15, 2013 04:03
From UWaterloo Fall Orientation 2013 SCUNT
#!/usr/bin/python
from scipy.signal import *
from cv2 import *
from numpy import *
cap=VideoCapture(0)
cc=CascadeClassifier("/usr/share/OpenCV/haarcascades/haarcascade"
"_frontalface_default.xml")
face=imread("joshua_kalpin.png")
while cap.grab():
frame=cap.retrieve()[1]
@yingted
yingted / sync-acpi-intel.sh
Last active December 23, 2015 01:18 — forked from michel-slm/sync-acpi-intel.sh
Sync intel_backlight to acpi_video0 brightness using gamma.
#!/bin/sh
# Copyright (c) 2013, Ted Ying
# Permission is hereby granted, without written agreement and without
# license or royalty fees, to use, copy, modify, and distribute this
# software and its documentation for any purpose, provided that the
# above copyright notice and the following two paragraphs appear in
# all copies of this software.
#
# IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
# DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
@yingted
yingted / copy-clipboard-from-android.sh
Created September 14, 2013 05:43
Copy Android clipboard over ssh or adb to the local clipboard. Set login to -d or -e to force adb to only look for devices or emulators. See also copy-clipboard-to-android.sh.
#!/bin/sh
# Copies the Android clipboard to local X11 secondary buffer.
# Useful for debugging.
limit=33
delay=3000
login=my-android-ssh-name # ssh $login or adb $login shell should log you in
while getopts 't:h:q' opt
do
case $opt in
@yingted
yingted / copy-clipboard-to-android.sh
Created September 14, 2013 05:43
Copy the local clipboard to Android clipboard over ssh or adb. Set login to -d or -e to force adb to only look for devices or emulators. See also copy-clipboard-from-android.sh.
#!/bin/sh
# Copies local X11 secondary buffer to the Android clipboard.
# Useful for debugging.
delay=3000
login=my-android-ssh-name # ssh $login or adb $login shell should log you in
while getopts 't:q' opt
do
case $opt in
h)
@yingted
yingted / 50-autologin
Created September 14, 2013 04:37
Automatically log in to public WiFi and prevent tabs from being redirected.
#!/bin/sh
# place in /etc/NetworkManager/dispatcher.d/50-autologin
if [ "$1" = "wlan0" ]
then
case "$2" in
up)
case "$CONNECTION_ID" in
WirelessMississauga)
curl -so/dev/null --interface "$1" -m60 http://1.1.1.1/login.html -d buttonClicked=4;;
esac;;