Skip to content

Instantly share code, notes, and snippets.

View kylieCat's full-sized avatar
🏳️‍🌈
Codin them thangs

Kylie Rogers kylieCat

🏳️‍🌈
Codin them thangs
View GitHub Profile
@chilts
chilts / dump.go
Created September 15, 2016 19:53
Dump entire BoltDB to stdout, including Nested Buckets
package main
import (
"fmt"
"log"
"strings"
"time"
"github.com/boltdb/bolt"
)
@iamralch
iamralch / subcommand.go
Created July 4, 2015 15:50
flag package: subcommand example
package main
import (
"flag"
"fmt"
"os"
)
func main() {
askCommand := flag.NewFlagSet("ask", flag.ExitOnError)
@mdwhatcott
mdwhatcott / custom_json.go
Created July 29, 2015 17:15
Example of implementing MarshalJSON and UnmarshalJSON to serialize and deserialize custom types to JSON in Go. Playground: http://play.golang.org/p/7nk5ZEbVLw
package main
import (
"bytes"
"encoding/json"
"fmt"
"strconv"
)
func main() {
@boaz0
boaz0 / main.go
Last active February 10, 2023 07:09
Detect compression type in Golang
package main
import (
"flag"
"log"
"net/http"
"os"
"strings"
)
@pdc
pdc / testy.py
Created September 2, 2011 14:23
Mocking time to do time-sensitive unit tests in Python
import unittest
from mock import *
from datetime import datetime, timedelta
import time # so we can override time.time
mock_time = Mock()
mock_time.return_value = time.mktime(datetime(2011, 6, 21).timetuple())
class TestCrawlerChecksDates(unittest.TestCase):
@patch('time.time', mock_time)
@philpoore
philpoore / time-docker-build.sh
Created September 5, 2018 19:13
Generate JSON output of docker build step timing, useful for profiling
#!/bin/bash
# script: time-docker-build.sh
#
# All command line arguments are passed to docker build command.
#
# usage: ./time-docker-build.sh
#
DATE_FORMAT="+%s"
@robmiller
robmiller / .gitconfig
Created July 17, 2013 07:52
Some useful Git aliases that I use every day
#
# Working with branches
#
# Get the current branch name (not so useful in itself, but used in
# other aliases)
branch-name = "!git rev-parse --abbrev-ref HEAD"
# Push the current branch to the remote "origin", and set it to track
# the upstream branch
publish = "!git push -u origin $(git branch-name)"
@jennyd
jennyd / falcon-logging-middleware.py
Last active February 11, 2024 22:09
Falcon logging middleware
import falcon
import logging
logger = logging.getLogger(__name__)
logger.addHandler(logging.FileHandler('test.log'))
logger.setLevel(logging.INFO)
class ResponseLoggerMiddleware(object):
def process_response(self, req, resp):
logger.info('{0} {1} {2}'.format(req.method, req.relative_uri, resp.status[:3]))
@gabrielfalcao
gabrielfalcao / get-free-tcp-port.py
Created October 31, 2015 18:30
Getting a random free tcp port in python using sockets
# Getting a random free tcp port in python using sockets
def get_free_tcp_port():
tcp = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
tcp.bind(('', 0))
addr, port = tcp.getsockname()
tcp.close()
return port
@enricofoltran
enricofoltran / main.go
Last active April 1, 2024 00:17
A simple golang web server with basic logging, tracing, health check, graceful shutdown and zero dependencies
package main
import (
"context"
"flag"
"fmt"
"log"
"net/http"
"os"
"os/signal"