Skip to content

Instantly share code, notes, and snippets.

View jnx's full-sized avatar

Christian Hjalmarsson jnx

View GitHub Profile
#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
@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 / 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
);
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 / 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
#
@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 / gist:1758729
Created February 7, 2012 09:41
mapcords
<area shape="poly" class="zones" href="#" data-nearby-zones="787,741,740,728,781" id="742" coords="387,331,388,361,381,371,369,376,365,391,352,398,349,410,324,419,321,413,318,412,316,400,311,401,306,384,324,324,338,332" />
<area shape="poly" class="zones" href="#" data-nearby-zones="743,745,735,740,742" id="741" coords="252,339,291,325,300,308,324,322,305,382,301,380,252,372" />
<area shape="poly" class="zones" href="#" data-nearby-zones="785,786,744,745,741,787" id="743" coords="231,372,291,381,291,384,286,395,262,409,266,414,260,440,249,438,239,432,231,440,208,455,199,452" />
<area shape="poly" class="zones" href="#" data-nearby-zones="742,741,735,736,738,728" id="740" coords="363,230,366,240,380,260,393,263,392,271,390,275,389,286,385,289,385,294,394,314,389,318,389,330,341,330,326,320,317,250" />
<area shape="poly" class="zones" href="#" data-nearby-zones="745,749,752,736,738,740,741" id="735" coords="222,266,284,264,315,250,322,317,299,305,288,322,252,338,220,309" />
<area shape="poly" class="z
@jnx
jnx / basecamp2github.rb
Created January 22, 2012 13:13 — forked from chip/basecamp2github.rb
Convert Basecamp tasks to Github issues
require 'rubygems'
require 'hash'
require 'active_resource'
require 'basecamp'
require 'httparty'
require 'json'
class GithubIssues
include HTTParty
base_uri "https://api.github.com"
@jnx
jnx / gist:1295423
Created October 18, 2011 13:30
Milestones
Discovery
kickoff → discovery approval
Design
discovery approval → design approval
Development
design approval → beta
Beta