Skip to content

Instantly share code, notes, and snippets.

View sabril's full-sized avatar

Muhammad Syaiful Sabril sabril

View GitHub Profile
@sabril
sabril / hello.rb
Last active January 16, 2016 16:32
test code
puts "hello ruby :-)"
@sabril
sabril / user.rb
Created October 21, 2014 22:52
How to refresh Google token
require 'google/api_client'
require 'google/api_client/client_secrets'
require 'google/api_client/auth/installed_app'
class User < ActiveRecord::Base
def save_google_credentials(omniauth, params)
if omniauth["credentials"]["refresh_token"]
self.google_access_token = omniauth["credentials"]["token"]
@sabril
sabril / ecdh.rb
Last active February 5, 2018 06:22
#openssl
require 'openssl'
require 'base64'
require "digest"
include OpenSSL
def aes256_encrypt(key, data)
key = Digest::SHA256.digest(key) if(key.kind_of?(String) && 32 != key.bytesize)
aes = OpenSSL::Cipher.new('AES-256-CBC')
aes.encrypt
require File.join(File.dirname(__FILE__), "../lib/diffie_hellman")
curve = Ecc::Curve.new 324, 1287, 3851
point = Ecc::Point.new 920, 303
server = Ecc::DiffieHellman.new curve, point, 1194
client = Ecc::DiffieHellman.new curve, point, 1759
server_pub = server.computePublicKey()
puts "Server Public Key: #{server_pub}"
# derived from http://h2np.net/tips/wiki/index.php?RubyOpenSSLDigitalSignatureSample
require 'openssl'
require 'base64'
include OpenSSL
group_name = 'secp160k1'
message = 'test payload aa'
puts "=== Generate Key ==="

Deploy Rails app to digitalocean/amazon EC2 with nginx, unicorn, capistrano & postgres

ubuntu 12.10 x32

ssh to root in terminal with your server ip

ssh [email protected]

or for ec2 you will need your public key

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<link rel="shortcut icon" href="assets/ico/favicon.png">
<title>Life Coach Drive</title>
@sabril
sabril / aws_setup.md
Last active December 31, 2015 21:59 — forked from rudylee/digitalocean.md

Deploy Rails app to digitalocean/amazon EC2 with nginx, unicorn, capistrano, sidekiq & postgres

Create droplet of your liking (ubuntu 12.10 x32)

ssh to root in terminal with your server ip

ssh -i config/onvard.pem [email protected]

Add ssh fingerprint and enter password provided in email

@sabril
sabril / omniauth.rb
Created December 10, 2013 15:50
tinggal buat routes untuk callbacknya
# gem "omniauth"
# gem "omniauth-instagram"
# gem "instagram"
Rails.application.config.middleware.use OmniAuth::Builder do
provider :instagram, ENV['INSTAGRAM_KEY'], ENV['INSTAGRAM_KEY']
end
Instagram.configure do |config|
config.client_id = ENV['INSTAGRAM_KEY']
@sabril
sabril / Gemfile
Last active February 27, 2017 08:45
source 'https://rubygems.org'
ruby '2.0.0'
# we are living on the edge, but to stay save.. keep this updated to the latest stable
gem 'rails', '4.0.2'
# i like an elephant more than a dolphin :)
gem "pg"
# mongodb is good for prototyping either it's RDBMS or not
gem 'mongoid', github: "mongoid/mongoid"