Skip to content

Instantly share code, notes, and snippets.

View loginx's full-sized avatar

Xavier Spriet loginx

View GitHub Profile
@loginx
loginx / gist:810311
Created February 3, 2011 22:04
Underscore.js mixin to emulate ruby's Array#each_slice method.
/**
* Underscore.js mixin to emulate Ruby's Enumerable#each_slice method.
* http://www.ruby-doc.org/core/classes/Enumerable.html#M001514
*
*/
_.mixin({
each_slice: function(obj, slice_size, iterator, context) {
var collection = obj.map(function(item) { return item; });
@loginx
loginx / jquery_isotope_reset.js
Created February 15, 2011 17:35
Extends Isotope, providing a reset() method to empty the grid and reLayout.
// Adds a .isotope( 'flush' ) method to your Isotope widget.
// This method will remove all items from the widget and from the DOM,
// then trigger a reLayout.
$.Isotope.prototype.flush = function() {
this.$allAtoms = $();
this.$filteredAtoms = $();
this.element.children().remove();
this.reLayout();
};
@loginx
loginx / .irbrc
Created March 10, 2011 16:36
~/.irbrc config file to enable ActiveRecord logging to the rails console (if in rails console) and enable IRB autocompletion and autoindent.
require 'irb/completion'
require 'pp'
IRB.conf[:AUTO_INDENT]=true
if defined?(Rails) && !Rails.env.nil?
ActiveRecord::Base.logger = Logger.new(STDOUT)
end
@loginx
loginx / _partial1.html.erb
Created May 16, 2012 21:25
Dynamic partials in Batman.js
<div data-replace="item">
PARTIAL 1: <span data-bind="item.name"></span>
</div>
@loginx
loginx / irb.rb
Created May 30, 2012 16:21
How to use make_flaggable with STI relations
User.find(1).flag Tablet.find(1)
# => #<MakeFlaggable::Flagging id: 1, flaggable_type: "Device", flaggable_id: 1, flagger_type: "User", flagger_id: 1, reason: nil, created_at: "2012-05-30 16:16:23", updated_at: "2012-05-30 16:16:23">
User.find(1).flagged? Tablet.find(1)
# MakeFlaggable::Flagging Load (0.4ms) SELECT "flaggings".* FROM "flaggings" WHERE "flaggings"."flagger_id" = 1 AND "flaggings"."flagger_type" = 'User' AND "flaggings"."flaggable_type" = 'Tablet' AND "flaggings"."flaggable_id" = 1 LIMIT 1
# => false
# :rage:
#########
# If you look at the query, it inserted the `flaggable_type` as 'Device', but is searching for 'Tablet'
@loginx
loginx / ie8.html
Created June 12, 2012 00:27 — forked from johnthethird/ie8.html
IE8 Batman Performance
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=8" />
<title>Batman Profiler</title>
<script type="text/javascript" src="https://raw.github.com/Shopify/batman/master/lib/es5-shim.js"></script>
<script type="text/javascript" src="https://raw.github.com/Shopify/batman/v0.9.0/lib/batman.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.3.3/underscore-min.js"></script>
<script type="text/javascript" src="http://coffeescript.org/extras/coffee-script.js"></script>
<script src="http://code.highcharts.com/highcharts.js"></script>
@loginx
loginx / containspoint.coffee
Created November 20, 2012 20:29
jQuery containsPoint method
# jQuery method to detect whether or not a point (x,y) is within the bounds of a jQuery element.
# Example usage: $("#container").containsPoint 100, 100
$.fn.containsPoint = (x, y) ->
(@offset.left < x < @offset.left + @width()) and
(@offset.top < y < @offset.top + @height())
@loginx
loginx / overlaps.jquery.coffee
Created November 29, 2012 23:44
jQuery $(el).overlaps(otherEl) helper
$.fn.overlaps = (el) ->
el = $(el)
o =
el1: @offset()
el2: el.offset()
el1 =
x1: o.el1.left
x2: o.el1.left + @width()
@loginx
loginx / .bash_login
Created June 12, 2013 19:15
Show git branch in bash prompt
function parse_git_branch {
ref=$(git symbolic-ref HEAD 2> /dev/null) || return
echo " ("${ref#refs/heads/}")"
}
export PS1="\[\033[01;32m\]\u@\h\[\033[01;34m\] \w\$(parse_git_branch) \$\[\033[00m\] "
@loginx
loginx / .bashrc
Created November 1, 2013 04:39
Current git branch info in bash prompt.
# Insert this in ~/.bashrc or ~/.bash_login
function parse_git_branch {
ref=$(git symbolic-ref HEAD 2> /dev/null) || return
echo " ("${ref#refs/heads/}")"
}
export PS1="\[\033[01;32m\]\u@\h\[\033[01;34m\] \w\$(parse_git_branch) \$\[\033[00m\] "