Skip to content

Instantly share code, notes, and snippets.

View inscapist's full-sized avatar

Felx inscapist

  • Penang, Malaysia
View GitHub Profile
@inscapist
inscapist / compress-pdf-with-gs.md
Created January 19, 2016 10:19 — forked from guifromrio/compress-pdf-with-gs.md
Compress PDF files with ghostscript

This can reduce files to ~15% of their size (2.3M to 345K, in one case) with no obvious degradation of quality.

ghostscript -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/printer -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf input.pdf

Other options for PDFSETTINGS:

  • /screen selects low-resolution output similar to the Acrobat Distiller "Screen Optimized" setting.
  • /ebook selects medium-resolution output similar to the Acrobat Distiller "eBook" setting.
  • /printer selects output similar to the Acrobat Distiller "Print Optimized" setting.
  • /prepress selects output similar to Acrobat Distiller "Prepress Optimized" setting.
@inscapist
inscapist / gist:608d3c52a84cac6a254c
Created February 23, 2016 03:30
logrotate for production log
/home/ubuntu/lending_platform/log/production.log {
weekly
missingok
rotate 5
compress
delaycompress
notifempty
create 0644 ubuntu ubuntu
maxsize 2M
}
@inscapist
inscapist / join_table.sql
Created June 22, 2016 09:25
SQL example for self-join
SELECT
prev.investment_id,
prev.from as prev_from,
prev.to as prev_to,
next.from as next_from,
next.to as next_to,
to_date(cast(prev.created_at as TEXT), 'YYYY-MM-DD') as prev_created_at,
to_date(cast(next.created_at as TEXT), 'YYYY-MM-DD') as next_created_at
FROM investment_state_transitions as prev
INNER JOIN investment_state_transitions as next
@inscapist
inscapist / reinvest_reporter.rb
Created June 22, 2016 09:27
How to get the repayment rollover number
class ReinvestReporter
attr_accessor :investor_hash, :investor_states, :loan_hash, :loan_states, :loan_assignment
def initialize
investor_vars = calc_investor_variables
@investor_hash = investor_vars[0]
@investor_states = investor_vars[1]
loan_vars = calc_loan_variables
@loan_hash = loan_vars[0]
@loan_states = loan_vars[1]
@inscapist
inscapist / time_traveller.rb
Last active August 22, 2016 20:58
Time Travel (Memento Pattern) SQL queries, using state_machine and state_machine_transition record
module ReportersCommon::TimeTraveller
def investment_ids_for_state(state, date)
available_states = Set.new [
Investment::PENDING_BID,
Investment::CONFIRMED_BID,
Investment::ACTIVE,
Investment::COMPLETED,
Investment::DEFAULT,
Investment::CANCELLED,
Investment::EXPIRED_BID
@inscapist
inscapist / setup.md
Created August 27, 2016 10:34 — forked from kpheasey/setup.md
WSL, RVM & RubyMine; ubuntu on windows, bash on windows

Add inbound firewall rule for TCP 2222

  • Windows 10 has 2 new services, SSH Server Proxy and SSH Server Broker which will already be bound to port 22
  • Do not allow public connection on this rule, WSL is not proven safe

ConEmu

Add as cmd startup with bash.exe --login

Install the SSH server and some Rails essentials libraries in bash

sudo apt-get update && sudo apt-get upgrade -y
@inscapist
inscapist / Dockerfile
Last active April 11, 2020 08:32
Docker + Rails configuration + Docker Sync
# This Dockerfile is intended to build a production-ready app image.
#
# This is not required for development environments
FROM sagittaros/rails-base:latest
MAINTAINER Felix Tioh <felix.tioh@crowdo.com>
COPY . /app
WORKDIR /app
EXPOSE 5000
@inscapist
inscapist / clear-cache.sh
Created October 3, 2016 09:03
free up memory cache (Ubuntu)
sync; sudo echo 3 > /proc/sys/vm/drop_caches
@inscapist
inscapist / privatize-s3-bucket.sh
Last active November 8, 2016 03:42
privatize s3 buckets that were made public, using boto. "pip install boto"
#!/usr/bin/env python
#remove public read right for all keys within a directory
#usage: ./privatize-s3-bucket.sh bucketName folderName
# env AWS_ACCESS_KEY_ID=$aws_key \
# AWS_SECRET_ACCESS_KEY=$aws_secret \
# ./privatize-s3-bucket.sh cwd-p2p-uploads document_uploads/user
@inscapist
inscapist / getFirafonts.sh
Created March 23, 2017 04:11 — forked from muammar/getFirafonts.sh
Download and install Fira fonts in Linux or Mac OS X
#!/bin/bash
## cf from http://programster.blogspot.com/2014/05/ubuntu-14-desktop-install-fira-sans-and.html
cd /tmp
# install unzip just in case the user doesn't already have it.
if [[ `uname` = Linux ]]; then
sudo apt-get install unzip -y
wget "http://www.carrois.com/downloads/fira_4_1/FiraFonts4106.zip"