Skip to content

Instantly share code, notes, and snippets.

View jfgomez86's full-sized avatar

Jose Felix Gomez jfgomez86

View GitHub Profile
@jfgomez86
jfgomez86 / heroku_autoscaler.rb
Created November 2, 2011 04:48
Quick Dirty Heroku AutoScaling script that may save you money. Works with Delayed Job.
# Inspired by http://verboselogging.com/2010/07/30/auto-scale-your-resque-workers-on-heroku
module HerokuAutoscale
module Scaler
class << self
@@heroku = Heroku::Client.new(ENV['HEROKU_USER'], ENV['HEROKU_PASS'])
def workers
@@heroku.info(ENV['HEROKU_APP'])[:workers].to_i
end
@jfgomez86
jfgomez86 / database_yml.rb
Created November 12, 2011 18:05
Script that generates a database.yml file based on some input. Used for CI environments mainly.
require 'yaml'
class DatabaseYML
attr_accessor :project_name, :config
DEFAULT_OPTIONS = {
"adapter" => "mysql2",
"encoding" => "utf8",
"reconnect" => false,
"pool" => 5,
<div id="swf_upload">
<strong>New Upload:</strong>
<div id="browse">
<%= raw s3_swf_upload_tag(
fileTypes: "*.csv",
queueSizeLimit: 1,
selectMultipleFiles: false,
onQueueEmpty: "window.uploader.queueEmpty();",
onFileAdd: "window.uploader.fileAdd(file);",
onUploadingStart: "window.uploader.uploadingStart();",
@jfgomez86
jfgomez86 / copy.sql
Created November 17, 2011 01:32
Note to self about PostgreSQL's COPY
COPY table (each, f_ing, column, here, please, this, is, important!)
FROM '/Users/jfgomez86/the_f_ing.csv'
WITH CSV HEADER;
@jfgomez86
jfgomez86 / user.rb
Created November 29, 2011 03:21
Users who haven't written any post in the past 30 days.
scope :inactive, lambda {
ids = User.joins(:posts)
.select("users.id, max(post.created_at)")
.group("users.id")
.having("max(posts.created_at) < ?", [30.days.ago])
where(id: ids)
}
@jfgomez86
jfgomez86 / export_users.sql
Created December 1, 2011 14:42
Export from MySQL to CSV
SELECT username,fullname,email
INTO OUTFILE '/tmp/users.csv'
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"'
ESCAPED BY '\\'
LINES TERMINATED BY '\n'
FROM users;
class AccountsController < ApplicationController
before_filter :force_ssl
def new
end
def create
end
$(function() {
WysiHat.Commands.promptLinkSelection = (function() {
if (this.linkSelected()) {
if (confirm("Remove link?"))
this.unlinkSelection();
} else {
var value = prompt("Enter a URL", "http://www.google.com/");
if (value)
this.linkSelection(value);
}
@jfgomez86
jfgomez86 / precompile_assets.textile
Created March 1, 2012 20:41 — forked from kathgironpe/precompile_assets.textile
Rails 3.1: Precompile Assets for Cloudfront/CDN support

Naming files and using asset_path

application.scss.erb
- use <%= asset_path 'background.jpg' %>

on config/environments/production.rb

@jfgomez86
jfgomez86 / graph_api.rb
Created October 11, 2012 14:38
Simple (and incomplete) Facebook Graph API wrapper for public objects. It is incomplete on purpose for a ruby lesson :)
require 'rubygems'
require 'open-uri'
require 'json'
require 'ostruct'
def get_graph_object(object_id)
graph_json = open("https://graph.facebook.com/#{object_id}").read
data_hash = JSON.parse(graph_json)
parsed_hash = parse_hash(data_hash)