Skip to content

Instantly share code, notes, and snippets.

SSL/TLS Handshake (TLS 1.2 with RSA)

One-way SSL

sequenceDiagram
    autonumber
    participant Client
    participant Server
    participant CA as Certificate Authority
@khiet
khiet / github_img_table.js
Last active May 11, 2021 21:07
Format images in table in Github description
const textarea = document.querySelector('textarea[name="pull_request[body]"]');
const text = textarea.value;
const lines = text.split("\n")
const images = lines.filter(line => {
return line.includes("https://user-images");
});
let output = '';
let imgs = images.map(image => {
const match = image.match(/\((.*?)\)/);
@khiet
khiet / private_protected.rb
Last active May 3, 2021 06:54
private and protected in Ruby
class A
def public_message
protected_message
end
def self_protected_message
self.protected_message
end
def self_private_message
@khiet
khiet / maintenance.html
Created August 23, 2019 08:48
ehochef maintenance page based on heroku's
<!doctype html>
<html>
<head>
<meta charset=utf-8>
<meta content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" name=viewport>
<title>Offline for maintenance | ehochef.com </title>
<link rel="shortcut icon" type="image/x-icon" href="https://eho-production.s3-eu-west-1.amazonaws.com/maintenance/favicon.ico">
<style>
html,
body {
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BOARD)
GPIO.setup(7,GPIO.OUT)
# https://www.youtube.com/watch?v=ddlDgUymbxc
# SG90 angle and pulse width
# 0: 0.5 ms
# neutral: 1.5 ms
@khiet
khiet / cookie.js
Created April 24, 2018 14:56
Cookie manipulation in JS
@khiet
khiet / rails-6-redirect-www.rb
Last active July 8, 2020 09:16
Rails 5 redirect root domain to www and vice versa
# example.com => www.example.com
match '(*any)', to: redirect(subdomain: 'www'), via: :all, constraints: { subdomain: false }
# www.example.com => example.com
match '(*any)', to: redirect(subdomain: false), via: :all, constraints: {subdomain: 'www'}
# caveat
# subdomain is anything from 3rd level domain, so for example.co.uk domains the syntax will be the following:
# example.co.uk => www.example.co.uk
match '(*any)', to: redirect(subdomain: 'www.example'), via: :all, constraints: { subdomain: 'example' }
# www.example.co.uk => example.co.uk
#!/bin/bash
BACKUP_DIR="/home/dumps/"
S3_PATH="s3://sunbury-dental-production/dumps/"
# create a dump
mysqldump -u$DB_USER -p$DB_PASSWORD dental_production > /home/dumps/production_dump_$(date +\%m\%d\%y).sql
# delete old dumps
find $BACKUP_DIR -type f -name "mysql_dump_*.sql.gz" -mtime +10 -daystart | xargs rm -rf
time = ARGV[0]
dry_run = ARGV[1] == '--dry'
puts "Killing stale servers older than #{time}"
puts "***DRY RUN***" if dry_run
output = `for i in {1..36}; do echo web$i; ssh deploy@web$i.housetrip.com "ps aux | grep [R]ack" | grep -v "#{time}" | awk '{ print $2 }'; done`
server = nil
output.split("\n").each do |line|
@khiet
khiet / gbgrep
Last active August 29, 2015 13:57 — forked from nas/gbgrep
#!/usr/local/bin/ruby
grep = `git grep -n #{ARGV[0]}`
puts "\n-----------------------------------------------------------"
puts "GREP RESULT"
puts '-----------------------------------------------------------'
puts grep
files = grep.scan /.*\:\d+/