Skip to content

Instantly share code, notes, and snippets.

View willread's full-sized avatar

William Read willread

View GitHub Profile
FILES=( foo.ext, bar.ext )
PATH=./src
for FILE in "${FILES[@]}"
do
if [[ $(grep -R $FILE $PATH) ]]; then
:
else
echo "$FILE is unused"
fi
done
@willread
willread / convert.sh
Created July 25, 2016 06:55
Recursively convert the bitrate of all mp3 files in the specified folder
#!/bin/sh
files="$(find -L $1 -name '*.mp3' -type f)"
echo "$files" | while read file; do
lame --mp3input -b 64 "$file" "$file.converted"
rm "$file"
mv "$file.converted" "$file"
done
@willread
willread / .gitconfig
Created January 26, 2016 21:36
Remove or recreate git tags
[alias]
detag = "!f() { param=${1}; git tag -d $param; git push origin :refs/tags/$param; }; f"
retag = "!f() { param=${1}; git detag $param; git tag -a $param -m 'Tagging release'; git push --tags; }; f"
var fs = require('fs');
var screenshot = function(path) {
browser.takeScreenshot().then(function (png){
png = new Buffer(png, 'base64');
fs.writeFile(path, png, 'binary', function (err) {
if(err){
throw err
}
});
@willread
willread / gist:6ebdb478aef35508c246
Last active August 29, 2015 14:24
Gulp task to scale all css pixel values down by 10%
var replace = require('gulp-replace');
gulp.task('resizeCSS', function() {
gulp.src(['clients/unata/styles/*.styl', 'clients/unata/styles/**/*.styl'])
.pipe(replace(/([0-9]+\.?[0-9]*)px/g, function(match, size) {
if(size > 0){
size = Math.max(1, Math.round(size * 0.9));
}
return size + 'px';
}))
@willread
willread / gist:d1551cb5dc7eceab475a
Last active August 29, 2015 14:24
Code refactor checklist

Add a space between function and opening bracket

(function.+\))\{
$1 {

Dots should be at the start of a line, not the end

<style>
.main {
background: #f4f1ee;
width: 100%;
min-width: 640px;
color: #333333;
table-layout: fixed;
}
.main, a {
@willread
willread / gist:8fa10bac81160f1f45b8
Last active August 29, 2015 14:17
Convert rem units to pixels
var glob = require('glob');
var _ = require('lodash');
var fs = require('fs');
var rem = 18;
var path = '/path/stuff/**/*.css';
glob(path, {}, function(err, files) {
_.each(files, function(file) {
fs.readFile(file, 'utf-8', function(err, data) {
@willread
willread / gist:669dad645c8ab35524c5
Created March 8, 2015 13:29
Scrape beeradvocdate links and open search tabs for each on untappd
$("#ba-content > table:nth-child(3) > tbody > tr > td:nth-child(3) > a:nth-child(1) > b").each(function(i, beer){
setTimeout(function() {
window.open("https://untappd.com/search?q=" + $(beer).text());
}, i * 1000)
});
@willread
willread / gist:3ac901949c0b7b7d999c
Created January 5, 2015 19:38
Use watchers in an angular service
angular.module('app')
.service('myService', function($rootScope) {
// Inject an isolate scope into the rootscope to
// enable us to use $watch to from a service
this.scope = $rootScope.$new(true);
this.scope.myService = this;
this.scope.$watch('something', function() {});