Skip to content

Instantly share code, notes, and snippets.

View jfgomez86's full-sized avatar

Jose Felix Gomez jfgomez86

View GitHub Profile
$(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);
}
class AccountsController < ApplicationController
before_filter :force_ssl
def new
end
def create
end
@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;
@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 / 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;
<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 / 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,
@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 / tweet.rb
Created July 29, 2011 16:10
Finding latest tweets by unique users
##
# Find latest *n* tweets, but don't repeat tweets by users.
# Example:
#
# If we have the following table:
#
# id | user_id | created_at
# 1 | 1 | 3 days ago
# 2 | 2 | 3 days ago
# 3 | 1 | 2 days ago
@jfgomez86
jfgomez86 / .zshrc
Created July 11, 2011 20:14
My .zshrc customizations
###
# Shortcut to projects directory: you can replace 'p' with your favorite word/character.
# Autocompleter enabled! Try: `p <tab>` ;)
#
PROJECTS_DIR="/Users/jfgomez86/Projects"
p() {
PROJECT_NAME="$1";
cd "$PROJECTS_DIR/$PROJECT_NAME";
}