Skip to content

Instantly share code, notes, and snippets.

View strboul's full-sized avatar

Metin Yazici strboul

View GitHub Profile
package main
import (
"flag"
"fmt"
"os"
"os/exec"
"path/filepath"
"strings"
@strboul
strboul / test.py
Created May 19, 2023 13:14
lsof test
# Run
# - python test.py
# - lsof test.log
import time
import os
FILE_NAME = "test.log"
def main():
import string
import random
message = "hello world from python"
# secret = ''.join(random.choices(string.ascii_uppercase + string.digits, k=100))
secret = 'bob'
encrypted = ''.join([chr(ord(a) ^ ord(b)) for a, b in zip(message, secret)])
decrypted = ''.join([chr(ord(a) ^ ord(b)) for a, b in zip(encrypted, secret)])

Keybase proof

I hereby claim:

  • I am strboul on github.
  • I am strboul (https://keybase.io/strboul) on keybase.
  • I have a public key ASB-QR3015IubTjaSubzmM12zzDk8pvITKhfPqr_MJAXGwo

To claim this, I am signing this object:

# RStudio snippets
# https://support.rstudio.com/hc/en-us/articles/204463668-Code-Snippets
# BASE
snippet lib
library(${0})
snippet ifelse
ifelse(${1:condition}, ${2:yes}, ${3:no})
@strboul
strboul / calc_growth.py
Created October 23, 2021 14:57
if a business has $x revenue and $y% fixed growth rate every year, how much revenue will it have in the next $z years?
from pprint import pprint
def calc_growth(revenue, fixed_rate, years):
"""Calculate growth rate
revenue: Initial revenue.
fixed_rate: fixed rate to grow in a year. It's between 0 and 1.
years: number of years.
"""
init_revenue = revenue
@strboul
strboul / import_sql_to_pg.sh
Created July 15, 2021 19:34
Import CSV files into PostgreSQL database
prepare_csv_data_import() {
schema_file="$(<yellow_tripdata.schema.template.sql)"
csv_files=( data/* )
out=""
for csv_file in "${csv_files[@]}"; do
tablename="$(basename "${csv_file%.*}")"
str_schema="${schema_file//\{TABLENAME\}/${tablename}}"
str_copy_query="COPY ${tablename} FROM '/${csv_file}' DELIMITER ',' CSV HEADER;"
out="${out}\n\n${str_schema}\n${str_copy_query}"
done
@strboul
strboul / airline.vim
Created July 5, 2021 13:05
(Retired) vim-airline config - although it's great, it's just too slow and feels clumsy
" vim-airline
Plug 'https://github.com/vim-airline/vim-airline'
Plug 'https://github.com/vim-airline/vim-airline-themes'
let g:airline_theme='bubblegum'
" powerline symbols
let g:airline_powerline_fonts=1
" statusline settings
// We parameterize ApiResponse to specify the type of its data field
interface ApiResponse<T> {
status: "success" | "failure";
data: T;
}
interface User {
id: number
name: string
const sleep = (ms) => {
return new Promise((resolve) => {
setTimeout(resolve, ms);
});
};
const queryDb = async (success) => {
await sleep(3000);
if (!success) {
throw new TypeError();