Skip to content

Instantly share code, notes, and snippets.

View jnx's full-sized avatar
🎅

Christian Hjalmarsson jnx

🎅
View GitHub Profile
@jnx
jnx / guid_generator.js
Created March 14, 2012 08:08
GUID Generator
function guidGenerator() {
var S4 = function() {
return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
};
return (S4()+S4()+"-"+S4()+"-"+S4()+"-"+S4()+"-"+S4()+S4()+S4());
}
// How to use it:
guidGenerator();
@jnx
jnx / hack.sh
Created March 31, 2012 17:47 — forked from erikh/hack.sh
OSX For Hackers
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh
#
class ActionDispatch::Routing::Mapper
def draw(routes_name)
instance_eval(File.read(Rails.root.join("config/routes/#{routes_name}.rb")))
end
end
BCX::Application.routes.draw do
draw :api
draw :account
draw :session
@jnx
jnx / example-user.js
Created May 4, 2012 11:31 — forked from nijikokun/example-user.js
Beautiful Validation... Why have I never thought of this before?!
var user = {
validateCredentials: function (username, password) {
return (
(!(username += '') || username === '') ? { error: "No Username Given.", field: 'name' }
: (!(username += '') || password === '') ? { error: "No Password Given.", field: 'pass' }
: (username.length < 3) ? { error: "Username is less than 3 Characters.", field: 'name' }
: (password.length < 4) ? { error: "Password is less than 4 Characters.", field: 'pass' }
: (!/^([a-z0-9-_]+)$/i.test(username)) ? { error: "Username contains invalid characters.", field: 'name' }
: false
);
@jnx
jnx / gist:2841711
Created May 31, 2012 07:44
Hackernews in terminal
require 'open-uri'
class Story
attr_accessor :title, :url
def initialize(title, url)
@title = title
@url = url
end
@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
#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 / 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" }
]
@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: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