Skip to content

Instantly share code, notes, and snippets.

View SunDi3yansyah's full-sized avatar
Verified

Cahyadi Triyansyah SunDi3yansyah

Verified
View GitHub Profile
@SunDi3yansyah
SunDi3yansyah / jwt-expiration.md
Created July 7, 2019 14:56 — forked from soulmachine/jwt-expiration.md
How to deal with JWT expiration?

First of all, please note that token expiration and revoking are two different things.

  1. Expiration only happens for web apps, not for native mobile apps, because native apps never expire.
  2. Revoking only happens when (1) uses click the logout button on the website or native Apps;(2) users reset their passwords; (3) users revoke their tokens explicitly in the administration panel.

1. How to hadle JWT expiration

A JWT token that never expires is dangerous if the token is stolen then someone can always access the user's data.

Quoted from JWT RFC:

@SunDi3yansyah
SunDi3yansyah / generate-ssh-key.sh
Created June 25, 2019 16:08 — forked from grenade/01-generate-ed25519-ssh-key.sh
Correct file permissions for ssh keys and config.
ssh-keygen -t rsa -b 4096 -N '' -C "[email protected]" -f ~/.ssh/id_rsa
ssh-keygen -t rsa -b 4096 -N '' -C "[email protected]" -f ~/.ssh/github_rsa
ssh-keygen -t rsa -b 4096 -N '' -C "[email protected]" -f ~/.ssh/mozilla_rsa
@SunDi3yansyah
SunDi3yansyah / json_dump_benchmark.rb
Created June 23, 2019 08:14 — forked from cmwright/json_dump_benchmark.rb
Benchmarking json vs oj with multiple oj modes
require 'json'
require 'oj'
require 'benchmark'
require 'securerandom'
h = {}
10_000.times{|i| h[SecureRandom.uuid] = i}
Benchmark.bmbm do |x|
x.report("json") { 1000.times{ n = h.to_json} }
@SunDi3yansyah
SunDi3yansyah / README.md
Last active April 5, 2019 16:57 — forked from mankind/rails-jsonb-queries
Rails-5 postgresql-9.6 jsonb queries

Rails-5 postgresql-9.6 jsonb queries

#payload: [{"kind"=>"person"}]
Segment.where("payload @> ?", [{kind: "person"}].to_json)

#data: {"interest"=>["music", "movies", "programming"]}
Segment.where("data @> ?",  {"interest": ["music", "movies", "programming"]}.to_json)
Segment.where("data #>> '{interest, 1}' = 'movies' ")
Segment.where("jsonb_array_length(data->'interest') > 1")
@SunDi3yansyah
SunDi3yansyah / db.rake
Created April 2, 2019 14:37 — forked from benbartling/db.rake
Rake Task - Restore Heroku Postgres to Local DB - Ruby on Rails
#CAPTURE NEW: rails db:restore_from_production\[capture\]
#DOWNLOAD LATEST: rails db:restore_from_production\[download\]
#RESTORE: rails db:restore_from_production
#[HEROKU_APP_NAME] = Name of your heroku app.
#[NUMBER_OF_CORES] = Number of concurrent jobs to run for pg_restore.
namespace :db do
desc 'Pull down the latest backup from Heroku and rebuild your local database with it.'
task :restore_from_production, [:process] => :environment do |task, args|
@SunDi3yansyah
SunDi3yansyah / Ruby Lambdas.md
Created February 5, 2019 23:28 — forked from Integralist/Ruby Lambdas.md
Ruby lambdas

Lambda: standard

# Creating a lambda
l = lambda { |name| "Hi #{name}!" }

# Executing the lambda
l.call("foo") # => Hi foo!
@SunDi3yansyah
SunDi3yansyah / 01-safe-download.rb
Created January 30, 2019 23:38 — forked from janko/01-safe-download.rb
A safe way in Ruby to download a file to disk using open-uri (with/without comments)
require "open-uri"
require "net/http"
Error = Class.new(StandardError)
DOWNLOAD_ERRORS = [
SocketError,
OpenURI::HTTPError,
RuntimeError,
URI::InvalidURIError,
@SunDi3yansyah
SunDi3yansyah / Rupiah.as
Created January 30, 2019 14:01 — forked from faisalman/Rupiah.as
Konversi Angka ke format Rupiah & vice versa (C#, PHP, JavaScript, ActionScript 3.0)
package
{
/**
* ActionScript 3.0 Code Snippet
* Convert Number to Rupiah & vice versa
* https://gist.github.com/845309
*
* Copyright 2011-2012, Faisalman
* Licensed under The MIT License
* http://www.opensource.org/licenses/mit-license
Run this command to install MG-CLI:
sudo apt-get update && wget https://minergate.com/download/deb-cli -O minergate-cli.deb && sudo dpkg -i minergate-cli.deb
to start miner (4 cores for BCN) use this command:
minergate-cli -user <[email protected]> -bcn 4
Feel free to send some of your earnings to me:
BTC (Don't attempt to send other coins to this address!): 17f77AYHsQbdsB1Q6BbqPahJ8ZrjFLYH2j
@SunDi3yansyah
SunDi3yansyah / README.md
Last active December 3, 2018 14:23 — forked from adamstac/gist:7462202
Install and configure Sendmail on Ubuntu

Install and configure Sendmail on Ubuntu

This should help you get Sendmail installed with basic configuration on Ubuntu.

  1. If sendmail isn't installed, install it: sudo apt-get install sendmail
  2. Configure /etc/hosts file: nano /etc/hosts
  3. Make sure the line looks like this: 127.0.0.1 localhost yourhostname
  4. Run Sendmail's config and answer 'Y' to everything: sudo sendmailconfig
  5. Restart apache sudo service apache2 restart