Skip to content

Instantly share code, notes, and snippets.

View johnlonganecker's full-sized avatar

John Longanecker johnlonganecker

View GitHub Profile
-- taken from https://www.youtube.com/watch?v=fg24wrRKE8g
import Prelude hiding (Maybe(..), lookup)
data Maybe a = Just a | Nothing
deriving Show
favoriteFoods :: [(String, String)]
favoriteFoods = [("David", "Green Papaya Salad")
,("Becky", "Sorbet")]
@johnlonganecker
johnlonganecker / struct-to-map.go
Last active October 25, 2021 11:28
Convert Struct to Map Example
func ConvertStructToMap(st interface{}) map[string]interface{} {
reqRules := make(map[string]interface{})
v := reflect.ValueOf(st)
t := reflect.TypeOf(st)
for i := 0; i < v.NumField(); i++ {
key := strings.ToLower(t.Field(i).Name)
typ := v.FieldByName(t.Field(i).Name).Kind().String()
@johnlonganecker
johnlonganecker / DumpRequest.go
Created March 8, 2017 18:01
Dump HTTP Request for debugging
import "net/http/httputil"
func (c *Client) DoRequest(r *request) (*http.Response, error) {
req, err := r.toHTTP()
if err != nil {
return nil, err
}
req.Header.Set("User-Agent", c.config.UserAgent)
if r.body != nil {
req.Header.Set("Content-type", "application/json")
@johnlonganecker
johnlonganecker / rabbitmq-smoke-test.sh
Created November 8, 2016 00:25
CF RabbitMQ Smoke Test
#!/bin/bash
# example execution
# ./rmq-smoke-test.sh --api https://<api.mycf.com> --user <usr> --password <password> --org smoke-tests --space the-final-frontier --domain <run.appsdomain.com>
set -e -u
while test $# -gt 0; do
case "$1" in
--api)
@johnlonganecker
johnlonganecker / leaflet-min-zoom-res-based.js
Last active March 9, 2024 14:00
Leaflet minZoom based on screen resolution. Fit up to one globe.
// Get the largest screen dimension
// reason for doing this is a phone may start in portrait then move to landscape
var maxScreenDimension = window.innerHeight > window.innerWidth ? window.innerHeight : window.innerWidth;
// assuming tiles are 256 x 256
var tileSize = 256;
// How many tiles needed to for the largest screen dimension
// I take the floor because I don't want to see more then 1 world
// Use Math.ceil if you don't mind seeing the world repeat