Skip to content

Instantly share code, notes, and snippets.

@tedheich
tedheich / twerminal.sh
Created October 21, 2009 13:11
Small script to send twitter updates from bash
#! /bin/sh
# Simple bash script to send Tweets using bash
# author: ted heich
# blog: http://www.kindawannadothat.com
user="type-your-twitter-username-here"
password="type-your-password-here"
echo "What are you doing right now? "
read message
@tedheich
tedheich / todosqlite-createdb.py
Created October 21, 2009 13:18
script to create the sqlite db for todo.py
#-*- coding: ISO-8859-1 -*-
# filename: todosqlite-createdb.py
# author: ted heich
#
# This program is the first part of the todosqlite app, this program handles
# the creation of the table. If todo.sqlite does not exist on the file system.
# Everytime you run this code, the table todo will be dropped and recreated--so be warned.
# it is created automatically.
#
@tedheich
tedheich / todosqlite.py
Created October 21, 2009 13:19
A simple command line todo list using SQLite and Python
#! /sw/bin/python
# filename: todosqlite.py
# author: ted heich
# blog: http://fornoobs.info
#
# A simple todo list app using Python and sqlite using the cmd line interface
#
#from pysqlite2 import dbapi2 as sqlite
import pysqlite2.dbapi2 as sqlite
@tedheich
tedheich / PythonMailer.py
Created October 22, 2009 08:21
Simple python snippet to send mail
# Send an HTML email with an embedded image and a plain text message for
# email clients that don't want to display the HTML.
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
from email.MIMEImage import MIMEImage
import smtplib
# Define these once; use them twice!
strFrom = 'ted@fornoobs.info' # Who is this email coming from
@tedheich
tedheich / Hello.h
Created October 23, 2009 05:40
Hello World in Objective C
// Hello.h
#import <Foundation/Foundation.h>
@interface Hello: NSObject {
}
- (void) sayhello ;
@end
@tedheich
tedheich / Hello.java
Created October 24, 2009 14:34
Simple Hello World in Java
class Hello {
void sayhello() {
System.out.println("Hello World\n");
}
}
class HelloMain {
public static void main(String []args) {
System.out.println("Hello World\n");
}
@tedheich
tedheich / DiskCheck.sh
Created October 26, 2009 05:42
How to check disk level in Linux and mail an alert
ADMIN="adminEmail@yourDomain.com"
# set alert-level 90 % standard
ALERT=10
df -h | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $6 }' | while read output;
do
usep=$(echo $output | awk '{ print $1}' | cut -d'%' -f1 )
partition=$(echo $output | awk '{ print $2 }' )
if [ $usep -ge $ALERT ]; then
echo "space low on \"$partition ($usep%)\", on server $(hostname) at $(date)" |
mail -s "Alert: Free space low, $usep % used on $partition" $ADMIN
@tedheich
tedheich / matrix-screensaver.sh
Created November 13, 2009 00:48
Matrix screen saver on the shell
# tr -c "[:digit:]" " " < /dev/urandom | dd cbs=$COLUMNS conv=lcase,unblock | GREP_COLOR="1;32" grep --color "[^ ]"
@tedheich
tedheich / search-for-term.sh
Created November 15, 2009 05:57
run a command as soon as it occurs in a log file
tail -f file.log | grep --line-buffered "search pattern" | while read line
do
echo $line
done
# the line --line-buffered is key here, the read will fail without it
@tedheich
tedheich / printlinenumber.py
Created November 15, 2009 10:41
Printing line numbers of a source file
import sys
counter = 0
for line in open(sys.argv[1],'r'):
counter = counter + 1
print counter, line,