Skip to content

Instantly share code, notes, and snippets.

View jamesadney's full-sized avatar

James Adney jamesadney

View GitHub Profile
package main
/*
http://play.golang.org/p/3YP3gdwpFG
*/
import "fmt"
func main() {
s := "This is a string."
@jamesadney
jamesadney / ppastats.py
Created May 2, 2012 17:18
Launchpad PPA usage statistics
#!/usr/bin/python
#usage python ppastats.py PPATEAM (ex: webupd8team) PPA (ex: gthumb) DIST (Ubuntu version eg maverick) ARCH (ubuntu arch eg i386 or amd64)
#http://www.webupd8.org/2010/12/launchpad-finally-gets-ppa-usage-stats.html
#example - highest downloaded file: python ppastats.py webupd8team y-ppa-manager maverick amd64 | tr '\t' ',' | cut -d ',' -f3 | sort -gr
import sys
from launchpadlib.launchpad import Launchpad
PPAOWNER = sys.argv[1]
@jamesadney
jamesadney / compact_django.py
Created May 1, 2012 19:49
Remove whitespace from rendered Django templates
import re
REMOVE_PATTERN = re.compile(r'\n\s*\{')
def compact(django_temp):
with open(django_temp) as f:
text = f.read()
compacted = re.sub(REMOVE_PATTERN, r'{', text)
return compacted
@jamesadney
jamesadney / hdparm_fix.rst
Created April 24, 2012 19:39
Prevent hard drive from constantly spinning down on battery (Ubuntu)

Add the following to /etc/hdparm.conf:

apm_battery = 128
@jamesadney
jamesadney / create-launcher.sh
Created April 9, 2012 21:27
Add "Create New Launcher" shortcut to nautilus context menu
#!/bin/bash
# 1. Install nautilus-actions and create a new action
# 2. Under "Command" tab: "Path" -> "create-launcher.sh" and "Parameters" -> "%f"
# 3. Copy create-launcher.sh to somewhere in $PATH and make executable
# For some reason the desktop gets sent to nautilus actions as "/", so just make launcher go to desktop
# if the current user doesn't own the location sent to the script.
if [ -O $1 ]; then
PATHNAME=$1
@jamesadney
jamesadney / hide_launcher.sh
Created March 13, 2012 18:18
Hide Ubuntu Unity launcher when window is maximized
#!/bin/bash
# Install wmctrl before using: sudo apt-get install wmctrl
# From http://ubuntuforums.org/showthread.php?p=11761683
# User settings
sleep 8 # Time it takes before script starts with autodetection
DELAY="2" # Set delay
# End of user settings
@jamesadney
jamesadney / pyglet_alpha_mask.py
Created March 5, 2012 01:17
Texture with alpha mask in Pyglet
import pyglet
from pyglet.gl import *
window = pyglet.window.Window()
image = pyglet.image.load('circle.png')
mask = pyglet.image.load('mask.png')
texture = pyglet.image.Texture.create(200, 200)
done = False
@jamesadney
jamesadney / pil_to_pyglet.py
Created March 4, 2012 08:28
Load pyglet image from PIL
temp_image = Image.open("picture.png")
raw_image = temp_image.tostring()
image = pyglet.image.ImageData(width, height, 'RGB', raw_image, pitch= -resized_x * 3)
@jamesadney
jamesadney / fix_pulse.rst
Created February 24, 2012 22:32
How to fix pulseaudio unamplified != 0% problem
  1. Copy pulseaudio configuration template to home folder. :

    cp /etc/pulse/default.pa ~/.pulse/default.pa
  2. Append ignore_dB=1 to line with load-module module-udev-detect.
  3. Make sure "speaker" volume is at 100% using alsamixer (press F6 and select HDA NVidia to see more volume controls.
  4. To make "speaker" volume persist between boots, run alsactl store -f ~/.asoundrc then make alsactl restore -f ~/.asoundrc start when logging into your user. (See Arch Wiki - ALSA)
@jamesadney
jamesadney / idle.py
Created February 22, 2012 06:43 — forked from tcurvelo/energysaver.py
idle time on windows
#!/usr/bin/env python
from ctypes import Structure, windll, c_uint, sizeof, byref
import time
class LASTINPUTINFO(Structure):
_fields_ = [
('cbSize', c_uint),
('dwTime', c_uint),
]