Skip to content

Instantly share code, notes, and snippets.

Hugo Schmitt hugows

Block or report user

Report or block hugows

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@hugows
hugows / validate.go
Created Mar 19, 2019
gojsonschema and echo
View validate.go
var mySchema = `{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"color": {
"description": "The price of the product",
"type": "string",
"enum": ["blue", "red", "black"],
"exclusiveMinimum": 0
}
@hugows
hugows / update_go.sh
Last active Mar 15, 2019
script to update go to new version on linux ubuntun
View update_go.sh
#!/usr/bin/env bash
# Original author: Ravi Teja Pothana (@RaviTezu)
# Hugo: removed stuff I didn't need on Linux
set -e
GO_VERSION="invalid"
GO_ROOT=/usr/local/go
function usage {
printf "./update_go.sh <version> \n"
View sshfs.md

Mount your remote server to easily edit files with VSCODE

sudo mkdir /mnt/droplet
sudo sshfs -o allow_other root@xxx.xxx.xxx.xxx:/ /mnt/droplet

To unmount:

View linux-tips.md

Helpful linux tips

Handy aliases I always type again:

alias sai='sudo apt install -y'
alias sas='sudo apt-cache search'
alias gc="git clone"
alias sshhugo="sshpass -p 'mypass' ssh myserver.com"
alias psqlacme="PGPASSWORD=acmepass psql -h localhost -U acme acmedb"
View postgres-quick-setup-ubuntu.md

Quick setup Postgres 10 on Ubuntu 18.10

Paste this into your terminal, replacing acme with your project name:

PGUSER=acme
PGPASS=acmepass
PGDB=acmedb

sudo apt-get install postgres
View 00-notes-about-APIs.org

On the emergence of interfaces

Interfaces naturally emerge as software gets broken down into parts communicating with one another. The larger and more deliberate structures emerge from a deliberate attempt to organize the development process itself. [fn:Liskov2008] Structure often emerge directly from division of labor: as teams take on independent tasks, interfaces are established betweeen domains they become responsible for. (Conway’s Law)

Software developers are responsible for systems built out of very small atoms while ultimately performing tasks for their users of a much greater magnitude. Dijkstra showed this by computing the ratio between grains of time at the lowest and largest atoms of the system (from say, CPU instructions to a human interaction with the system) The span was already quite large by Dijkstra’s time, of about 10^9. Today this ratio would be at least above 10^12 (see grain ratios)

This large span has to be manage

View gist:2ac057531acd6d3b9e60590ba28f48a5
export function items(state = [], action) {
switch (action.type) {
case 'ITEMS_FETCH_DATA_SUCCESS':
return action.items;
default:
return state;
}
}
@hugows
hugows / .screenrc
Last active Mar 7, 2018 — forked from jbeluch/.screenrc
Basic .screenrc (Good enough for 2018 - hugo)
View .screenrc
startup_message off
hardstatus on
hardstatus alwayslastline
hardstatus string "%{.bW}%-w%{..G}%n %t%{-}%+w %=%{..G} %H %{..Y} %m/%d %C%a"
View QueryBuilder.go
// This is a helper function to make Go work with https://github.com/marmelab/admin-on-rest parameters
// a little bit easier.
func QueryBuilder(tableName string, cols string, query url.Values) (string, error) {
// only match string like `name`, `users.name`
var columnRegexp = regexp.MustCompile("^[a-zA-Z\\d]+(\\.[a-zA-Z\\d]+)*$")
baseQuery := fmt.Sprintf("SELECT %s FROM %s", cols, tableName)
colsMap := make(map[string]bool)
View slow_insert.go
// A slower insert that is faster to type.
func (db *DB) ReflectInsert(tablename string, obj interface{}) error {
base := "INSERT INTO %s(%s) VALUES (%s)"
count := 1
var columns []string
var placeholders []string
var vals []interface{}
v := reflect.ValueOf(obj).Elem()
t := v.Type()
You can’t perform that action at this time.