Skip to content

Instantly share code, notes, and snippets.

View jnx's full-sized avatar
🎅

Christian Hjalmarsson jnx

🎅
View GitHub Profile
@jnx
jnx / gist:6409792
Created September 2, 2013 06:32 — forked from davidmh/gist:6228319
function precmd() {
if command git rev-parse --git-dir > /dev/null 2>&1; then
window_label=$(git rev-parse --show-toplevel)
tab_label=$(echo $window_label | awk -F\/ '{print "[git] " $NF}')
else
window_label=${PWD/${HOME}/\~}
tab_label=$window_label
fi
echo -ne "\e]2;${window_label}\a"
echo -ne "\e]1;${tab_label: -24}\a"
require 'mogli'
module FacebookIntegrationHelpers
shared_context "with unconnected facebook user" do
let(:fb_user) { create_test_user(installed: false) }
after { fb_user.destroy }
end
def app_client
Mogli::AppClient.new(AppConfig.facebook.access_token, AppConfig.facebook.app_id)
@jnx
jnx / 0-readme.md
Created January 11, 2013 09:32 — forked from burke/0-readme.md

ruby-1.9.3-p327 cumulative performance patch for rbenv

This installs a patched ruby 1.9.3-p327 with various performance improvements and a backported COW-friendly GC, all courtesy of funny-falcon.

Requirements

You will also need a C Compiler. If you're on Linux, you probably already have one or know how to install one. On OS X, you should install XCode, and brew install autoconf using homebrew.

@jnx
jnx / track-form-abandonment.md
Created December 11, 2012 08:37 — forked from arnklint/track-form-abandonment.md
Track Form Abandonment in Google Analytics in five rows of javascript

Put this code on the page where the form you want to track resides. Some other examples are currently passed around the web with varying quality. This is one that will work as long as your form tag has an id= or name attribute.

You don´t have to change this code to be able to track form abandonment in your shopping cart, order form or whatever form you want.

This sends events to Google Analytics when a user focuses somewhere not in a field after having focused on a input field. You won´t know for how long users focused on respective fields, or the actual conversion rate in the form using this, but it might be a start.

A tool that provides more insight both over time and per field, is Form Analytics. For instance, it measures dropout rate, average field input length, conversion rate and average time per field. All which provides great insights in the most overlooked, yet important part of you site.

Anyway, here´s the code:

@jnx
jnx / comment.js.coffee
Created August 24, 2012 06:06
Ember Associations
App.Comment = DS.Model.extend(
body: DS.attr("string")
post: DS.belongsTo('App.Post')
validate: ->
if @get("body") is `undefined` or @get("body") is ""
"Comments require a body."
)
@jnx
jnx / gist:3427057
Created August 22, 2012 16:06 — forked from lucasfais/gist:1207002
Sublime Text 2 - Useful Shortcuts

Sublime Text 2 – Useful Shortcuts (Mac OS X)

General

⌘T go to file
⌘⌃P go to project
⌘R go to methods
⌃G go to line
⌘KB toggle side bar
⌘⇧P command prompt
@jnx
jnx / mountain-lion-brew-setup.markdown
Created August 7, 2012 06:35 — forked from myobie/mountain-lion-brew-setup.markdown
Get Mountain Lion and Homebrew to Be Happy

Get Mountain Lion and Homebrew to Be Happy

1) Install XCode 4.4 into /Applications

Get it from the App Store.

2) Install Command Line Tools

In XCode's Preferences > Downloads you can install command line tools.

@jnx
jnx / gist:3246066
Created August 3, 2012 08:55 — forked from javan/gist:3237348
Sublime Text 2: Preferences > Key Bindings - User
[
// Make paste-and-indent the default paste behavior
{ "keys": ["super+v"], "command": "paste_and_indent" },
{ "keys": ["super+shift+v"], "command": "paste" }
]
#get the attribute from a given url (image) by using OCR
def ocr_attribute url
dir = "/tmp/scrapers"
file = rand(36**10).to_s(36)
path = "#{dir}/#{file}"
pnm_path = "#{dir}/#{file}.pnm"
open(url) do |f|
Dir.mkdir(dir) if !File.exists? dir
image = Image.from_blob(f.read)[0]
image.write(path)
@jnx
jnx / redcarpet.rb
Created June 29, 2012 17:59 — forked from davidjrice/redcarpet.rb
Rails 3.2 Markdown Template Handler
# config/initializers/redcarpet.rb
module ActionView
module Template::Handlers
class Markdown
class_attribute :default_format
self.default_format = Mime::HTML
def call(template)
markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, :autolink => true, :space_after_headers => true)
markdown.render(template.source).html_safe.inspect