Skip to content

Instantly share code, notes, and snippets.

View tonyfabeen's full-sized avatar

Tony Fabeen tonyfabeen

View GitHub Profile
# Given a phone number that contains digits from 2–9, find all possible letter
# combinations the phone number could translate to.
#
# Example
# Input: "56"
# Output:["jm","jn","jo","km","kn","ko","lm","ln","lo"]
#
# Approach explanation
# All possible combinations: backtracking
# input.size * number of letters => 5,6 => 3*3 => 9
@tonyfabeen
tonyfabeen / main.go
Created March 19, 2021 18:23
Create a new Bitcoin Wallet along with a new address
package main
import (
"crypto/sha256"
"encoding/hex"
"errors"
"fmt"
"io"
"github.com/shengdoushi/base58"
sealed trait Expr
case class BinOp(left: Expr, op:String, right: Expr) extends Expr
case class Literal(value: Int) extends Expr
case class Variable(name: String) extends Expr
trait ExprParser[T] { def parse(s: String): T }
object ExprParser {
implicit object ParseLiteral extends ExprParser[Literal] {
def parse(s: String): Literal = Literal(s.toInt)
}
@tonyfabeen
tonyfabeen / array.go
Created February 2, 2020 11:09
Dynamic Array in Golang
package array
const DefaultCapacity int = 10
type Array struct {
capacity int
size int
items []interface{}
}
@tonyfabeen
tonyfabeen / trie.py
Created January 30, 2019 19:01
Trie Data Structure in Python
class Node():
def __init__(self):
self.children = {}
self.last = False
def __str__(self):
str(self.children.keys())
class Trie():
def __init__(self):
@tonyfabeen
tonyfabeen / pascal_triangle.rb
Created September 9, 2018 16:50
pascal triangle (naive)
require 'test/unit'
#Every number in Pascal's triangle is calculated by adding the numbers to the left and right of it from
#the row above it. For example, the first 4 in the 5th row is found by
#adding the 1 and the 3 from above it in the 4th row.
#
#Write a function pascal(n) that calculates the nth row of Pascal's Triangle,
#and return it as an array of integers.
def solution(n)
@tonyfabeen
tonyfabeen / .env.example
Created March 8, 2018 20:36
DotEnv in Golang
KEY_A=value-a
KEY_B=value-b
KEY_C=value-c
DB_HOST=postgres.database.com
DB_PASSWORD=dr.i,G<I=!B3f[U8Qg%z9oP}FqYn\r
@tonyfabeen
tonyfabeen / bst.go
Created March 6, 2018 20:53
BST in golang
package main
import "log"
type Node struct {
Left *Node
Right *Node
Value int
}
@tonyfabeen
tonyfabeen / avl.rb
Created March 3, 2017 11:53
Avl Tree in Ruby
# Node
class Node
attr_accessor :value,
:height,
:left,
:right
def initialize(value = nil, height = 0)
@value = value
@height = height
http {
server {
location /render_imgur {
mruby_content_handler_code '
images_from_imgur = ["OiZvLe0b", "3xEanY9b", "JedUbc1b"]