Skip to content

Instantly share code, notes, and snippets.

View tonespy's full-sized avatar
🙄
Lol...

Abubakar Oladeji tonespy

🙄
Lol...
  • Netherlands
View GitHub Profile
// mockRequestHandler :- Mocks a handler and returns a httptest.ResponseRecorder
func mockRequestHandler(req *http.Request, method string, path string, reqHandler func(w http.ResponseWriter, r *http.Request, param httprouter.Params)) *httptest.ResponseRecorder {
router := httprouter.New()
router.Handle(method, path, reqHandler)
recorder := httptest.NewRecorder()
router.ServeHTTP(recorder, req)
return recorder
}
@tonespy
tonespy / main.go
Created June 23, 2019 12:40
Main file
func main() {
userRoutes := apis.GenerateUserRoutes()
router := router.NewRouter(userRoutes)
addr := ":8540"
log.Println("Listening on", addr)
log.Fatal(http.ListenAndServe(addr, router))
}
@tonespy
tonespy / router.go
Created June 23, 2019 12:21
Router Helper
/*
Route is a struct for handling all routes
*/
type Route struct {
Name string
Method string
Path string
HandlerFunction httprouter.Handle
}
@tonespy
tonespy / user_api.go
Created June 23, 2019 12:12
User Create Endpoint
// ok represents types capable of validating
// themselves.
type ok interface {
OK() error
}
// CreateUser :- Handler for creating a user
// POST /user
func createUser(w http.ResponseWriter, r *http.Request, params httprouter.Params) {
var user models.User
@tonespy
tonespy / user.go
Created June 23, 2019 08:27
User Model
package models
import "strconv"
type missingFieldError string
func (m missingFieldError) Error() string {
return string(m) + " is required"
}
@tonespy
tonespy / logger.go
Created June 23, 2019 08:18
API Logger
package app
import (
"log"
"net/http"
"time"
"github.com/julienschmidt/httprouter"
)
@tonespy
tonespy / pr.md
Created May 1, 2018 07:04 — forked from piscisaureus/pr.md
Checkout github pull requests locally

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = [email protected]:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:

@tonespy
tonespy / Usage.swift
Last active March 8, 2018 10:03
MutableStrings
let aggreementLabel: UILabel = {
let label = UILabel()
label.font = UIFont.systemFont(ofSize: 15)
label.textColor = UIColor.textfieldTextColor()
label.numberOfLines = 0
let titles = ["I agree to the", " terms and conditions", " and confirm that the information I have provided is accurate."]
let colors = [UIColor.authTextGray(), UIColor.appColor(), UIColor.authTextGray()]
let attributedText = NSMutableAttributedString().generateMultipleColorString(sentences: titles, colors: colors)
if let attributedText = attributedText {
label.attributedText = attributedText
@tonespy
tonespy / GenerateMultipleColorString.swift
Last active March 8, 2018 10:04
NSMutableAttributedString Implementation
import UIKit
extension NSMutableAttributedString {
func generateMultipleColorString(sentences: [String], colors: [UIColor]) -> NSMutableAttributedString? {
let attributedText = NSMutableAttributedString()
var count = 0
while count < sentences.count {
let minAttr = NSMutableAttributedString(string: sentences[count])
@tonespy
tonespy / gist:8228f771912300732c41901b99dd0c97
Created December 31, 2017 16:25 — forked from giannisp/gist:ebaca117ac9e44231421f04e7796d5ca
Upgrade PostgreSQL 9.6.5 to 10.0 using Homebrew (macOS)
After automatically updating Postgres to 10.0 via Homebrew, the pg_ctl start command didn't work.
The error was "The data directory was initialized by PostgreSQL version 9.6, which is not compatible with this version 10.0."
Database files have to be updated before starting the server, here are the steps that had to be followed:
# need to have both 9.6.x and latest 10.0 installed, and keep 10.0 as default
brew unlink postgresql
brew install [email protected]
brew unlink [email protected]
brew link postgresql