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 / job_details.js
Last active May 28, 2016 00:54
Fetch all error jobs from bitcodin api
var fs = require('fs');
var apiKey = "api-key";
var bitcodin = require('bitcodin')(apiKey);
var promise = bitcodin.job.getDetails(1);
promise.then(function (data) {
console.log(data);
});
}
@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:
@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 / _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 / 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 / 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 / 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 / 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 / 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 / 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) }