Skip to content

Instantly share code, notes, and snippets.

View ssokolow's full-sized avatar

Stephan Sokolow ssokolow

View GitHub Profile
@ssokolow
ssokolow / snippet.sh
Created June 24, 2009 04:21 — forked from ches/snippet.sh
ches's github alias modified for Linux
# Bash alias to open Github page for project in current working directory.
# Will use the current active branch if it exists remotely, or falls back to master.
alias github='br=$(git branch --contains HEAD | sed -rn "s/^\* //p"); if ! git ls-remote . | grep -q -e "refs/remotes/.*/${br}"; then br="master"; fi; xdg-open $(git config -l | sed -rn "s%remote.origin.url=git(@|://)(github.com)(:|/)(.+/.+).git%https://\2/\4/tree/${br}%p")'
@ssokolow
ssokolow / saver_disabler.sh
Created June 25, 2009 02:56
xkill-style screensaver-disabling which won't leave it disabled by accident
#!/bin/sh
# A simple little script which prompts you to click a window and then disables
# the screensaver until it goes away.
WID=`xwininfo -int | awk '/Window id/ {print $4}'`
xdg-screensaver suspend "$WID"
@ssokolow
ssokolow / radiobuttons_with_none_selected.py
Created June 25, 2009 03:01
How to fake a gtk.RadioToolButton group where you can set all buttons inactive
# PyGTK doesn't let you set_active(False) on all radio buttons.
# You can work around that by adding a button to the group which will never
# be made visible to the user. (Don't add it to any window)
self.zoom_100 = self.wTree.get_widget("zoom_100")
self.zoom_fit = self.wTree.get_widget("zoom_fit")
self.zoom_manual = gtk.RadioToolButton(self.zoom_100)
@ssokolow
ssokolow / get_selection_html.coffee
Created June 25, 2009 03:09
How to get the current selection in HTML rather than plaintext
getSelectionHTML = ->
# Everyone but IE supports DOM selections
if window.getSelection
sel = window.getSelection()
# IE Selections (Must come last to avoid messing with Opera)
else if document.selection
return document.selection.createRange().htmlText
# Fail safely
else
return ""
@ssokolow
ssokolow / completer_entry.py
Created June 25, 2009 04:02
Modification of PyGTK's EntryCompletion example with shell-like tab completion.
#!/usr/bin/env python
"""Modification of PyGTK's EntryCompletion example with shell-like tab completion.
Tab works normally unless there's content, the cursor is at the end of it,
and nothing is selected, preserving intuitive tab-cycling behaviour in all
reasonable cases while still allowing comfortable tab completion.
(To tab-cycle into a field with content in it and then tab-complete, just press
End before you request completion)
If no completions are found, users may press Tab again to go to the next field.
@ssokolow
ssokolow / boilerplate.py
Last active January 8, 2022 17:43
Python boilerplate from which I start all my projects
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""[application description here]"""
__appname__ = "[application name here]"
__author__ = "Stephan Sokolow (deitarion/SSokolow)"
__version__ = "0.0pre0"
__license__ = "GNU GPL 3.0 or later"
import logging
@ssokolow
ssokolow / LCDd.conf
Created November 3, 2009 06:48
LCDd.conf for PCIDEA 20x4 USB LCD
[server]
Driver=CFontzPacket
## CrystalFontz packet driver (for CF631, CF633 & CF635) ##
[CFontzPacket]
# Select the LCD model [default: 633; legal: 631, 633, 635]
Model=631
# Select the output device to use [default: /dev/lcd]
Device=/dev/ttyUSB0
@ssokolow
ssokolow / pagination_example.sql
Created December 23, 2009 13:02
Reasonably efficient pagination without OFFSET (SQLite version)
-- Reasonably efficient pagination without OFFSET
-- SQLite version (Adapted from MS SQL syntax)
-- Source: http://www.phpbuilder.com/board/showpost.php?p=10376515&postcount=6
SELECT foo, bar, baz, quux FROM table
WHERE oid NOT IN ( SELECT oid FROM table
ORDER BY title ASC LIMIT 50 )
ORDER BY title ASC LIMIT 10
@ssokolow
ssokolow / background-page.html
Created June 29, 2010 03:59 — forked from romannurik/background-page.html
Simple cross-domain XHR boilerplate for Chrome extensions. Modified to be more useful for POST
<!DOCTYPE html>
<html>
<head>
<script src="xhrproxy.js"></script>
<script>
setupXHRProxy();
</script>
</head>
@ssokolow
ssokolow / distutils_command_template.py
Created July 28, 2010 19:34
Template for custom Distutils commands with dependencies
"""Template for custom Distutils commands with dependencies"""
from distutils.core import Command
commands = {}
try:
from third_party_package import something
class MyCommand(Command):
description = "Use ThirdPartyPackage™ to frob the project source"