Skip to content

Instantly share code, notes, and snippets.

@khun84
khun84 / Ruby Snippets
Last active August 20, 2022 06:31
Ruby snippets
- concurrent thread pool
@khun84
khun84 / Nodejs Snippet
Last active August 20, 2022 01:44
Nodejs snippet
- sleep
- pipeline
- parallel task
@khun84
khun84 / install-libv8.md
Created April 22, 2022 03:06
Fixing libv8 installation

Basically we just need to do the following

# 1. Install v8 ourselves
$ brew install v8-315
# 2. Install libv8 using the v8 binary we just installed
$ gem install libv8 -v '3.16.14.19' -- --with-system-v8
# 3. Install therubyracer using the v8 binary we just installed
$ gem install therubyracer -- --with-v8-dir=/usr/local/opt/v8@315 # your path could be different, e.g. /usr/local/opt/v8@3.15
# 4. Install the remaining dependencies
@khun84
khun84 / kafka-ruby.md
Last active December 19, 2022 13:54
Kafka
require 'kafka'
require 'avro_turf/messaging'

kaf_broker = "from-ur-credentials"
kaf_api_key = "from-ur-credentials"
kaf_api_secret = "from-ur-credentials"
schema_url = "from-ur-credentials"
schema_api_key = "from-ur-credentials"
schema_api_secret = "from-ur-credentials"
@khun84
khun84 / holistics-jobs-export.rb
Last active January 19, 2022 02:31
Holistics jobs export
require 'json'
require 'csv'
data = `pbpaste`
data = JSON.parse(data);nil
data = data.select{|d| d.dig('schedule', 'paused') == false && d['source_type'] == 'dbtable' };nil
keys = [
'title',
'description',
'src_db', # from_ds_name
@khun84
khun84 / wireshark.md
Created October 21, 2021 20:17 — forked from EddiG/wireshark.md
How to decrypt SSL/TLS traffic in Wireshark on MacOS

The main point is to save the SSL/TLS keys those used by the web browser (SSLKEYLOGFILE=/tmp/tmp-google/.ssl-key.log).
In the example below we run brand new instance of Google Chrome (--user-data-dir=/tmp/tmp-google do the trick):
SSLKEYLOGFILE=/tmp/tmp-google/.ssl-key.log /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --user-data-dir=/tmp/tmp-google
Then run the Wireshark and open the Preferences -> Protocols -> SSL, where we put the path to the SSL keys log file into the (Pre)-Master-Secret log filename field.
Now all SSL/TLS traffic from this browser instance will be decrypted.

@khun84
khun84 / README.md
Created October 21, 2021 20:17 — forked from felixhammerl/README.md
Write TLS keys system-wide in macOS via SSLKEYLOGFILE and launchd
  1. Put tlskeylogger.plist at ~/Library/LaunchAgents/tlskeylogger.plist
  2. launchctl load ~/Library/LaunchAgents/tlskeylogger.plist, so it will load on the next restart
  3. launchctl start ~/Library/LaunchAgents/tlskeylogger.plist, so it will load the environment variable immediately
  4. Restart your browser(s)
  5. See how TLS keys are being written to ~/.tlskeyfile via tail -f ~/.tlskeyfile
@khun84
khun84 / postgresql-replication.md
Last active October 21, 2021 02:16
Postgresql

Playbook to setup physical replication in Postgresql 13

  1. Install the postgresql 13 for replica on another instance. sudo apt-get install postgresql-13. Install binary extension if theres any, ie sudo apt-get install postgresql-13-postgis-3
  2. Create a user in master server for replication connection. create user replica with password <password>
  3. Change the following postgres config in the master server
# in /etc/postgresql/13/main/postgres.conf

max_wal_senders = 5
synchronous_standby_names = 'pgslave001' # or any other you prefer
@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.

@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)