Skip to content

Instantly share code, notes, and snippets.

View samonzeweb's full-sized avatar

Samuel GAY samonzeweb

View GitHub Profile
@samonzeweb
samonzeweb / gist:b1ae3e2d1f3203ee1722ac4bd2cb95e9
Created December 16, 2016 12:17
Nested queries with godb (not really a final way of doing it).
// problem : the placeholder '?' could be changed by ToSQL() !
query, args, err := db.SelectFrom("noeud").Columns("id").Where("identifiant like ?", "00%").ToSQL()
...
nodes := make([]Noeud, 0, 0)
err = db.Select(&nodes).Where("id in ("+query+")", args...).Do()
...
@samonzeweb
samonzeweb / test-godb-mssql.bash
Last active October 21, 2017 15:23
Testing godb on SQL Server through docker (OSX/Linux)
#!/bin/bash
# Testing godb ( https://github.com/samonzeweb/godb ) with SQL Server on OSX / Linux
docker run --name sqlserver -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=NotSoStr0ngP@ssword' -p 1433:1433 -d microsoft/mssql-server-linux:latest
docker exec -i sqlserver /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P NotSoStr0ngP@ssword <<-EOF
create database godb;
go
exit
@samonzeweb
samonzeweb / test-godb-postgresql.bash
Created October 22, 2017 15:48
Testing godb on PostgreSQL through docker (OSX/Linux)
#!/bin/bash
# Testing godb ( https://github.com/samonzeweb/godb ) with PostgreSQL
docker run --name postgresql -e 'POSTGRES_PASSWORD=NotSoStr0ngPassword' -p 5432:5432 -d postgres:latest
sleep 5
# See https://godoc.org/github.com/lib/pq#hdr-Connection_String_Parameters
GODB_POSTGRESQL="postgres://postgres:NotSoStr0ngPassword@localhost/postgres?sslmode=disable" go test
@samonzeweb
samonzeweb / test-godb-mariadb.bash
Created October 22, 2017 15:48
Testing godb on MariaDB through docker (OSX/Linux)
#!/bin/bash
docker run --name mariadb -e 'MYSQL_ROOT_PASSWORD=NotSoStr0ngPassword' -p 3306:3306 -d mariadb:latest
sleep 10
docker exec -it mariadb mysql -uroot -pNotSoStr0ngPassword -hlocalhost -e "create database godb;"
# See https://github.com/go-sql-driver/mysql#dsn-data-source-name
GODB_MYSQL="root:NotSoStr0ngPassword@/godb?parseTime=true" go test
@samonzeweb
samonzeweb / test-godb-windows.txt
Created October 24, 2017 11:04
Testing godb on windows (gcc required for sqlite3)
Testing godb ( https://github.com/samonzeweb/godb ) on MS Windows
(cgo/gcc related to github.com/mattn/go-sqlite3)
Source : https://github.com/mattn/go-sqlite3/issues/212#issuecomment-185036480
Install MSYS2 (64 bits)
- http://www.msys2.org/
- https://github.com/msys2/msys2/wiki/MSYS2-installation
@samonzeweb
samonzeweb / Caddyfile
Created December 27, 2017 11:54
Proxy API to avoid CORS problems during JS development
# Proxy API to avoid CORS problems during development :
# - Get Caddy from https://caddyserver.com/
# - Put the Caddyfile somewhere with the Caddy executable
# - Change posts, paths, ... as needed
# - Start the Caddy process (without args)
# - Lauch the SPA using the URL http://localhost:8081
localhost:8081
log stderr
@samonzeweb
samonzeweb / goandvue.go
Last active December 17, 2022 17:35
Go and Vue.js development
package main
// ----------
// How to developp with Vue.js and golang (or other JS framework)
// (awful almost raw notes)
//
// ----------
// Create a projet ClientVue with vue-cli
//
// For developpment with webpack add a proxy to
@samonzeweb
samonzeweb / fwsql.ps1
Created March 9, 2018 10:12
Open firewall ports for SQL Server with PowerShell
# SQL Sever & firewall : https://docs.microsoft.com/en-us/sql/sql-server/install/configure-the-windows-firewall-to-allow-sql-server-access
# New-NetFirewallRule : https://docs.microsoft.com/en-us/powershell/module/netsecurity/new-netfirewallrule?view=win10-ps
New-NetFirewallRule -DisplayName "SQLServer default instance" -Direction Inbound -LocalPort 1433 -Protocol TCP -Action Allow
New-NetFirewallRule -DisplayName "SQLServer Browser service" -Direction Inbound -LocalPort 1434 -Protocol UDP -Action Allow
@samonzeweb
samonzeweb / purge.ps1
Created March 9, 2018 13:41
Remove folders created more than X days in PowerShell
# Script parameters
$pathToClean = 'C:\paht\to\somewhere'
$maxDays = 5
# Computed values, don't touch below
$dateLimit = (Get-Date).AddDays(-1 * $maxDays)
Get-ChildItem $pathToClean |
Where { $_.CreationTime -lt $dateLimit } |
Remove-Item -Recurse #-WhatIf
@samonzeweb
samonzeweb / backup-all-databases.ps1
Created March 9, 2018 15:23
Backup all SQL Server databases with PowerShell
# SQL Server parameters
$serverInstance = 'localhost'
# Backup parameters
$backupDirectory = 'C:\path\to\backup\dir'
$retentionDays = 10
# Mail parameters
$mailFrom = '[email protected]'
$mailTo = '[email protected]'