Skip to content

Instantly share code, notes, and snippets.

Avatar
🔮
Focusing

Dom Hallan polyglotdev

🔮
Focusing
View GitHub Profile
@polyglotdev
polyglotdev / notes
Created February 24, 2023 23:22
Use the existing admin CLI commands implementation in consolidated services
View minstack.go
// leetcode min stack
// https://leetcode.com/problems/min-stack/
type MinStack struct {
stack []int
minStack []int
}
/** initialize your data structure here. */
func Constructor() MinStack {
return MinStack{stack: make([]int, 0), minStack: make([]int, 0)}
@polyglotdev
polyglotdev / dynamic_reducer.py
Last active January 3, 2023 18:21
`dynamic_reducer` takes a list integers and an operator and does maths on list to sum integers.
View dynamic_reducer.py
def dynamic_reducer(numbers, operator):
result = numbers[0]
for i in range(1, len(numbers)):
if operator == "+":
result += numbers[i]
elif operator == "-":
result -= numbers[i]
elif operator == "*":
result *= numbers[i]
elif operator == "/":
@polyglotdev
polyglotdev / account_test.go
Created December 12, 2022 02:35
Testing using gomock
View account_test.go
func TestGetAccountAPI(t *testing.T) {
account := randomAccount()
testCases := []struct {
name string
accountID int64
buildStubs func(store *mockdb.MockStore)
checkResponse func(t *testing.T, recorder *httptest.ResponseRecorder)
}{
{
View account.sql.go
// Code generated by sqlc. DO NOT EDIT.
// source: account.sql
package db
import (
"context"
)
const createAccount = `-- name: CreateAccount :one
@polyglotdev
polyglotdev / main.go
Created October 27, 2022 12:22
confusing slices in go
View main.go
package main
import "fmt"
func main() {
x := make([]int, 0, 5)
x = append(x, 1, 2, 3, 4)
fmt.Println("x:", x) // [1 2 3 4]
fmt.Printf("x's length: %d\nx's capacity: %d", len(x), cap(x)) // x's length: 4 x's capacity: 5
View index.html
<html>
<body>
<h1>CatPhotoApp</h1>
<main>
<h2>Cat Photos</h2>
<!-- TODO: Add link to cat photos -->
<p>
Click here to view more
<a target="_blank" href="https://freecatphotoapp.com">cat photos</a>.
</p>
View reverse_int.py
def reverse_int(my_num):
convert_to_list = str(my_num).split(' ')
rev_positive_int = ''
str_abs = ''
if(my_num <= 0):
reversed_value = ''
for i in convert_to_list:
abs_num = abs(int(i))
str_abs += str(abs_num)
@polyglotdev
polyglotdev / olympic_medal.rb
Created August 12, 2022 19:14
mixins example in Ruby
View olympic_medal.rb
# frozen_string_literal: true
# OlympicMedal is class that represents an olympic medal
class OlympicMedal
# <, <=, >=, >, ==, !=, <=>, .between?
include Comparable
MEDAL_VALUES = { Gold: 3, Silver: 2, Bronze: 1 }.freeze
attr_reader :type
@polyglotdev
polyglotdev / pry-output
Created March 5, 2022 20:15
Pry output for ORM exercise
View pry-output
❯ rails console
Running via Spring preloader in process 16338
Loading development environment (Rails 6.1.4.6)
[1] pry(main)> help
Help
help Show a list of commands or information about a specific command.
Context
cd Move into a new context (object or scope).
find-method Recursively search for a method within a class/module or the current namespace.