Skip to content

Instantly share code, notes, and snippets.

View satriashp's full-sized avatar
🏠
Working from home

Satria Sahputra satriashp

🏠
Working from home
View GitHub Profile
@satriashp
satriashp / .htaccess
Created July 13, 2018 03:16 — forked from brickgale/.htaccess
Laravel force https for Heroku
#add this on public/.htaccess for Laravel
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
@satriashp
satriashp / .env.travis
Created August 14, 2018 12:47 — forked from qWici/.env.travis
Laravel 5.5 Travis CI config
APP_ENV=testing
APP_KEY=SomeRandomString
DB_CONNECTION=testing
DB_TEST_USERNAME=root
DB_TEST_PASSWORD=
CACHE_DRIVER=array
SESSION_DRIVER=array
QUEUE_DRIVER=sync
@satriashp
satriashp / rails-jsonb-queries
Created August 30, 2018 09:29 — forked from mankind/rails-jsonb-queries
Rails-5 postgresql-9.6 jsonb queries
http://stackoverflow.com/questions/22667401/postgres-json-data-type-rails-query
http://stackoverflow.com/questions/40702813/query-on-postgres-json-array-field-in-rails
#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")
@satriashp
satriashp / 01-safe-download.rb
Created December 13, 2018 07:35 — 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,
@satriashp
satriashp / download-file.js
Created February 4, 2019 09:00 — forked from javilobo8/download-file.js
Download files with AJAX (axios)
axios({
url: 'http://localhost:5000/static/example.pdf',
method: 'GET',
responseType: 'blob', // important
}).then((response) => {
const url = window.URL.createObjectURL(new Blob([response.data]));
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', 'file.pdf');
document.body.appendChild(link);
@satriashp
satriashp / access_postgresql_with_docker.md
Created April 18, 2019 06:55 — forked from MauricioMoraes/access_postgresql_with_docker.md
Allow Docker Container Access to Host's Postgres Database on linux (ubuntu)

You have to do 2 things in order to allow your container to access your host's postgresql database

  1. Make your postgresql listen to an external ip address
  2. Let this client ip (your docker container) access your postgresql database with a given user

Obs: By "Host" here I mean "the server where docker is running on".

Make your postgresql listen to an external ip address

Find your postgresql.conf (in case you don't know where it is)

$ sudo find / -type f -name postgresql.conf

@satriashp
satriashp / ruby_on_rails_deployment.md
Created April 23, 2019 09:26 — forked from zentetsukenz/ruby_on_rails_deployment.md
Deploy Ruby on Rails application with Docker Compose and Capistrano with ease

#Docker

##Files and Folders.

|
|\_ app
|...
|\_ docker
| |
@satriashp
satriashp / 1-Nginx-Unicorn-Rails-DO-Ubuntu-16.md
Created July 10, 2019 03:17 — forked from aquaflamingo/1-Nginx-Unicorn-Rails-DO-Ubuntu-16.md
Ubuntu 16.04 Unicorn+Nginx, PostgreSQL, active_storage, Amazon S3 on Digital Ocean

🚂 Deploy Ubuntu 16.04 Rails Server on Digital Ocean

using Unicorn, Nginx, PostgreSQL, active_storage, Amazon S3. Combined summary of all guides.

💧 1. Basic Droplet/SSH Set Up

Create Droplet: Ubuntu 16.04

Your root password is e-mailed to you.

@satriashp
satriashp / mysql-docker.sh
Created October 4, 2019 03:28 — forked from spalladino/mysql-docker.sh
Backup and restore a mysql database from a running Docker mysql container
# Backup
docker exec CONTAINER /usr/bin/mysqldump -u root --password=root DATABASE > backup.sql
# Restore
cat backup.sql | docker exec -i CONTAINER /usr/bin/mysql -u root --password=root DATABASE
@satriashp
satriashp / mysql-docker.sh
Created October 4, 2019 03:28 — forked from spalladino/mysql-docker.sh
Backup and restore a mysql database from a running Docker mysql container
# Backup
docker exec CONTAINER /usr/bin/mysqldump -u root --password=root DATABASE > backup.sql
# Restore
cat backup.sql | docker exec -i CONTAINER /usr/bin/mysql -u root --password=root DATABASE