Skip to content

Instantly share code, notes, and snippets.

View PaulCapestany's full-sized avatar

Paul Capestany PaulCapestany

View GitHub Profile

Most developers that are familiar with dynamic scripting language like Ruby, JavaScript, or Python have been exposed to higher-order functions. Coming from a scripting background, it can be hard to translate that knowledge into Go, since the type system seems to get in the way. On the other hand, coming from a statically typed, primarily object-oriented language like C++, C#, or Java, the problem may be the opposite: static type systems are less of a stumbling block, but the usage of higher-order functions may be less intuitive. For programmers with functional experience, most of this knowledge may come across as very pedestrian, but hopefully this article will at least demonstrate how to use Go's type system with respect to functions.

In this article, we'll look at a few situations where function types in Go can be very useful. The reader is not assumed to be an experienced Go programmer, although a cursory knowledge of Go will certainly be helpful

@freeformz
freeformz / WhyILikeGo.md
Last active October 6, 2022 23:31
Why I Like Go

A slightly updated version of this doc is here on my website.

Why I Like Go

I visited with PagerDuty yesterday for a little Friday beer and pizza. While there I got started talking about Go. I was asked by Alex, their CEO, why I liked it. Several other people have asked me the same question recently, so I figured it was worth posting.

Goroutines

The first 1/2 of Go's concurrency story. Lightweight, concurrent function execution. You can spawn tons of these if needed and the Go runtime multiplexes them onto the configured number of CPUs/Threads as needed. They start with a super small stack that can grow (and shrink) via dynamic allocation (and freeing). They are as simple as go f(x), where f() is a function.

@timpulver
timpulver / GetNameAndTitleOfActiveWindow.scpt
Created February 11, 2013 10:38
[AppleScript] Get Name of active window | Returns the name / title of the active (frontmost) window
# taken from user Albert's answer on StackOverflow
# http://stackoverflow.com/questions/5292204/macosx-get-foremost-window-title
# tested on Mac OS X 10.7.5
global frontApp, frontAppName, windowTitle
set windowTitle to ""
tell application "System Events"
set frontApp to first application process whose frontmost is true
set frontAppName to name of frontApp
@postmodern
postmodern / comment.md
Last active January 11, 2024 15:37
Crypto Privacy Copy Pasta
@rboyd
rboyd / filter_long_emails.js
Last active July 1, 2023 05:37
google apps script to archive and autoreply to long emails.
/* paste into http://script.google.com
run periodically (e.g. every 5 minutes) with a timer by selecting 'Resources' > 'current project's triggers...'
*/
function filterLongEmails() {
var num_messages = 1; // will be applied to the last n messages. Google allows up to 500
var word_limit = 50;
var subj = "Shorter emails will get read.";
var body = "Dear friends, I value my time and yours but I appreciate it if you can keep your emails under " + word_limit + " words. Please edit and resend.";
./sync_gateway ~/code/CouchChat-iOS/sync-gateway-config.json
16:23:39.792740 Enabling logging: [CRUD REST+]
Sync Gateway starting with config settings:
{
"Interface": ":4984",
"AdminInterface": ":4985",
"Persona": {
"Origin": "http://animal.local:4984/"
},
"Log": [
@dankrause
dankrause / _hover_example.py
Last active March 8, 2024 18:31
Example code to use the (unofficial, unsupported, undocumented) hover.com DNS API.
import requests
class HoverException(Exception):
pass
class HoverAPI(object):
def __init__(self, username, password):
params = {"username": username, "password": password}
r = requests.post("https://www.hover.com/api/login", params=params)
@nriley
nriley / extract.py
Created June 27, 2013 06:51
Extract English subtitle text for WWDC 2013 videos.
import requests
import os, re, sys
RE_SD_VIDEO = re.compile(
r'<a href="(http://devstreaming.apple.com/videos/wwdc/2013/[^"]*-SD.mov)')
RE_WEBVTT = re.compile(r'fileSequence[0-9]+\.webvtt')
# stdin: dump of https://developer.apple.com/wwdc/videos/
for l in sys.stdin:
m = RE_SD_VIDEO.search(l)
@dustin
dustin / progress.go
Last active December 19, 2015 16:18
Uploading a ton of stuff to S3, I decided I wanted something that would take this boring *os.File and give me a progress indicator. Here's the thing I threw together. Sends this sort of thing to stdout ('\r'ing over itself every second): 10MB/72MB (14.6%)
package main
import (
"fmt"
"io"
"os"
"time"
"github.com/dustin/go-humanize"
)
@shrop
shrop / gist:5995086
Last active November 17, 2022 08:07
Improved script for highlighting git repo folders which have unstated/uncommitted files. An improvement on the script for the Hazel rule created by @tylerhall: http://clickontyler.com/blog/2013/03/hazel-and-git. This improvement checks to see if the folder is actually a git repo and if not, doesn't bother processing any further.
dirname=$1
if [ -f $dirname ]; then
dirname=`dirname $dirname`
fi
cd $dirname
if [ ! -d .git ]; then
exit 1
fi