Skip to content

Instantly share code, notes, and snippets.

View raderj89's full-sized avatar

Jared Rader raderj89

View GitHub Profile
@raderj89
raderj89 / add_user_id_to_sessions_devise.md
Last active May 13, 2020 07:46
Make sessions queryable by user with ActiveRecord Session Store and Devise

Make sessions queryable by user with ActiveRecord Session Store and Devise

  1. Install the ActiveRecord Session Store gem and read the documentation for how to use it and create your sessions table.

  2. Create a migration to add user_id to the sessions table.

class AddUserIdToSessions < ActiveRecord::Migration
  disable_ddl_transaction!
@raderj89
raderj89 / delete_comments_likes.js
Created March 25, 2018 17:21 — forked from DanTup/delete_comments_likes.js
Delete all Facebook posts for a year
// Only tested in Chrome...
// Must browse to "Your Comments" (or "Your Likes") page of activity feed, then pre-load the year you want to delete
// and as many comments as possible (scroll down, they load lazily).
//
// I ACCEPT ABSOLUTELY NO RESPONSIBILITY FOR THIS DOING BAD STUFF. THE NEXT FACEBOOK DEPLOYMENT
// COULD WELL BREAK THIS, OR MAKE IT DO THINGS YOU DO NOT EXPECT. USE IT AS A STARTING POINT ONLY!
//
// It will start failing once it gets to the end, just reload the page and kick it off again.
var rows = document.querySelectorAll('#year_2012 .pam._5shk');
class User < ApplicationRecord
has_many :posts
has_many :comments
# id :integer not null, primary key
# name :string(50) default("")
end
@raderj89
raderj89 / sum.exs
Created April 7, 2016 17:33
write a sum function without an accumulator
# Write a sum function without an accumulator
defmodule MyList do
def sum([]), do: 0
def sum([x]), do: x
def sum([ head | tail ]), do: head + sum(tail)
end
@raderj89
raderj89 / sums_consecutive_position.js
Last active March 15, 2016 06:28
Sums of consecutive integers
/**
* Given the number of consecutive integers and the total of the integers,
* return the consecutive integer at the requested position.
*
* @param {int} x number of consecutive integers
* @param {int} y sum of consecutive integers
* @param {int} n position of requested integer
* @return {int} consecutive integer at requested position
*/
function position(x, y, n) {
@raderj89
raderj89 / money_transfer.rb
Last active September 10, 2015 20:43
DCI example
class Account < ActiveRecord::Base
def transfer_to(destination, amount)
self.balance -= amount
destination.balance += amount
destination.save
self.save
end
end
class TransfersController < ApplicationController
class FetchingProgressInstance
attr_reader :enrollment, :roadmap
def initialize(enrollment, roadmap)
@enrollment = enrollment
@roadmap = roadmap
assign_progress_fetcher(@enrollment)
end
def fetch_progress
require 'spec_helper'
describe Referral do
let(:company) { FactoryGirl.create(:company) }
before do
@referral = company.referrals.build(details: "Lorem ipsum", link: "http://example.com")
@referrals = Referral.all
end
# spec/controllers/properties_controller_spec.rb
require 'spec_helper'
describe PropertiesController do
let(:manager_invitation) { create(:manager_invitation) }
describe 'GET #new' do
context 'with invalid invitation token' do
it "redirects to root path" do
get :new, invitation_token: 'asdfsae'

This JavaScript code represents some functionality to dynamically add links to employee goals and company grades added in past meetings on the Taqeela app. Grades and goals are added under one meeting, but the UI requirements we were given called for displaying different sections where these data could be accessed. Had I not taken an object oriented approach, I'd have had to duplicate the same jQuery code for each call.