Skip to content

Instantly share code, notes, and snippets.

View hassansin's full-sized avatar
Working from home

Hassansin hassansin

Working from home
View GitHub Profile
View .md

Ideas on generics in Go

As we all know, Go 2 is on its way and despite the hesitations, it's clear that without generics, it would end up being a disappointment. And although we are still gathering real-life use-cases, or experience reports, there's nothing bad about starting to think about how generics in Go could look like. I've come up with a few ideas which I'd love to share. So, here we go!

What's already achievable?

Now, Go 1 has no generics, but has interfaces. Interfaces (sometime accompanied by reflection)

albulescu / download.go
Created March 25, 2016 09:44
golang download file with progress
View download.go
package main
* @website
* @author Cosmin Albulescu <>
import (
ciaranarcher / example.go
Created July 27, 2014 06:53
Wrapping a ResponseWriter to capture the status code
View example.go
// Create our own MyResponseWriter to wrap a standard http.ResponseWriter
// so we can store the status code.
type MyResponseWriter struct {
status int
func NewMyResponseWriter(res http.ResponseWriter) *MyResponseWriter {
// Default the status code to 200
return &MyResponseWriter{200, res}
dweinstein / Dockerfile
Created March 14, 2014 15:37
View Dockerfile
FROM ubuntu
MAINTAINER David Weinstein <>
# install our dependencies and nodejs
RUN echo "deb precise main universe" > /etc/apt/sources.list
RUN apt-get update
RUN apt-get -y install python-software-properties git build-essential
RUN add-apt-repository -y ppa:chris-lea/node.js
RUN apt-get update
RUN apt-get -y install nodejs
ellemenno / spinner.rb
Created March 11, 2014 16:41
ascii spinner
View spinner.rb
#!/usr/bin/env ruby
# encoding: UTF-8
@dot_cycle = ['⣾','⣽','⣻','⢿','⡿','⣟','⣯','⣷']
#braille random: 0x2800 - 0x28ff
@z_arrow = ['←','↖','↑','↗','→','↘','↓','↙']
@z_b = ['b','ᓂ','q','ᓄ']
@z_d = ['d','ᓇ','p','ᓀ']
mogarick / utcTimestampsWithTimezone.js
Last active January 27, 2021 14:00
Getting UTC timestamps of iCal with Timezone using the mozilla-comm/ical.js lib
View utcTimestampsWithTimezone.js
//Please note I'm also using underscore each function for the iterations
//iCal -> jsCal
var icalEvents = ICal.parse(iCalStringData);
var comp = new Component(icalEvents[1]);
//Get all VTIMEZONE iCalendar components
var vtimezones = comp.getAllSubcomponents("vtimezone");
//Add all timezones in iCalendar object to TimezonService
ukolka / HttpStreamWrapperTestCase.php
Last active August 15, 2019 12:19
PHPUnit extension for testing code that's using PHP's http:// stream wrapper context to make requests.
View HttpStreamWrapperTestCase.php
namespace tests\unittests\custom;
* Whenever PHP HTTP stream is used you can
* inject a mock stream resource into an object that
* expect it.
* Usage example:
* ...
willurd /
Last active September 28, 2023 14:00
Big list of http static server one-liners