Skip to content

Instantly share code, notes, and snippets.

View prihandi's full-sized avatar

Dwi Prihandi prihandi

View GitHub Profile

#Answer for Formulatrix Software Engineering Object-Oriented Test

I used Java to create this answer.
This answer Implementing a Formulatrix Queue class from an Queue interface that can accept integers for its capacity (defined in Object initialization) The Formulatrix Queue class below also have 2 methods as required in the question (enqueue and dequeue)

This is the code ###Queue.java

# This one for terminal output
<?php
$panjang = 10;
function double_pyramid($limit) {
global $panjang;
if ($limit > 0) {
echo str_repeat(' ', $panjang - $limit ).str_repeat('*', 2 * $limit - 1)."\n";
if ($limit > 1) {
double_pyramid($limit - 1);
echo str_repeat(' ', $panjang - $limit ).str_repeat('*', 2 * $limit - 1)."\n";

Ruby example question

Level of difficulty : Easy

Given two class definition, Car and Bus :

    class Car
      def honk
        puts "Teen, Teen"
 end
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
import (
"fmt"
"math/rand"
"regexp"
"golang.org/x/crypto/bcrypt"
)
func ValidatePassword(hashedPassword, plainPassword string) (isValid bool) {
hashedPasswordInBytes := []byte(hashedPassword)
plainPasswordInBytes := []byte(plainPassword)
@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
# 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 / 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
@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 / 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
"""