Skip to content

Instantly share code, notes, and snippets.

@basilleaf
basilleaf / launch_project.scpt
Created January 19, 2013 01:01
Applescript opens a Chrome window, 2 terminals, and sublime, pointing where you say.
# open a website in Chrome (couldn't get FF to work)
set site to "http://127.0.0.1:8000/"
tell application "Google Chrome"
reopen
activate
tell window 1
make new tab with properties {URL:site}
end tell
end tell
@basilleaf
basilleaf / gist:4695874
Created February 2, 2013 02:43
Remove extraneous whitespace from multiline string
' '.join([s.strip() for s in my_str.splitlines()]).strip()
@basilleaf
basilleaf / gist:5615466
Last active December 17, 2015 13:10
blink test Raspberry Pi python RPi.GPIO
#!/usr/bin/python
# -*- coding: utf-8 -*-
import RPi.GPIO as GPIO
from time import sleep
pin = 13
blink_delay = 1.
GPIO.setup(pin, GPIO.OUT)
@basilleaf
basilleaf / gist:5621968
Last active December 17, 2015 14:09
look for files locally that do not have READ permission.
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
recursively crawls directory
if any file does not have READ permission
squawks to stdout
"""
import os
directory = '/path/to/directory/'
@basilleaf
basilleaf / gist:5835620
Last active December 18, 2015 19:49
post to wordpress from python
# pip install python-wordpress-xmlrpc
from wordpress_xmlrpc import Client, WordPressPost
from wordpress_xmlrpc.methods.posts import NewPost
from wordpress_xmlrpc.compat import xmlrpc_client
from wordpress_xmlrpc.methods import media, posts
def post_to_wordpress(title, content, more_info_url, local_img_file):
# first upload the image
@basilleaf
basilleaf / gist:5931540
Last active December 19, 2015 09:18
grab remote json resource in python
import json
import requests
url = ''
data = json.loads(requests.get(url).text)
import json
import urllib2
url = ''
f = urllib2.urlopen(url)
@basilleaf
basilleaf / gist:5946621
Created July 8, 2013 06:27
read of photocell light sensor triggers IR LED to emulate press of the #8 key on a Sony remote - to open Teleclaw at sunrise.
#include "IRremote.h"
IRsend irsend;
int LDR_threshold = 250; // this number or higher = sunshine, calibrate me!
int LDR_Pin = A0; // analog pin 0
int claw_state = 0; // claw is assumed initially closed for now..
void setup()
{
Serial.begin(9600);
@basilleaf
basilleaf / gist:6226869
Created August 14, 2013 00:02
fixing COUVIS ring_obs_ids in .TAB files
# fixing COUVIS ring_obs_ids in .TAB files
filename = 'ring/COUVIS_0012_ring_summary.tab'
new_filename = 'new/' + filename
new_file = open(new_filename, "w")
for l in open(filename).readlines():
fname = l.split(',')[1] # file spec name in field 1, quotes intact
ring_obs_id = l.split(',')[2][1:].strip('"').strip() # ring_obs_id in field 2 and strip out quotes and spaces
@basilleaf
basilleaf / gist:6245549
Created August 15, 2013 22:28
replace Windows/DOS line breaks (^M) with linux style line breaks
perl -pi -e 's/\015/\r\n/g' file.tab
# http://alextrle.blogspot.com/2011/05/how-to-send-sms-message-with-python.html
def sms_when_finished():
if gmail_pw:
server = smtplib.SMTP( "smtp.gmail.com", 587)
server.starttls()
server.login( 'YOUR_NAME@gmail.com',YOUR_GMAIL_PW)
server.sendmail('YOUR_NAME@gmail.com','YOUR_PHONE_NUMBER@vtext.com','Your Fabric job is finished!')