Skip to content

Instantly share code, notes, and snippets.

@khun84
khun84 / encryption-decryption.rb
Created May 7, 2018 11:29 — forked from gevans/encryption-decryption.rb
A couple examples of using asymmetric RSA signing and encryption using Ruby's OpenSSL libraries.
require 'openssl'
key = OpenSSL::PKey::RSA.new(2048)
p encrypted_string = key.public_encrypt('my plaintext string', OpenSSL::PKey::RSA::PKCS1_OAEP_PADDING)
p decrypted_string = key.private_decrypt(encrypted_string, OpenSSL::PKey::RSA::PKCS1_OAEP_PADDING)
@khun84
khun84 / README.md
Created March 1, 2019 15:52 — forked from magnetikonline/README.md
Mac OS X - SSH client host autocomplete.

Mac OS X SSH client autocomplete for hosts

Snippet for ~/.bash_profile, adding hostname autocomplete to ssh.

Extracts host hints from both ~/.ssh/config and /etc/hosts.

function __completeSSHHosts {
	COMPREPLY=()
	local currentWord=${COMP_WORDS[COMP_CWORD]}
	local completeHosts=$(
@khun84
khun84 / service_area_map_exploration.py
Created March 18, 2019 01:55
service_area_map_exploration
import pandas as pd
import folium
# edit this section to project the polygon that you want
pj_geojson = {"type":"Polygon","coordinates":[[[101.6637271,3.070996],[101.6637271,3.204971],[101.5526301,3.204971],[101.5526301,3.070996],[101.6637271,3.070996]]]}
subang_jaya = {"type":"Polygon","coordinates":[[[101.6210431,3.085025],[101.6210431,2.975538],[101.5493918,2.975538],[101.5493918,3.085025],[101.6210431,3.085025]]]}
langat = {"type":"Polygon","coordinates":[[[101.6828061,2.643176],[101.6828061,2.9793898],[101.2863841,2.9793898],[101.2863841,2.643176],[101.6828061,2.643176]]]}
boundary = pj_geojson['coordinates'][0]
boundary2 = subang_jaya['coordinates'][0]
@khun84
khun84 / archive_service_matches.md
Last active July 29, 2019 07:42
Archive Service Match

ServiceMatch table housekeeping

Steps:

  1. Provision snapshot instance with same production spec
  1. Create archived service match table in another namespace
  2. Export service matches that are to be archived (via pg_dump or copy) into flat file (to be performed using psql in one of the prod application instance)
  3. Load archived service matches from flat file into archive table (via pg_restore or copy)
  4. Hard delete service matches to be archived in production DB by using batch strategy
@khun84
khun84 / rvm_ruby_2.3.1_openssl.md
Last active May 27, 2021 02:53
How to install Ruby 2.3.1 using RVM and OpenSSL 1.0.2

Guides

  1. Uninstall and install openssl version 1.0.2. As openssl v1.0.2 is no longer available, I have extracted openssl v1.0.2 and make it available at https://github.com/khun84/homebrew-repo/
brew uninstall --force --ignore-dependencies openssl
brew install khun84/homebrew-repo/openssl
brew cleanup # in case it fails due to permission denied, it can be due to the symlink to be removed is pointing to a non-exist file/directory. Just create the corresponding file or directory and run this command again
  1. After OpenSSL installation, check it using pkg-config --libs openssl. You should see something like -L/usr/local/Cellar/openssl/1.0.2t/lib -lssl -lcrypto
@khun84
khun84 / ruby_google_calendar_api.md
Last active February 4, 2020 03:09
How to implement google calendar api in Ruby

Steps

Somewhat helpful link: https://developers.google.com/api-client-library/ruby/

Go to: https://console.developers.google.com/iam-admin/projects
Click "+Create Project"
Enter a "Project name" and "Project ID" and click "Create"
Under "Library" select "Calendar API"
Click ">Enable"
Return to: https://console.developers.google.com/iam-admin/projects

Click "Service Accounts"

@khun84
khun84 / download_file.rb
Last active August 20, 2022 06:29 — forked from daipresents/example1
Ruby rest-client file upload as multipart
filepath = 'local-filepath'
url = 'web-url'
File.open(filepath, 'w') {|f|
block = proc { |response|
response.read_body do |chunk|
puts "Working on response"
f.write chunk
end
}
RestClient::Request.new(method: :get, url: url, block_response: block).execute
@khun84
khun84 / open-jdk-post-installation.md
Created June 23, 2021 16:20
Open JDK post installation setup
For the system Java wrappers to find this JDK, symlink it with
  sudo ln -sfn /usr/local/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk

openjdk is keg-only, which means it was not symlinked into /usr/local,
because it shadows the macOS `java` wrapper.

If you need to have openjdk first in your PATH run:
  echo 'export PATH="/usr/local/opt/openjdk/bin:$PATH"' >> /Users/Daniel/.bash_profile
@khun84
khun84 / hot-tips.md
Last active November 10, 2021 05:05
Ubuntu package installation

Fix corrupted cached packages

If bump into errors similar to the following during apt install

Preparing to unpack .../libllvm3.8v4_1%3a3.8-2ubuntu3~trusty4_i386.deb ...
Unpacking libllvm3.8v4:i386 (1:3.8-2ubuntu3~trusty4) ...
dpkg: error processing archive /var/cache/apt/archives/libllvm3.8v4_1%3a3.8-2ubuntu3~trusty4_i386.deb (--unpack):
 trying to overwrite '/usr/lib/i386-linux-gnu/libLLVM-3.8.so.1', which is also in package libllvm3.8:i386 1:3.8~+rc3-1~exp1~gd~t
dpkg-deb: error: subprocess paste was killed by signal (Broken pipe)
@khun84
khun84 / letsencrypt_ca_cert.md
Created October 11, 2021 14:09
How to fix letsencrypt expired root cert

The reason of this issue is here => https://www.openssl.org/blog/blog/2021/09/13/LetsEncryptRootCertExpire/

So basically we can just remove the expired cert from the ssl cert file as suggested here => https://www.linuxadictos.com/en/ya-iniciaron-los-problemas-generados-por-el-certificado-dst-root-ca-x3.html

My ssl cert file is located in /etc/ssl/cert.pem. I just need to look for the expired cert and comment it out.

Since Im using ruby 2.3.1 which is using openssl 1.0.2t and I dont want to recompile it, I can use the env var SSL_CERT_FILE to tell which ssl cert i want to use in ruby runtime.