Skip to content

Instantly share code, notes, and snippets.

View robertgreiner's full-sized avatar

Robert Greiner robertgreiner

View GitHub Profile
@robertgreiner
robertgreiner / git_history.rb
Created September 2, 2011 22:25
Get information about the number of production lines of code and test lines of code added for a git or svn checkin
class GitHistory
attr_reader :test_lines_of_code, :production_lines_of_code, :current_commit_id, :previous_commit_id, :diff, :has_java_or_test_code
def initialize(commit_id = nil)
@commit_id= commit_id unless commit_id.nil?
if commit_id.nil?:
getLatestCommit
end
@has_java_or_test_code = false
@robertgreiner
robertgreiner / SumNumbers.cs
Created December 15, 2011 15:59
Use LINQ to perform calculations
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace LINQSum
{
public class SumNumbers
{
private int[] numberList = {1, 2, 4, 8, 16, 32};
@robertgreiner
robertgreiner / spellcheck.py
Created December 28, 2011 03:19
Peter Norvig's spell check example
import re, collections
def words(text): return re.findall('[a-z]+', text.lower())
def train(features):
model = collections.defaultdict(lambda: 1)
for f in features:
model[f] += 1
return model
@robertgreiner
robertgreiner / FileWatcher.cs
Created December 28, 2011 12:57
Monitor a directory for changes
using System;
using System.Text;
using System.IO;
namespace FolderWatcher {
class Watcher {
static void Main(string[] args) {
FileSystemWatcher watcher = new FileSystemWatcher(@"D:\test");
watcher.IncludeSubdirectories = true;
watcher.Filter = "";
@robertgreiner
robertgreiner / Time.cs
Created December 28, 2011 18:35
An example of how to work with custom time strings in C#
//locale information
CultureInfo provider = CultureInfo.InvariantCulture;
//The timestamp from the external file
string dateString = "Dec 07 01:32:25 2009";
//the new format
string format = "MMM dd HH':'mm':'ss yyyy";
//Convert the time string into a legitimate DateTime object
@robertgreiner
robertgreiner / Web.config
Created December 28, 2011 18:45
Web.config for sending email using ASP
<system.net>
<mailSettings>
<smtp>
<network defaultCredentials="false"
host="mail.yourdomain.com" port="25"
userName="name-to-send-email@yourdomain.com"
password="*****"/>
</smtp>
</mailSettings>
</system.net>
@robertgreiner
robertgreiner / SendMail.cs
Created December 28, 2011 18:45
Send some email using C#
/* using System.Net.Mail; */
MailMessage newMail = new MailMessage();
newMail.To.Add(toAddress);
newMail.Subject = subject;
newMail.Body = body;
newMail.From = new MailAddress(fromAddress, name);
newMail.IsBodyHtml = true;
SmtpClient SmtpSender = new SmtpClient();
SmtpSender.Port = 25; //or, whatever port your SMTP server operates on
@robertgreiner
robertgreiner / debug.cs
Created December 28, 2011 18:51
conditionally execute debug code
/* using System.Diagnostics; */
[Conditional("DEBUG")]
public void printDebug() {
Console.WriteLine("Debug Information");
}
@robertgreiner
robertgreiner / RandomRoll.java
Created December 28, 2011 19:01
Roll a die
package RandomRoll;
import java.util.Random;
public class RandomRoll extends Thread {
private boolean running = true;
public RandomRoll() {
super("RandomRoll thread");
@robertgreiner
robertgreiner / bundle.manifest
Created December 28, 2011 19:00
The manifest file for Knopflerfish
Manifest-Version: 1.0
Bundle-Name: RandomRoll
Bundle-Description: Roll a die every second
Bundle-Activator: RandomRoll.Activator
Import-Package: org.osgi.framework
Bundle-Vendor: Tutorial
Bundle-ManifestVersion: 2
Bundle-SymbolicName: RandomRoll
Bundle-Version: 1.0.0