Skip to content

Instantly share code, notes, and snippets.

@yortz
yortz / post-receive
Created June 26, 2011 00:28 — forked from carlosantoniodasilva/post-receive
Basic git post-receive hook file to deploy a Rails app.
#!/bin/bash
APP_NAME="your-app-name-goes-here"
APP_PATH=/home/deploy/${APP_NAME}
# Production environment
export RAILS_ENV="production"
# This loads RVM into a shell session. Uncomment if you're using RVM system wide.
# [[ -s "/usr/local/lib/rvm" ]] && . "/usr/local/lib/rvm"
@yortz
yortz / useful_queries.rb
Last active September 12, 2019 10:34
Useful queries for stats retrieval
# Total number of users from last month
User.where(last_sign_in_at: 1.month.ago..Date.today).count
User.where(last_sign_in_at: 1.month.ago..Date.today).order(:last_sign_in_at).pluck(:email, :last_sign_in_at)
# Number of users who updated at least one experiment in the last month
Experiment.joins(:user).where(updated_at: 1.month.ago..Date.today).order(:updated_at).pluck(:updated_at, :id, :title, 'users.email').uniq {|r| r.last}.count
Experiment.joins(:user).where(updated_at: 1.month.ago..Date.today).order(:updated_at).pluck(:updated_at, :id, :title, 'users.email').uniq {|r| r.last}
Experiment.joins(:user).where(updated_at: 1.month.ago..Date.today).order(:updated_at).pluck(:updated_at, :id, :title, 'users.email').uniq {|r| r.last}.map {|a| {a.first.strftime("%b-%Y") => { experiment_title: a[2], user_email: a.last } }}
# Number of experiments,grouped by users, created per month for the past 18 months
@yortz
yortz / gist:1394699
Created November 25, 2011 23:51 — forked from metaskills/gist:756111
Rails 3 Models To Export Mephisto To Jekyll & Disqus
require 'builder'
require 'digest/md5'
class Content < ActiveRecord::Base
belongs_to :user
end
class Section < ActiveRecord::Base
has_many :assigned_sections
has_many :articles, :order => 'position', :through => :assigned_sections
@yortz
yortz / app.js.coffee
Created February 3, 2016 12:58
require fancybox in octopress for octopress gallery plugin
#= require ./libs/jquery-1.9.1
#= require modernizr-2.0
#= require ender
#= require jquery.waitforimages
#= require fancybox/jquery.mousewheel-3.0.6.pack
#= require fancybox/jquery.fancybox.pack
#= require underscore
#= require twitter
#= require gallery
#= require ./libs/lunr.min
@yortz
yortz / gallery_tag.rb
Created February 2, 2016 10:13
gallery tag plugin that integrates lightbox functionality to octopress image gallery
@yortz
yortz / carrierwave.rb
Created November 27, 2010 16:49
image_uploader.rb
#config/initializers/carrierwave.rb
CarrierWave.configure do |config|
if Rails.env.production? or Rails.env.development?
config.storage :cloud_files
config.cloud_files_username = "your_username"
config.cloud_files_api_key = "your_key"
config.cloud_files_container = "test"
config.cloud_files_cdn_host = "c0012345.cdnn.cloudfiles.rackspacecloud.com"
def store_dir
@yortz
yortz / anagram_test.rb
Created August 13, 2013 11:25
exercism ruby/anagram test
require 'minitest/autorun'
require_relative 'anagram'
class AnagramTest < MiniTest::Unit::TestCase
def test_no_matches
detector = Anagram.new('diaper')
assert_equal [], detector.match(%w(hello world zombies pants))
end
@yortz
yortz / gist:5867564
Last active December 19, 2015 00:19
defmodule Twitter do
def get_oauth_token
consumer_key= "yourkey"
consumer_secret = "yoursecret"
url = 'https://api.twitter.com/oauth'
consumer = Oauthex.Consumer.new(
key: :erlang.binary_to_list(consumer_key),
secret: :erlang.binary_to_list(consumer_secret)
let g:ScreenImpl = 'Tmux'
let g:ScreenShellTmuxInitArgs = '-2'
let g:ScreenShellInitialFocus = 'shell'
let g:ScreenShellQuitOnVimExit = 0
" Screen settings
map <F5> :ScreenShellVertical<CR>
command! -nargs=? -complete=shellcmd W :w | :call ScreenShellSend("load '".@%."';")
map <Leader>c :ScreenShellVertical bundle exec rails c<CR>
map <Leader>r :w<CR> :call ScreenShellSend("rspec ".@% . ':' . line('.'))<CR>
map <Leader>e :w<CR> :call ScreenShellSend("cucumber --format=pretty ".@% . ':' . line('.'))<CR>
map <Leader>b :w<CR> :call ScreenShellSend("break ".@% . ':' . line('.'))<CR>