Skip to content

Instantly share code, notes, and snippets.

View fadhlirahim's full-sized avatar
💭
Most happiest building code that make sense.

Fadhli Rahim fadhlirahim

💭
Most happiest building code that make sense.
View GitHub Profile
@fadhlirahim
fadhlirahim / dirty_associations.rb
Last active January 31, 2024 09:16
Awesome simple solution for Rails ActiveRecord dirty tracking associations
# Credit Brandon Weiss of http://anti-pattern.com/dirty-associations-with-activerecord
# app/models/dirty_associations.rb
module DirtyAssociations
attr_accessor :dirty
attr_accessor :_record_changes
def make_dirty(record)
self.dirty = true
self._record_changes = record
@fadhlirahim
fadhlirahim / load_cassete.rb
Created January 16, 2024 01:08
Reading ruby gem vcr cassette binary
require 'yaml'
require 'oj'
path = 'spec/vcr_cassettes/cassette.yml'
loaded = YAML.load_file(path)
body_string = loaded['http_interactions'][0]['response']['body']['string']
Oj.load(body_string)
@fadhlirahim
fadhlirahim / installing_supervisor_macosx.md
Last active December 31, 2023 14:45
Setting up supervisord in Mac OS X

Installation

Installing Supervisor on OS X is simple:

sudo pip install supervisor

This assumes you have pip. If you don't:

@fadhlirahim
fadhlirahim / s3_bucket_size
Created October 4, 2023 01:33
Bash function to get the size of S3 bucket
# Usage:
#
# s3_bucket_size your-bucket-name
#
function s3_bucket_size() {
if [ -z "$1" ]; then
echo "Please provide a bucket name."
return 1
fi
@fadhlirahim
fadhlirahim / elixir.json
Created September 20, 2022 10:14
VSCode elixir snippet
{
"lv_module": {
"prefix": "lv",
"body": [
"defmodule ${WORKSPACE_NAME/((^[a-z])|_([a-z]))/${2:/upcase}${3:/upcase}/g}Web.${4}Live do",
" use ${WORKSPACE_NAME/((^[a-z])|_([a-z]))/${2:/upcase}${3:/upcase}/g}Web, :live_view",
"end",
],
"description": "LiveView module"
},
@fadhlirahim
fadhlirahim / access_token_helper.rb
Created September 6, 2016 05:07
doorkeeper oauth token in rspec
# assumption
# model user exist
#
module AccessTokenHelper
APP_NAME = "app name".freeze
REDIRECT_URL = "https://host.name/oauth/callback".freeze
def token_scopes(scopes)
app = Doorkeeper::Application.create!(:name => "MyApp", :redirect_uri => REDIRECT_URL)
user = create(:user)
@fadhlirahim
fadhlirahim / google_play_verification.rb
Created April 7, 2021 07:07 — forked from jkotchoff/google_play_verification.rb
Verifying an Android subscription in a Ruby on Rails app using the Google Play API
class GooglePlayVerification
require 'google/api_client'
# Refer:
# https://code.google.com/p/google-api-ruby-client/issues/detail?id=72
# and
# http://jonathanotto.com/blog/google_oauth2_api_quick_tutorial.html
# and
# http://milancermak.wordpress.com/2012/08/24/server-side-verification-of-google-play-subsc/
GOOGLE_KEY = 'xxx-xxx.apps.googleusercontent.com'
@fadhlirahim
fadhlirahim / install-wireguard-server.sh
Created March 5, 2021 16:30 — forked from jph00/install-wireguard-server.sh
Installation of Wireguard server. Tested on Ubuntu 20.04. Should work on 18.04 as well.
#!/usr/bin/env bash
set -e
echo
if ! [[ $(id -u) = 0 ]]; then
echo "Please run 'sudo ./install-wireguard.sh'" >&2
exit 1
fi
read -e -p "Use VPN for *all* internet traffic? [y/n] " -i n ROUTE_ALL
@fadhlirahim
fadhlirahim / config.yml
Created January 14, 2020 07:46 — forked from sjparkinson/config.yml
Deploy a Fastly service using Terraform and CircleCI 2.0.
version: 2
jobs:
validate_terraform:
docker:
- image: hashicorp/terraform
steps:
- checkout
- run:
name: Validate Terraform Formatting
@fadhlirahim
fadhlirahim / heartbeat.rb
Created May 18, 2016 03:48
A rails rack middleware to check the heartbeat, redis & database connection of your rails app
# Rack middleware to return 200 if service is up
#
# Usage:
#
# GET /hb
#
# GET /db
#
class HeartBeat
OK = [200, {"Content-Type" => "text/plain"}, []].freeze