Skip to content

Instantly share code, notes, and snippets.

View zykadelic's full-sized avatar

Andreas Fransson zykadelic

View GitHub Profile
@hopsoft
hopsoft / db.rake
Last active September 17, 2024 06:23
Rails rake tasks for dump & restore of PostgreSQL databases
# lib/tasks/db.rake
namespace :db do
desc "Dumps the database to db/APP_NAME.dump"
task :dump => :environment do
cmd = nil
with_config do |app, host, db, user|
cmd = "pg_dump --host #{host} --username #{user} --verbose --clean --no-owner --no-acl --format=c #{db} > #{Rails.root}/db/#{app}.dump"
end
puts cmd
@hdragomir
hdragomir / sm-annotated.html
Last active October 9, 2024 00:35
The deferred font loading logic for Smashing Magazine. http://www.smashingmagazine.com/
<script type="text/javascript">
(function () {
"use strict";
// once cached, the css file is stored on the client forever unless
// the URL below is changed. Any change will invalidate the cache
var css_href = './index_files/web-fonts.css';
// a simple event handler wrapper
function on(el, ev, callback) {
if (el.addEventListener) {
el.addEventListener(ev, callback, false);
@multiplegeorges
multiplegeorges / simpleFormat.js
Created December 20, 2012 17:32 — forked from kares/simpleFormat.js
Handlebars helper to replicate the functionality of Rails' simple_format view helper. Wraps everything in a paragraph and corrects newlines and carriage returns. Ignores all other HTML.
Handlebars.registerHelper 'simple_format', (text) ->
carriage_returns = /\r\n?/g
paragraphs = /\n\n+/g
newline = /([^\n]\n)(?=[^\n])/g
text = text.replace(carriage_returns, "\n") # \r\n and \r -> \n
text = text.replace(paragraphs, "</p>\n\n<p>") # 2+ newline -> paragraph
text = text.replace(newline, "$1<br/>") # 1 newline -> br
text = "<p>" + text + "</p>";
@matisojka
matisojka / valid_json.rb
Created March 29, 2012 11:36 — forked from carlcrott/gist:2218175
JSON validation method (without monkey patching and with proper error handling)
def valid_json?(value)
JSON.parse value
true
rescue JSON::ParserError, TypeError
false
end
@artero
artero / launch_sublime_from_terminal.markdown
Last active September 12, 2024 02:13 — forked from olivierlacan/launch_sublime_from_terminal.markdown
Launch Sublime Text 2 from the Mac OS X Terminal

Launch Sublime Text 2 from the Mac OS X Terminal

Sublime Text 2 ships with a CLI called subl (why not "sublime", go figure). This utility is hidden in the following folder (assuming you installed Sublime in /Applications like normal folk. If this following line opens Sublime Text for you, then bingo, you're ready.

open /Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl

You can find more (official) details about subl here: http://www.sublimetext.com/docs/2/osx_command_line.html

Installation

@buffpojken
buffpojken / gist:736035
Created December 10, 2010 09:49
Roulette.
%w(rubygems json rest-client).map{|a|require a};puts"Amount betted:";a = gets;JSON.parse(RestClient.get("http://roulette.engineyard.com/")).each_pair{|k,v|v.eql?("13") ? (puts"You've won #{a.to_i*35}"):(puts "No winnings!")}