Skip to content

Instantly share code, notes, and snippets.

View mrgenixus's full-sized avatar

Benjamin West mrgenixus

View GitHub Profile
@schacon
schacon / gist:942899
Created April 26, 2011 19:19
delete all remote branches that have already been merged into master
$ git branch -r --merged |
grep origin |
grep -v '>' |
grep -v master |
xargs -L1 |
awk '{split($0,a,"/"); print a[2]}' |
xargs git push origin --delete
@dmitriy-kiriyenko
dmitriy-kiriyenko / active_model_lint.rb
Created February 23, 2012 13:37
ActiveModel lint tests for rspec
# put the file into spec/support
shared_examples_for "ActiveModel" do
include ActiveModel::Lint::Tests
# to_s is to support ruby-1.9
ActiveModel::Lint::Tests.public_instance_methods.map{|m| m.to_s}.grep(/^test/).each do |m|
example m.gsub('_',' ') do
send m
end
end
@ebidel
ebidel / handle_file_upload.php
Created April 18, 2012 03:23
Uploading files using xhr.send(FormData) to PHP server
<?php
$fileName = $_FILES['afile']['name'];
$fileType = $_FILES['afile']['type'];
$fileContent = file_get_contents($_FILES['afile']['tmp_name']);
$dataUrl = 'data:' . $fileType . ';base64,' . base64_encode($fileContent);
$json = json_encode(array(
'name' => $fileName,
'type' => $fileType,
'dataUrl' => $dataUrl,
@mrgenixus
mrgenixus / ctrr.md
Created October 25, 2012 19:57 — forked from esmooov/ctrr.md
Carats and Tildes, Resets and Reverts

Until last night I lived in fear of tildes, carats, resets and reverts in Git. I cargo culted, I destroyed, I laid waste the tidy indicies, branches and trees Git so diligently tried to maintain. Then Zach Holman gave a talk at Paperless Post. It was about Git secrets. He didn't directly cover these topics but he gave an example that made me realize it was time to learn.

A better undo

Generally, when I push out bad code, I panic, hit git reset --hard HEAD^, push and clean up the pieces later. I don't even really know what most of that means. Notational Velocity seems to be fond of it ... in that I just keep copying it from Notational Velocity and pasting it. Turns out, this is dumb. I've irreversibly lost the faulty changes I made. I'll probably even make the same mistakes again. It's like torching your house to get rid of some mice.

Enter Holman. He suggests a better default undo. git reset --soft HEAD^. Says it stag

@ahoward
ahoward / js-class.js
Created November 12, 2012 21:55
my latest favorite way to declare js classes...
//
var Grid = new Function();
Grid.initialize = function(){
var args = Array.prototype.slice.apply(arguments);
var grid = new Grid();
grid.initialize.apply(grid, args);
@michiels
michiels / ffmpeg_wrapper.rb
Created November 14, 2012 14:19
FFMPEG Wrapper
class FFMPEGWrapper
def duration_in_sections
command = IO.popen("ffmpeg -i #{uploaded_file} 2>&1 | awk '/Duration/ { print substr($2,0,length($2)-1) }'")
duration_output = command.read
matches = duration_output.match(/(\d{2}):(\d{2}):(\d{2}\.\d{1,2})\n/)
hours = matches[1].to_f
minutes = matches[2].to_f
seconds = matches[3].to_f
miliseconds = matches[4].to_f
@elliottkember
elliottkember / app.js
Last active December 17, 2015 05:09
Ever wanted to repeat parts of your markup while building templates? Do it like this!
$(function(){
$('*[data-repeat]').each(function(){
var n = $(this).data('repeat');
var parent = $(this).parent();
self = $(this);
for (var i = 0; i < n; i++) {
self.after(self.clone());
}
})
});