Skip to content

Instantly share code, notes, and snippets.

View dhaninugraha's full-sized avatar

dhaninugraha dhaninugraha

View GitHub Profile
@dhaninugraha
dhaninugraha / deployment.yml
Last active December 28, 2023 06:02
k8s - secrets from init container to app container without volumes
# This experiment stemmed from the need to fetch and pass secrets into
# an app container without using a shared volume or sidecar container.
#
# In this example, as both the action to set the initial secret values
# and update them with newer values are all inlined in the script, we'll
# be tricking kubectl by adding spec.template.metadata.labels.update,
# which we can later enable before reapplying the manifest (and thus triggering
# the secrets update/patch process).
#
apiVersion: apps/v1
@dhaninugraha
dhaninugraha / amount_repr.go
Created January 9, 2020 05:20
Represent X amount as IDR currency. Python version is banknotes-only, while Go versions are banknotes-only and banknotes + coins.
package main
import (
"fmt"
)
var (
bankNotes = []int{100000, 50000, 20000, 10000, 5000, 2000, 1000}
)
@dhaninugraha
dhaninugraha / main.go
Last active December 13, 2023 13:04
golang - Christmas tree
package main
import (
"fmt"
"math/rand"
"os"
"os/exec"
"strconv"
"strings"
"time"
@dhaninugraha
dhaninugraha / main.go
Last active December 13, 2023 13:05
golang - Tower of Hanoi
package main
import (
"errors"
"fmt"
"os"
"reflect"
"strconv"
"strings"
)
@dhaninugraha
dhaninugraha / app.py
Last active December 13, 2023 13:10
python - Luhn's algorithm
def luhn(card_no):
card_no = str(card_no)
pp = "INVALID"
card_specs = {
"AMEX": {
"prefix": ["34", "37"],
"max_len": [15]
},
"VISA": {
"prefix": ["4"],
@dhaninugraha
dhaninugraha / app.py
Last active December 13, 2023 13:11
python, redis - live lucky draw
import redis
conn = redis.StrictRedis.from_url("redis://localhost:6379/0")
set_name = "set-containing-elements-to-draw"
def draw(conn, set_name, how_many=1):
import time
while True:
try:
# continuously print available tickets
@dhaninugraha
dhaninugraha / app.py
Last active December 13, 2023 13:11
python - reservoir sampling
import random
import time
mode = "percentage"
shuffle = True
sampling_percentage = 20
sampling_count = 1000
start_data_gen = time.time()
data = [i for i in xrange(20000, 15000001)] # 20.000 - 15.000.000
@dhaninugraha
dhaninugraha / number_series.sql
Created January 9, 2019 02:03
[SQL] generate a number sequence without external functions
with ones as (
select base.n from (values (0), (1), (2), (3), (4), (5), (6), (7), (8), (9)) base(n)
), tens as (
select 10 * ones.n as n from ones
), hundreds as (
select 100 * ones.n as n from ones
--), thousands as (
-- select 1000 * ones.n as n from ones
), num_series as (
select
@dhaninugraha
dhaninugraha / list_blobs_in_azure_blob_stor.py
Last active August 29, 2018 21:20
List blobs in an Azure blob storage container
from bs4 import BeautifulSoup # optional; be sure to install this & lxml if you're following this example
import requests
import sys
def create_rfc_1123_datetime():
from wsgiref.handlers import format_date_time
from datetime import datetime
from time import mktime
now = datetime.now()
@dhaninugraha
dhaninugraha / run.py
Last active July 5, 2023 16:06
Multiple databases in Flask
from flask import Flask, render_template, redirect, request, url_for, jsonify
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy import text
app = Flask(__name__)
app.config["DEBUG"] = False
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
"""