Skip to content

Instantly share code, notes, and snippets.


Steven Black StevenBlack

View GitHub Profile
StevenBlack / trycatch.go
Created Apr 30, 2021
Go Try/Catch/Finally implementation
View trycatch.go
// source:
package main
import (
type Block struct {
Try func()
Catch func(Exception)
StevenBlack / defaulthosts
Created Apr 13, 2020
All-purpose default hosts
View defaulthosts localhost localhost.localdomain local broadcasthost
::1 localhost
::1 ip6-localhost
::1 ip6-loopback
fe80::1%lo0 localhost
ff00::0 ip6-localnet
ff00::0 ip6-mcastprefix
StevenBlack /
Last active Oct 17, 2020 — forked from ChrisWellsWood/
Initialising empty structs in Rust.

Initializing Empty Structs in Rust

In C/C++, you can initialise a struct without giving values for any of the fields:

struct Point {
  float x;
  float y;
  float z;
View colors.css
Better default colors for the web
StevenBlack / GA-Events.js
Last active Sep 27, 2019
Google Analytics Events Example
View GA-Events.js
// Upon document ready, have jQuery do the following
$( function(){
var gaJsHost = ( ( "https:" === document.location.protocol ) ? "https://ssl." : "http://www." );
// use jQuery to call the Google Analytics JavaScript
$.getScript( gaJsHost + "", function(){
// tell Analytics about the current page load using standard _trackPageview method
try {
var pageTracker = _gat._getTracker( $ );
// the standard page tracking code
View jquery.pluginOutline.js
// Skeleton jQuery plugin
$.fn.myPlugin = function( options )
// options.
$.fn.myPlugin.settings = $.extend( {}, $.fn.myPlugin.defaults, options );
// Go through the matched elements and return the jQuery object.
StevenBlack / gist:960189
Created May 7, 2011
View gist:960189
// for contrasting text color
// Original article:
function getContrastYIQ(hexcolor){
var r = parseInt(hexcolor.substr(0,2),16);
var g = parseInt(hexcolor.substr(2,2),16);
var b = parseInt(hexcolor.substr(4,2),16);
var yiq = ((r*299)+(g*587)+(b*144))/1000;
return (yiq >= 131.5) ? 'black' : 'white';
StevenBlack /
Created Apr 8, 2018 — forked from jirutka/
Some convenient scripts to manage ownerships and privileges in PostgreSQL.
# The MIT License
# Copyright 2014-2017 Jakub Jirutka <>.
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
View postgres_queries_and_commands.sql
-- show running queries (pre 9.2)
SELECT procpid, age(query_start, clock_timestamp()), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(query_start, clock_timestamp()), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
StevenBlack /
Created Apr 8, 2018 — forked from Kartones/
PostgreSQL command line cheatsheet


Magic words:

psql -U postgres

Some interesting flags (to see all, use -h):

  • -E: will describe the underlaying queries of the \ commands (cool for learning!)
  • -l: psql will list all databases and then exit (useful if the user you connect with doesn't has a default database, like at AWS RDS)