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 / GitHub-Forking.md
Created February 4, 2017 01:45 — forked from Chaser324/GitHub-Forking.md
GitHub Standard Fork & Pull Request Workflow

Whether you're trying to give back to the open source community or collaborating on your own projects, knowing how to properly fork and generate pull requests is essential. Unfortunately, it's quite easy to make mistakes or not know what you should do when you're initially learning the process. I know that I certainly had considerable initial trouble with it, and I found a lot of the information on GitHub and around the internet to be rather piecemeal and incomplete - part of the process described here, another there, common hangups in a different place, and so on.

In an attempt to coallate this information for myself and others, this short tutorial is what I've found to be fairly standard procedure for creating a fork, doing your work, issuing a pull request, and merging that pull request back into the original project.

Creating a Fork

Just head over to the GitHub page and click the "Fork" button. It's just that simple. Once you've done that, you can use your favorite git client to clone your repo or j

@fadhlirahim
fadhlirahim / const.rb
Created December 14, 2016 06:15
Module.get_const vs Object.get_const vs Rails constantize
# run this in rails console
require 'benchmark/ips'
def track
track ||= Track.first
end
Benchmark.ips do |x|
x.report("Module.get_const") { Module.const_get("#{V1}::TrackPresenter").new(track) }
@fadhlirahim
fadhlirahim / cache_key.rb
Last active September 16, 2016 02:08
A module to create cache key using ruby. Often I find myself putting arbitrary strings all over the place in my code base. This module helps as being the 1 place in the code base to define what each key represents
module Cache
# Placeholder for your redis key prefixes
# Serves as a way to identify which prefix keys belongs to which cache key resource
#
# Usage:
#
# To create cache key
#
# Cache::Key.prefix(Cache::Key::PRESENTER, resource)
# => "pr:Track:#{track.id}:"
@fadhlirahim
fadhlirahim / facebook.rb
Last active September 14, 2016 06:34
A generic solution for facebook graph user integration with rails with the assumption that client already secured a Facebook Access Token. Not a login implementation
require 'date'
require 'net/http'
require 'active_support/concern'
# Module for verifying/creating users from authenticated facebook_token
#
# This will make a call to FB api and fetch the details of your user and store in your users database table.
#
# Ideal in use cases where you're clients are logged in/signed up using Facebook and you want to store user details and let your
@fadhlirahim
fadhlirahim / is_isogram.rb
Last active September 12, 2016 11:53
My Kata Collection
# An isogram is a word that has no repeating letters, consecutive or non-consecutive.
# Implement a function that determines whether a string that contains only letters is an isogram.
# Assume the empty string is an isogram. Ignore letter case.
is_isogram("Dermatoglyphics") == true
is_isogram("aba" ) == false
is_isogram("moOse" ) == false # -- ignore letter case
def is_isogram(str)
return true if str.nil? || str == ""
@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 / Gemfile
Created June 28, 2016 03:33 — forked from bf4/Gemfile
Rails lograge and logstash request logging
gem 'lograge' # more readable logs
gem 'logstash-event' # for logstash json format
gem 'mono_logger' # threadsafe logging
@fadhlirahim
fadhlirahim / _service.md
Created June 21, 2016 07:07 — forked from naholyr/_service.md
Sample /etc/init.d script

Sample service script for debianoids

Look at LSB init scripts for more information.

Usage

Copy to /etc/init.d:

# replace "$YOUR_SERVICE_NAME" with your service's name (whenever it's not enough obvious)
@fadhlirahim
fadhlirahim / advancedsettings.xml
Created June 15, 2016 14:57
kodi cache settings
<advancedsettings>
<network>
<buffermode> 1 </buffermode>
<readbufferfactor> 1.5 </readbufferfactor>
<cachemembuffersize> 104857600 </cachemembuffersize>
</network>
</advancedsettings>
@fadhlirahim
fadhlirahim / bm_ips.rb
Last active June 1, 2016 07:57
Some benchmarking using benchmark-ips on some common ruby methods
# gem install benchmark-ips
# run irb
require "benchmark/ips"
n = 100_000
# Array#push vs Array#<<
#
# Results: