Skip to content

Instantly share code, notes, and snippets.

#application controller
around_filter :update_user_seen_on
def update_user_seen_on
yield
if signed_in?
current_user.last_seen_on = DateTime.now
current_user.save
def fizzbuzz( number, index = 1 )
# Do this in one pass
value = ""
value += "fizz" if (index % 3 == 0)
value += "buzz" if (index % 5 == 0)
p value
# and next number
fizzbuzz( number, index + 1 )
@jancel
jancel / gist:913662
Created April 11, 2011 15:07
an example from my parser
require 'spec_helper'
describe Parser do
def parser(str = nil)
Parser.new(str)
end
describe "when initialized" do
describe "with a valid string" do
@jancel
jancel / gist:1367606
Created November 15, 2011 17:01 — forked from r00k/gist:906356
Custom devise strategy
# In config/initializers/local_override.rb:
require 'devise/strategies/authenticatable'
module Devise
module Strategies
class LocalOverride < Authenticatable
def valid?
true
end
def build_table
build_table_head
build_table_body unless @collection.blank?
end
versus
def build_table
build_table_head
#config/production.rb (line 1)
def compile_asset?(path)
# ignores any filename that begins with '_' (e.g. sass partials)
# all other css/js/sass/image files are processed
if File.basename(path) =~ /^[^_].*\.\w+$/
puts "Compiling: #{path}"
true
else
puts "Ignoring: #{path}"
@jancel
jancel / Gemfile
Created March 31, 2014 14:43
Example deploy.rb for Capistrano
source 'https://rubygems.org'
gem 'rails', "3.2.10"
# omitted
group :stage, :production do
gem 'pg'
gem 'unicorn'
end
@jancel
jancel / Dockerfile
Created May 30, 2023 16:46
Installing SQL Server Tools on Debian 10
FROM debian:10
################################################################
# Install bulk copy program (bcp)
################################################################
RUN apt install -y gnupg2 apt-transport-https wget curl
RUN wget -q -O- https://packages.microsoft.com/keys/microsoft.asc | \
gpg --dearmor | tee /usr/share/keyrings/microsoft.gpg > /dev/null 2>&1
RUN echo "deb [signed-by=/usr/share/keyrings/microsoft.gpg arch=amd64,armhf,arm64] https://packages.microsoft.com/debian/10/prod buster main" | \
tee /etc/apt/sources.list.d/prod.list
@jancel
jancel / gist:ff55b3d0d6d6c4ddbc60e3644938c5f0
Created January 12, 2024 17:20
Rails Database.yml Example with Rails.credentials
default: &default
adapter: postgresql
encoding: unicode
url: <%= ENV.fetch('DATABASE_URL') { Rails.application.credentials.database_url } %>
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
"<%= Rails.env %>":
<<: *default
@jancel
jancel / pg_dump_restore.sh
Created January 12, 2024 18:18
Short script that will copy a postgres database to somewhere given URLs (Can change username and database name)
#!/bin/bash
: "${SOURCE:?Please provide a SOURCE which should be a database url}"
: "${TARGET:?Please provide a TARGET which should be a database url}"
dump_path=dump
if [ -d "$dump_path" ]; then
echo "/$dump_path already exists. Please remove ./$dump_path before running this script."
exit 1