Skip to content

Instantly share code, notes, and snippets.

View abhionlyone's full-sized avatar
:octocat:
Focusing

Abhilash Reddy abhionlyone

:octocat:
Focusing
View GitHub Profile
@abhionlyone
abhionlyone / hash_deep_diff.rb
Created February 5, 2019 06:06 — forked from henrik/hash_deep_diff.rb
Recursively diff two Ruby hashes.
# Recursively diff two hashes, showing only the differing values.
# By Henrik Nyh <http://henrik.nyh.se> 2009-07-14 under the MIT license.
#
# Example:
#
# a = {
# "same" => "same",
# "diff" => "a",
# "only a" => "a",
# "nest" => {
@abhionlyone
abhionlyone / letsencrypt_2018.md
Created August 18, 2018 13:50 — forked from cecilemuller/letsencrypt_2020.md
How to setup Let's Encrypt for Nginx on Ubuntu 18.04 (including IPv6, HTTP/2 and A+ SSL rating)

How to setup Let's Encrypt for Nginx on Ubuntu 18.04 (including IPv6, HTTP/2 and A+ SLL rating)


Virtual hosts

Let's say you want to host domains first.com and second.com.

Create folders for their files:

@abhionlyone
abhionlyone / gist:129ed753031bdb534016cf1be5a5bb10
Created August 14, 2018 08:12 — forked from cpjolicoeur/gist:3590737
Ordering a query result set by an arbitrary list in PostgreSQL

I'm hunting for the best solution on how to handle keeping large sets of DB records "sorted" in a performant manner.

Problem Description

Most of us have work on projects at some point where we have needed to have ordered lists of objects. Whether it be a to-do list sorted by priority, or a list of documents that a user can sort in whatever order they want.

A traditional approach for this on a Rails project is to use something like the acts_as_list gem, or something similar. These systems typically add some sort of "postion" or "sort order" column to each record, which is then used when querying out the records in a traditional order by position SQL query.

This approach seems to work fine for smaller datasets, but can be hard to manage on large data sets with hundreds (or thousands) of records needing to be sorted. Changing the sort position of even a single object will require updating every single record in the database that is in the same sort group. This requires potentially thousands of wri

@abhionlyone
abhionlyone / deploy.rb
Created May 22, 2018 07:00 — forked from ryancheung/deploy.rb
Capistrano config file example with Resque and Resque Scheduler
require "rvm/capistrano" # Load RVM's capistrano plugin.
require "bundler/capistrano"
set :rvm_ruby_string, '1.9.3'
set :rvm_type, :user # Literal ":user"
set :application, "blog_test"
set :repository, "git@github.com:ryancheung/blog.git"
set :scm, :git
@abhionlyone
abhionlyone / rails-jsonb-queries
Created May 15, 2018 08:37 — forked from mankind/rails-jsonb-queries
Rails-5 postgresql-9.6 jsonb queries
http://stackoverflow.com/questions/22667401/postgres-json-data-type-rails-query
http://stackoverflow.com/questions/40702813/query-on-postgres-json-array-field-in-rails
#payload: [{"kind"=>"person"}]
Segment.where("payload @> ?", [{kind: "person"}].to_json)
#data: {"interest"=>["music", "movies", "programming"]}
Segment.where("data @> ?", {"interest": ["music", "movies", "programming"]}.to_json)
Segment.where("data #>> '{interest, 1}' = 'movies' ")
Segment.where("jsonb_array_length(data->'interest') > 1")
@abhionlyone
abhionlyone / facebook.rb
Created November 29, 2017 05:48 — forked from a14m/facebook.rb
Gist for manually OAuth2 facebook for Rails APIs
# lib/omniauth/facebook.rb
require 'httparty'
module Omniauth
class Facebook
include HTTParty
# The base uri for facebook graph API
base_uri 'https://graph.facebook.com/v2.3'
@abhionlyone
abhionlyone / api_controller.rb
Created November 29, 2017 05:28 — forked from a14m/api_controller.rb
Rails JWT authentication
# app/controllers/api/v1/api_controller.rb
# Base API controller class
class Api::V1::ApiController < ApplicationController
before_action :http_authorization_header?, :authenticate_request, :set_current_user
protected
# Bad Request if http authorization header missing
def http_authorization_header?
fail BadRequestError, 'errors.missing_auth_header' unless authorization_header