Skip to content

Instantly share code, notes, and snippets.

@rgreenjr
rgreenjr / postgres_queries_and_commands.sql
Last active May 6, 2024 12:37
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(clock_timestamp(), query_start), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
@flomotlik
flomotlik / Gemfile
Last active April 6, 2021 13:17
Puma on Heroku
gem 'foreman'
gem 'puma'
@quirkey
quirkey / console_helpers.rb
Last active February 13, 2020 19:57
All the code for the Paperless Profiler
require 'rblineprof'
module Rblineprof
module ConsoleHelpers
include Rblineprof::Helpers
def lineprof_block(options = {}, &block)
profile = lineprof(rblineprof_profiler_regex(options[:lineprofiler])) do
ret = yield
end
@anotheruiguy
anotheruiguy / web-fonts-asset-pipeline.md
Last active May 24, 2023 22:08
Custom Web Fonts and the Rails Asset Pipeline

Web fonts are pretty much all the rage. Using a CDN for font libraries, like TypeKit or Google Fonts, will be a great solution for many projects. For others, this is not an option. Especially when you are creating a custom icon library for your project.

Rails and the asset pipeline are great tools, but Rails has yet to get caught up in the custom web font craze.

As with all things Rails, there is more then one way to skin this cat. There is the recommended way, and then there are the other ways.

The recommended way

Here I will show how to update your Rails project so that you can use the asset pipeline appropriately and resource your files using the common Rails convention.

@thebucknerlife
thebucknerlife / authentication_with_bcrypt_in_rails_4.md
Last active January 17, 2024 23:54
Simple Authentication in Rail 4 Using Bcrypt

#Simple Authentication with Bcrypt

This tutorial is for adding authentication to a vanilla Ruby on Rails app using Bcrypt and has_secure_password.

The steps below are based on Ryan Bates's approach from Railscast #250 Authentication from Scratch (revised).

You can see the final source code here: repo. I began with a stock rails app using rails new gif_vault

##Steps

@thatrubylove
thatrubylove / gol.rb
Last active August 29, 2015 14:01
Functional Game of Life (spike)
require 'curses'
module Seeder
extend self
def generate_matrix
rand(40..200).times.map { [rand(24), rand(48)] }
end
end
class Universe
@drbrain
drbrain / README.md
Last active August 29, 2015 14:19
Parentheses don't make code readable by themselves

I've heard people argue "parentheses make code more readable" or "parentheses make code less ambiguous". Parentheses neither help nor hinder ambiguity or readability, your style decisions beyond use of () do that.

Here's a bug we introduced in our application that was allowed through by a coding style that preferred parentheses. If you follow a coding style that omits all unneccesary parentheses (only those that suppress warnings, which I prefer) this bug would have been impossible.

The bug is simple but subtle. The environment-specific data wasn't fetched from config/two.yml because a ) was in the wrong place. Neither my coworker who wrote it, another coworker who reviewed it, nor my own review of the line caught it.

Without parentheses, though, there is no way to introduce this class of bugs because you can't chain off of intermediate results without introducing a local variable.

The main difference between the two examples is not the use of parentheses, it's the style in which the code is wri

@JoshCheek
JoshCheek / lambda_calculus_list.rb
Created April 19, 2015 20:39
Linked List (only as far as the stack) implemented with the constraints of the lambda calculus.
# Build the relevant methods
-> with_self {
-> list {
-> the_program {
the_program[with_self, list] }}[
# list
-> build_node {
with_self[-> me {
build_node[-> { me }, -> { raise 'too far!' }]}]}[
At Monmouth Telecom we provide high-availability cloud based telephone systems for medium to large companies. Because
we have written our own code in Ruby it is easy for us to customize or add additional features at the request of customers,
often at no charge, and that is key to our business.
Several years ago our engineering team developed a real time display panel for managers and operators alike that kept people
abreast of the status of phone extensions, conference bridges, and call queues, as well as allowing a variety of call control
features. We wrote this in ruby so that it would be easy to extend. The web display panel accesses customer data through
Active Record and is based on HTML5 with canvas and web sockets so it doesn’t require setup on the customer site.
Unsurprisingly it was one our more popular features and so we immediately started monitoring Rubinius as our migration path
for the day when one core of our 8 processor cores would become insufficient to meet demand. Well earlier this year
@maxivak
maxivak / 00.md
Last active May 6, 2024 15:27
Sending emails with ActionMailer and Sidekiq

Sending emails with ActionMailer and Sidekiq

Send email asynchroniously using Sidekiq.

ActionMailer

Create your mailer us usual: