Skip to content

Instantly share code, notes, and snippets.

class Fill < ActiveRecord::Migration[5.0]
def up
execute <<-SQL
UPDATE payments p
SET discount_amount = sub.discount_amount
FROM
(
SELECT payments.id AS payment_id, sum(charges.discount_amount) AS discount_amount
FROM payments
INNER JOIN orders
class ChargesRecalculator
attr_reader :account, :charges_with_discount, :not_closed_charges, :closed_charges
def initialize(account, charges_with_discount)
@account = account
@charges_with_discount = charges_with_discount
@not_closed = charges_with_discount.not_in_closed # 11
@closed_charges = charges_with_discount.in_closed # 1
end
@entei
entei / pp.rb
Last active August 4, 2017 15:53
# plan_period.rb
class PlanPeriod < ActiveRecord::Base
# id: integer
# endless: boolean
# trial: boolean
# plan_id: integer
belongs_to :plan
validates :endless, uniqueness: { scope: :plan_id }, on: [:endless]
end
@entei
entei / Redis.sh
Created May 3, 2017 08:08 — forked from nrollr/Redis.sh
Install Redis via Homebrew
#!/bin/bash
brew install redis # Install Redis using Homebrew
ln -sfv /usr/local/opt/redis/*.plist ~/Library/LaunchAgents # Enable Redis autostart
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.redis.plist # Start Redis server via launchctl
# homebrew.mxcl.redis.plist contains reference to redis.conf file location: /usr/local/etc/redis.conf
redis-server /usr/local/etc/redis.conf # Start Redis server using configuration file, Ctrl+C to stop
redis-cli ping # Check if the Redis server is running
@entei
entei / postgresql.rb
Created May 3, 2017 07:55
install postgresql on mac with homebrew
# show installed versions of psql
brew info postgresql #=> 9.1.5 and 9.6
# We may activate older installed version using brew switch
brew switch postgresql 9.1.5
# update & install
brew update
brew install postgres
# if this is first time installing Postgres with Homebrew, you'll need to create a database with:
@entei
entei / gist:19d7d72173749d1ed97a4d0c793ea236
Created February 28, 2017 10:34 — forked from ryansobol/gist:5252653
15 Questions to Ask During a Ruby Interview

Originally published in June 2008

When hiring Ruby on Rails programmers, knowing the right questions to ask during an interview was a real challenge for me at first. In 30 minutes or less, it's difficult to get a solid read on a candidate's skill set without looking at code they've previously written. And in the corporate/enterprise world, I often don't have access to their previous work.

To ensure we hired competent ruby developers at my last job, I created a list of 15 ruby questions -- a ruby measuring stick if you will -- to select the cream of the crop that walked through our doors.

What to expect

Candidates will typically give you a range of responses based on their experience and personality. So it's up to you to decide the correctness of their answer.

@entei
entei / appendTo.js
Created December 10, 2015 11:32
jquery appendTo
<!doctype html>
<html>
<head>
<meta charset=utf-8>
<title>Appending Content</title>
<style>
article {
width: 600px;
margin: auto;
}
@entei
entei / registrations_controller.rb
Last active August 29, 2015 14:25 — forked from jwo/registrations_controller.rb
API JSON authentication with Devise
class Api::RegistrationsController < Api::BaseController
respond_to :json
def create
user = User.new(params[:user])
if user.save
render :json=> user.as_json(:auth_token=>user.authentication_token, :email=>user.email), :status=>201
return
else
@entei
entei / authentication_with_bcrypt_in_rails_4.md
Last active August 29, 2015 14:25 — forked from thebucknerlife/authentication_with_bcrypt_in_rails_4.md
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

Ideal ;; syntax
Model tiny
jumps
;;; $ - end of line
dataseg
Attempts db 3
Password db 15,'ya - solonevich',13 ;;; 2 - password length
Password2 db 5,'denis',13 ;;; 2 - password length
Password3 db 10,'andreevich',13 ;;; 2 - password length
Path db 64 dup (?)