Skip to content

Instantly share code, notes, and snippets.

View idoqo's full-sized avatar

Michael Okoko idoqo

View GitHub Profile
@idoqo
idoqo / db-middleware.go
Created July 24, 2020 16:48
Middleware to send a database instance as chi middleware
func dbContext(db database.Database) func(next http.Handler) http.Handler {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ctx := context.WithValue(r.Context(), databaseKey, db)
next.ServeHTTP(w, r.WithContext(ctx))
})
}
}
/* USAGE*/
@idoqo
idoqo / chi-walker.go
Created June 25, 2020 13:37
save chi routes to a txt file
package main
import (
"fmt"
"net/http"
"os"
"strings"
"github.com/go-chi/chi"
"github.com/go-chi/chi/middleware"
@idoqo
idoqo / cmd.schemagen.main.go
Created June 24, 2020 10:32
convert a moira dto struct to its json equivalent
package main
import (
"encoding/json"
"fmt"
"github.com/moira-alert/moira/api/dto"
"os"
"github.com/alecthomas/jsonschema"
)
@idoqo
idoqo / intset.go
Created April 20, 2020 17:34
A simple golang set implementation (i.e elements should be unique)
package main
import (
"fmt"
)
type numSet map[int32]struct{}
func (s numSet) add(n int32) {
s[n] = struct{}{}
<?php
function convertDigit($digit){
switch($digit){
case "0": return "zero";
case "1": return "one";
case "2": return "two";
case "3": return "three";
case "4": return "four";
case "5": return "five";
case "6": return "six";
@idoqo
idoqo / mysql-docker.sh
Created August 29, 2019 15:34 — forked from spalladino/mysql-docker.sh
Backup and restore a mysql database from a running Docker mysql container
# Backup
docker exec CONTAINER /usr/bin/mysqldump -u root --password=root DATABASE > backup.sql
# Restore
cat backup.sql | docker exec -i CONTAINER /usr/bin/mysql -u root --password=root DATABASE
class Student:
def __init__(self, name, age):
fname = name.strip()+".txt"
student_file = open(fname, 'w')
student_file.write("Name: %s \n" % (name))
student_file.write("Age: %d \n" % (age))
student_file.close()
self.student_file = fname
self.name = name
@idoqo
idoqo / auto-deploy.php
Created June 7, 2018 12:11
PHP-Based Auto deploy script depending on github hooks
<?php
/**
* GIT DEPLOYMENT SCRIPT
*
* Used for automatically deploying websites via GitHub
*
*/
// array of commands
$commands = array(