Skip to content

Instantly share code, notes, and snippets.

@thegeorgeous
thegeorgeous / table.js
Created September 23, 2020 11:46
Generating an HTML table from JSON data
// From: https://www.valentinog.com/blog/html-table/
let mountains = [
{ name: "Monte Falco", height: 1658, place: "Parco Foreste Casentinesi" },
{ name: "Monte Falterona", height: 1654, place: "Parco Foreste Casentinesi" },
{ name: "Poggio Scali", height: 1520, place: "Parco Foreste Casentinesi" },
{ name: "Pratomagno", height: 1592, place: "Parco Foreste Casentinesi" },
{ name: "Monte Amiata", height: 1738, place: "Siena" }
];
@thegeorgeous
thegeorgeous / LuhnGenerator.java
Created April 13, 2020 19:00
Luhn Number generator
import java.util.Random;
public class LuhnGenerator {
public static String generate(Integer len) {
Random rgen = new Random();
Integer luhnNumber = rgen.nextInt(899999) + 100000;
String code = luhnNumber.toString();
return code + generateCheckSum(code);
}
@thegeorgeous
thegeorgeous / cherry-pick.zsh
Last active December 16, 2019 17:19
Cherry pick zsh script
# Usage
# $ cherry-pick 1898
# This will pick up all commits with 1898 in the commit message
# Can be used to cherry pick commits related to a ticket when creating
# a release branch
cherry-pick() {
mkdir -p tmp;
git log master --grep=$1 --pretty=%h --no-merges > tmp/cherry-pick.txt;
output=$(cat tmp/cherry-pick.txt | sed 's/:.*//');
# place this after nvm initialization!
autoload -U add-zsh-hook
load-nvmrc() {
local node_version="$(nvm version)"
local nvmrc_path="$(nvm_find_nvmrc)"
if [ -n "$nvmrc_path" ]; then
local nvmrc_node_version=$(nvm version "$(cat "${nvmrc_path}")")
if [ "$nvmrc_node_version" = "N/A" ]; then
nvm install
elif [ "$nvmrc_node_version" != "$node_version" ]; then

FWIW: I didn't produce the content presented here (the outline from Edmond Lau's book). I've just copy-pasted it from somewhere over the Internet, but I cannot remember what exactly the original source is. I was also not able to find the author's name, so I cannot give him/her the proper credits.


Effective Engineer - Notes

What's an Effective Engineer?

@thegeorgeous
thegeorgeous / System Design.md
Created November 11, 2019 09:34 — forked from vasanthk/System Design.md
System Design Cheatsheet

System Design Cheatsheet

Picking the right architecture = Picking the right battles + Managing trade-offs

Basic Steps

  1. Clarify and agree on the scope of the system
  • User cases (description of sequences of events that, taken together, lead to a system doing something useful)
    • Who is going to use it?
    • How are they going to use it?
@thegeorgeous
thegeorgeous / logger.js
Last active October 14, 2019 11:57
Logger for Sentry workers
const config = require("./config");
export class Logger {
constructor() {
this.projectId = config.sentry["projectId"];
this.apiKey = config.sentry["apiKey"];
this.secretKey = config.sentry["secretKey"];
this.headers = new Headers();
this.headers.append("User-Agent", "CF/1.0");
this.url = `https://sentry.io/api/${this.projectId}/store/?sentry_version=7&sentry_key=${
@thegeorgeous
thegeorgeous / commit-msg
Created April 23, 2019 10:30
Commit hook to pick the ticket number from branch name and append it to git log summary
#!/usr/bin/env ruby
branch_name = `git symbolic-ref --short HEAD`
if !File.read(ARGV[0]).match?(/fixup!|squash!|\[WIP\]|\[\d+\]/) && branch_name.match?(/\d+/)
story_number = branch_name.match(/\d+/)[0]
if story_number
lines = File.readlines(ARGV[0])
lines[0] = "[#{story_number}] " + lines[0]
File.open(ARGV[0], 'w') { |f| f.write(lines.join) }
end
@thegeorgeous
thegeorgeous / find_replace_describe_rspec.rb
Last active August 11, 2019 07:52
Find and Replace describe instances with RSpec.describe so that config.expose_dsl_globally can be set to false
file_names = Dir['./spec/**/*.rb'] # Get all the ruby files in spec
file_names.each do |file_name|
next if ['./spec/spec_helper.rb', './spec/rails_helper.rb'].include? file_name
text = File.read(file_name)
next if text.include?('RSpec.describe')
new_contents = text.sub(/describe/, 'RSpec.describe')
@thegeorgeous
thegeorgeous / sed_script.sh
Last active April 18, 2017 11:02
Useful Sed Scripts
# Replace multiple whitespaces with a comma
# Example:
# Convert dig answer output into a CSV
sed -i -e 's/ \{1,\}/,/g' file
# Add a character at the end of a file
# Example add comma to the end of a line
sed -i -e 's/$/|/g' abc.txt