Skip to content

Instantly share code, notes, and snippets.

View wulymammoth's full-sized avatar
processing unit

David W wulymammoth

processing unit
View GitHub Profile
'queue implemented with a list (dyanmic array) with O(n) time operations'
class Queue:
def __init__(self):
self.data = [] # using a python list here instead of array (we need dynamic sizing)
def enqueue(self, item):
self.data.append(item)
def dequeue(self):
remaining = self.data[1:] # slices from index 1 to the end of the list
@wulymammoth
wulymammoth / recursion.exs
Last active January 7, 2022 04:14
nth-Fibonacci (in elixir) : naive and TCO (tail-call optimized)
# naive will not work for larger values of N
defmodule FibNaive do
def n(0), do: 0
def n(1), do: 1
def n(2), do: 1
def n(n), do: n(n - 1) + n(n - 2)
end
# tail-call optimized (employing dynamic programming)
defmodule FibTailCall do
version: "3.7"
services:
db:
environment:
- POSTGRES_USER=postgres
image: postgres
ports:
- "5432:5432"
restart: always

FWIW: I didn't produce the content presented here (the outline from Edmond Lau's book). I've just copy-pasted it from somewhere over the Internet, but I cannot remember what exactly the original source is. I was also not able to find the author's name, so I cannot give him/her the proper credits.


Effective Engineer - Notes

What's an Effective Engineer?

/*
* nth-fib in both recursive and iterative (dynamic programming)
*
* 0, 1, 1, 2, 3, 5, 8, 13, 21
*/
// time: O(2^N) -- derived from branches (2) to the power of it's maximum depth (N); it is EXPONENTIAL
// space: O(N) -- derived from space used on the call-stack, the recursion will go down to N
function fibRecursive(n) {
if (n <= 1) return n;
@wulymammoth
wulymammoth / how-to-copy-aws-rds-to-local.md
Created April 26, 2020 02:43 — forked from syafiqfaiz/how-to-copy-aws-rds-to-local.md
How to copy production database on AWS RDS(postgresql) to local development database.
  1. Change your database RDS instance security group to allow your machine to access it.
    • Add your ip to the security group to acces the instance via Postgres.
  2. Make a copy of the database using pg_dump
    • $ pg_dump -h <public dns> -U <my username> -f <name of dump file .sql> <name of my database>
    • you will be asked for postgressql password.
    • a dump file(.sql) will be created
  3. Restore that dump file to your local database.
    • but you might need to drop the database and create it first
    • $ psql -U <postgresql username> -d <database name> -f <dump file that you want to restore>
  • the database is restored
@wulymammoth
wulymammoth / values_pointers.go
Created April 22, 2020 06:58 — forked from josephspurrier/values_pointers.go
Golang - Asterisk and Ampersand Cheatsheet
/*
********************************************************************************
Golang - Asterisk and Ampersand Cheatsheet
********************************************************************************
Also available at: https://play.golang.org/p/lNpnS9j1ma
Allowed:
--------
p := Person{"Steve", 28} stores the value
function add(a, b) {
return a + b;
}
const cases = [
// [a, b], expectedAnswer
[[1, 2], 3], // 3
[[5, 5], 10],// 10
[[-1, 2], 1], // 1
[[1, 1], 2]
@wulymammoth
wulymammoth / poodir-notes.md
Created July 19, 2019 06:51 — forked from elissonmichael/poodir-notes.md
Notes From "Practical Object-Oriented Design In Ruby" by Sandi Metz

Chapter 1 - Object Oriented Design

The purpose of design is to allow you to do design later, and it's primary goal is to reduce the cost of change.

SOLID Design:

  • Single Responsibility Principle: a class should have only a single responsibility
  • Open-Closed Principle: Software entities should be open for extension, but closed for modification (inherit instead of modifying existing classes).
  • Liskov Substitution: Objects in a program should be replaceable with instances of their subtypes without altering the correctness of that program.
  • Interface Segregation: Many client-specific interfaces are better than one general-purpose interface.
#!/usr/bin/env python
"""
Very simple HTTP server in python.
Usage::
./simple_server.py [<port>]
Send a GET request::
curl http://localhost