Skip to content

Instantly share code, notes, and snippets.

View EtienneLem's full-sized avatar

Etienne Lemay EtienneLem

View GitHub Profile
@rafbm
rafbm / application_helper.rb
Last active December 14, 2015 09:50
Rails view helper for stripping whitespace between elements. Very useful for using `display: inline-block`.
module ApplicationHelper
def inline_tag(*args, &block)
body = Nokogiri::HTML(capture(&block)).at_css('body')
# First-level text nodes
body.xpath('text()').each do |node|
node.content = node.content.strip
end
content_tag(*args) { body.inner_html.strip.html_safe }
@remi
remi / helpers.js
Created October 4, 2012 14:51
Got tired of using `if ($("#foo").length)`, so I wrote these helpers.
// Helpers
$.fn.isPresent = function() { return this && this.length > 0 }
$.fn.isBlank = function() { return typeof(this) == "undefined" || !this || (this && this.length == 0) }
// Examples
$("body").isPresent() // => true
$("#foo").isPresent() // => false
$("body").isBlank() // => false
$("#foo").isBlank() // => true
@remi
remi / cache.rake
Created September 25, 2012 17:38
Clear Rails cache store and do it fast (without loading the whole Rails environment)
# bundle exec rake cache:clear
namespace :cache do
desc "Clear Rails.cache"
task :clear do
Object.const_set "RAILS_CACHE", ActiveSupport::Cache.lookup_store(Rails.configuration.cache_store)
Rails.cache.clear
puts "Successfully cleared Rails.cache!"
end
end
@rafbm
rafbm / meta-debug.css
Created August 27, 2012 01:04
CSS snippet for debugging meta descriptions and Open Graph tags with class
head, meta[name="description"], meta[property^="og:"] { display: block }
head {
position: relative;
z-index: 9999;
font: 21px/1.4 Didot;
color: #444;
-webkit-hyphens: auto;
padding: 2em;
background: #fff;
-webkit-font-smoothing: subpixel-antialiased;
@marcedwards
marcedwards / high-dpi-media.css
Last active November 19, 2023 12:56
A CSS media query that captures almost all high DPI aware devices.
/* ---------------------------------------------------------- */
/* */
/* A media query that captures: */
/* */
/* - Retina iOS devices */
/* - Retina Macs running Safari */
/* - High DPI Windows PCs running IE 8 and above */
/* - Low DPI Windows PCs running IE, zoomed in */
/* - Low DPI Windows PCs and Macs running Firefox, zoomed in */
/* - Android hdpi devices and above */
@remi
remi / kernel.rb
Created August 22, 2012 17:27
Change I18n.locale just for the time of a block
module Kernel
# I18n.locale = :en
# with_locale(:fr) do
# I18n.localize(Time.now, :format => :long) # => "mercredi 22 août 2012 13:23"
# end
# I18n.localize(Time.now, :format => :long) # => "August 22, 2012 13:23"
def with_locale(locale)
old_locale = I18n.locale
I18n.locale = locale
capture = yield
@piscisaureus
piscisaureus / pr.md
Created August 13, 2012 16:12
Checkout github pull requests locally

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = [email protected]:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:

@madrobby
madrobby / gist:3161015
Created July 22, 2012 20:43
Detect retina support. Tested on iOS, Android 2.x, Chrome for Android, Safari on MacBook Pro Retina, Firefox mobile (beta) for Android, Opera Mobile (Android)
function isRetina(){
return (('devicePixelRatio' in window && devicePixelRatio > 1) ||
('matchMedia' in window && matchMedia("(min-resolution:144dpi)").matches))
}
@rafbm
rafbm / onclickortouch.md
Created July 9, 2012 15:01
This is how I handle snappy taps on iOS.

This is how I handle snappy taps on iOS.

I create a little jQuery/Zepto “plugin” function:

$.fn.onClickOrTouch = (callback) ->
  if window.ontouchend != undefined # insanely clever touch detection
    this.each -> this._touchMoveCount = 0
@simonprev
simonprev / gist:3044224
Created July 3, 2012 23:55
Fix my Rdio
1. Open terminal.app
2. Paste this command: defaults write NSGlobalDomain WebKitDeveloperExtras -bool true
(credit: https://twitter.com/defaultswrite/status/220164244954554368)
3. Open Rdio.app
4. Right click and show the inspector panel
5. In the console section, paste this line: $("head").append('<link href="https://s3.amazonaws.com/simon-dev/css/rdio.css" rel="stylesheet" type="text/css">')