Skip to content

Instantly share code, notes, and snippets.

View hafizbadrie's full-sized avatar

Hafiz Badrie Lubis hafizbadrie

  • Doctor Anywhere
  • Singapore
View GitHub Profile
@hafizbadrie
hafizbadrie / json_insert.rb
Created February 28, 2016 01:28
A script to insert 1 M JSON document
require 'sequel'
require 'json'
exit 1 if ARGV.empty?
db = Sequel.connect("postgres://localhost/hafizbadrie?user=hafizbadrie")
video_ids = ['12345', '54321', '34567', '87654', '67854']
platform = ['web-desktop', 'web-mobile', 'app-android', 'app-ios']
embed = ['true', 'false']
app_name = ['vidio', 'liputan6']
/* finding top ordinate value in a graph */
/* let's say $a is the highest value in data */
$a = 25;
$base = pow(10, (strlen($a) - 1));
$max = floor($a/$base) * $base;
$mod = $max%3;
$addition = ($mod == 0) ? 0 : 3 - $mod;
$max += $base * $addition;
echo $max;