Skip to content

Instantly share code, notes, and snippets.

View JamesSwift's full-sized avatar

James Swift JamesSwift

View GitHub Profile
@JamesSwift
JamesSwift / import.php
Last active July 5, 2020 18:05
Scan a directory and move or copy all files to a date-structured directory
<?php
/*
This script will scan the directory you specify and move or copy
all files within it and its subdirectories. The files will be moved
to a subdirectory of the location where the script is, based on
either it's creation date or if the file contains exif data, the
date the photo was taken.
Call this script like so:
@JamesSwift
JamesSwift / gist:7492869
Created November 15, 2013 22:37
NQC Code to alow a Lego RCX brick to stand on two wheels. I place this code in the public domain. No rights reserved.
#define FULL_POWER_OFFSET 3
task main()
{
SetSensor(SENSOR_2,SENSOR_LIGHT);
int last_reading=SENSOR_2;
//start adjust_power;
SetPower(OUT_A+OUT_C,7);
@JamesSwift
JamesSwift / gist:5273325
Created March 29, 2013 20:14
I was having trouble initiating the `ssh-agent` on Git Bash (Git for Windows) in my `.bashrc` file using the example provided at: https://help.github.com/articles/working-with-ssh-key-passphrases So I created a simple script that does the job. It initiates a ssh-agent when you open Git Bash, and kills it when you close the bash. Note, it doesn't…
#! /bin/bash
#Start ssh-agent
eval `ssh-agent`
#Uncomment the next line if you want to automatically load ssh-keys at startup
#ssh-add
#Kill ssh-agent when we close the shell
trap "ssh-agent -k" EXIT
@JamesSwift
JamesSwift / commit_if_changed.sh
Created August 3, 2012 11:32
Sometimes you want to run an automated "git commit -a" (perhaps as a cron job), but you don't want to clog up your history if nothing has changed. I use the following script to run a commit only if changes have been made.
#!/bin/bash
cd /path/to/your/git/repo/
if [ "$(git status -s)" ] ; then
echo "Changes detected. Commiting."
git add .
git commit -am "Your explanation here"
else
echo "No changes detected. Commit canceled."
fi