Skip to content

Instantly share code, notes, and snippets.

@francoishill
francoishill / golang_enums_check_has_flag
Last active May 29, 2023 11:40
Golang enums and checking if the value has a specific flag
package main
type verbosityEnum int
const (
NoneVerbosity verbosityEnum = 1 << iota
ErrorVerbosity verbosityEnum = 2
WarningVerbosity verbosityEnum = 4
InfoVerbosity verbosityEnum = 8
AllVerbosity verbosityEnum = 16
@francoishill
francoishill / gist:6483997
Created September 8, 2013 11:27
Media queries for mobile devices - Requires at least requires the meta viewport tag with content 'width=device-width'
/*http://i-skool.co.uk/mobile-development/web-design-for-mobiles-and-tablets-viewport-sizes/*/
/*At least requires the meta viewport tag with content 'width=device-width'*/
@media only screen and (max-width: 1080px) and (orientation : portrait) {
/* PORTRAIT:
Windows Surface Pro*/
}
@media only screen and (max-width: 800px) and (orientation : portrait) {
/* PORTRAIT:
Acer Iconia Tab A100
@francoishill
francoishill / controller.js
Last active July 31, 2022 13:34
Modal image in AngularJS and UI Bootstrap 3
$scope.openModalImage = function (imageSrc, imageDescription) {
$modal.open({
templateUrl: "path/to/modalImage.html",
resolve: {
imageSrcToUse: function () {
return imageSrc;
},
imageDescriptionToUse: function () {
return imageDescription;
}
@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)
@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 / 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 / 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";
<?php
class Blog extends Eloquent
{
public function images()
{
return $this->has_many_and_belongs_to('Image')
->order_by('blog_image.id', 'asc');
}
}
angular.module('ng').filter('tel', function () {
return function (tel) {
if (!tel) { return ''; }
var value = tel.toString().trim().replace(/^\+/, '');
if (value.match(/[^0-9]/)) {
return tel;
}