Skip to content

Instantly share code, notes, and snippets.

View prihandi's full-sized avatar

Dwi Prihandi prihandi

View GitHub Profile
@prihandi
prihandi / hls.sh
Created November 9, 2024 03:44 — forked from stenuto/hls.sh
HLS ffmpeg script
#!/bin/bash
# Function to display usage information
usage() {
echo "Usage: $0 /path/to/input.mp4 [ /path/to/output_directory ]"
exit 1
}
# Check if at least one argument (input file) is provided
if [ $# -lt 1 ]; then
@prihandi
prihandi / tsv_streaming.ex
Last active July 8, 2025 03:47
using NimbleCSV with file stream for parsing Tab separated CSV, because NimbleCSV.Spreadsheet.parse_stream didn't work
NimbleCSV.define(TabSeparatedCSVParser,
separator: "\t",
escape: "\"",
encoding: :utf8,
trim_bom: false
)
defmodule Parser(input_file) do
def run(input_file) do
input_file
@prihandi
prihandi / s3_downloads.ex
Created November 29, 2023 03:07
Elixiir S3 Downloads no dependency
defmodule S3Downloads do
@moduledoc """
Use at your own risk.
Code heavily borrowed from:
- https://github.com/ex-aws/ex_aws/blob/main/lib/ex_aws/auth.ex
- https://gist.github.com/chrismccord/37862f1f8b1f5148644b75d20d1cb073
"""
@prihandi
prihandi / config_helper.ex
Created March 10, 2023 01:20
Helper functions to resolve config from environment variables.
defmodule ConfigHelpers do
@type config_type :: :str | :int | :bool | :json
@doc """
Get value from environment variable, converting it to the given type if needed.
If no default value is given, or `:no_default` is given as the default,
an error is raised if the variable is not set.
"""
@spec get_env(String.t(), :no_default | any(), config_type()) :: any()
@prihandi
prihandi / check_no_of_database_pool.exs
Last active March 9, 2023 08:47
Check number of realtime database pool without relying on config
DBConnection.ConnectionPool.Supervisor
|> Supervisor.which_children()
|> Enum.each(fn {_, pid, _, _} ->
[
{{_adapter_prot, starter_pid, _worker_no}, _worker_pid, :worker, [_conn_module]}
| _
] = children_list = Supervisor.which_children(pid)
repo_name =
starter_pid
# Generate EDDSA public key and private key
{public_key, priv_key} = :crypto.generate_key(:eddsa, :ed25519)
# Payload that need to be signed
payload = "some_string"
# Generate signature with both public key and private key
signature = :public_key.sign(payload, :none, {:ed_pri, :ed25519, public_key, priv_key}, [])
# Verify signature with public key
@prihandi
prihandi / isbn_13.rb
Created January 15, 2018 04:51
Calculate the 13th number of 12 chars ISBN numbers
def create_isbn13(isbn_12)
isbn_arr = isbn_12.to_s.chars.map(&:to_i)
sumarr = isbn_arr.each.with_index.inject(0) { |sum,(value,index)| index.even? ? sum+(value*1) : sum+(value*3) }
last_digit = (10 - (sumarr % 10)) % 10
isbn13 = isbn_12.to_s + last_digit.to_s
end
import (
"fmt"
"math/rand"
"regexp"
"golang.org/x/crypto/bcrypt"
)
func ValidatePassword(hashedPassword, plainPassword string) (isValid bool) {
hashedPasswordInBytes := []byte(hashedPassword)
plainPasswordInBytes := []byte(plainPassword)
def cetakPola(size=1)
arr = Array.new(size) { Array.new(size) }
chars = (size**2).to_s.size
maks = size-1
x = maks / 2
y = maks / 2
(1..size).each do |ps|
start = (ps-1)**2 + 1
ends = ps**2

Ruby example question

Level of difficulty : Easy

Given two class definition, Car and Bus :

    class Car
      def honk
        puts "Teen, Teen"
 end