Skip to content

Instantly share code, notes, and snippets.

@francoishill
francoishill / README.md
Created February 13, 2017 05:45 — forked from notheotherben/README.md
PEG Grammar for Command Line Parsing

Command Line Parsing Grammar

This grammar allows you to parse command lines for program execution into their various components - specifically: environment variables, the executable itself and any arguments passed to the executable.

It will take an input like the following:

ENV_X=true ENV_Y="yes please" ./test/my_exec arg1 -f1 "arg with spaces" 'another arg' --flag2 yet\ another\ arg --flag=10
@francoishill
francoishill / ExpandedExample.cs
Created January 28, 2016 11:38
C# visitor pattern
public abstract class BaseAnimal
{
public abstract void Accept(IAnimalVisitor visitor);
}
public class DogAnimal : BaseAnimal
{
public string MoveHeadStepName = "Dog move head";
public string WagTailStepName = "Dog wag tail";
public string OpenMouthStepName = "Dog open mouth";
@francoishill
francoishill / README.md
Created December 10, 2015 13:21
Add your ssh key into the `authorized_keys` of CoreOS

On your machine (windows / linux) that you want to get access to from

Setup a (temporary) http server on your machine that always responds with your machine's SSH public key.

Replace the 'YOUR-SSH-KEY-GOES-HERE' if using the golang file of this gist.

On the CoreOS box you want to access

Call these commands below on the CoreOS box by replacing IP-OF-YOUR-MACHINE of your machine having the http server.

@francoishill
francoishill / run_go_app__windows_batch_file.sublime-snippet
Created November 19, 2015 08:49
A snippet to quickly generate a batch file to build/run a go app. In your folder with main.go, just create a new "run.bat" file and trigger this snippet by typing `run_go_app`.
<snippet>
<content><![CDATA[
@echo off
cls
SET ERRORLEVEL=0
echo Running go build... ^
& go build -o "${1:${TM_FILEPATH/.+\/(.+)\/.+\..+/$1/}}.exe"^
& if errorlevel 1 goto ERROR
echo Running exe ${1}.exe... ^
@francoishill
francoishill / main.go
Created October 2, 2015 05:05
Simple static golang static site server
package main
import (
"fmt"
"log"
"net/http"
"os"
)
func printRecovery() {
@francoishill
francoishill / golang_benchmark_interface_methods.go
Last active October 2, 2015 03:13
The idea of this benchmark is to determine the performance cost of when we pass around interfaces instead of the concrete struct and getting a field on the struct vs calling a `get` method on the interface
//The idea of this benchmark is to determine the
// performance cost of when we pass around interfaces
// instead of the concrete struct and getting a field
// on the struct vs calling a `get` method on the
// interface
package test
import (
"testing"
@francoishill
francoishill / accurev-stat-hist.reg
Created July 8, 2015 12:45
Add explorer right-click entries for Accurev to show `hist` and `stat`
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\*]
[HKEY_CLASSES_ROOT\*\AccurevSubCommands]
[HKEY_CLASSES_ROOT\*\AccurevSubCommands\Shell]
[HKEY_CLASSES_ROOT\*\AccurevSubCommands\Shell\Accurev stat]
"MUIVerb"="Accurev stat"
::
:: Thanks to: https://stackoverflow.com/questions/19832669/inserting-date-time-stamp-in-file-name-using-bat-script/19835038#19835038
::
@echo off
for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
set "YY=%dt:~2,2%" & set "YYYY=%dt:~0,4%" & set "MM=%dt:~4,2%" & set "DD=%dt:~6,2%"
set "HH=%dt:~8,2%" & set "Min=%dt:~10,2%" & set "Sec=%dt:~12,2%"
set "datestamp=%YYYY%%MM%%DD%" & set "timestamp=%HH%%Min%%Sec%"
@francoishill
francoishill / loop_files_folders_recursively.go
Created August 1, 2014 16:52
Loop through files and folders recursively in golang
package main
import (
"fmt"
"os"
"path/filepath"
)
func main() ([]string, error) {
searchDir := "c:/path/to/dir"
@francoishill
francoishill / visitor_pattern_in_go.go
Last active April 12, 2020 20:45
Visitor Pattern in Golang
package main
//Thanks to http://ecs.victoria.ac.nz/foswiki/pub/Main/TechnicalReportSeries/ECSTR11-01.pdf
import (
"fmt"
)
//We will have multiple car parts
type CarPart interface {
Accept(CarPartVisitor)