Skip to content

Instantly share code, notes, and snippets.

@francoishill
francoishill / Basic HTML5.html
Last active December 18, 2015 13:19
Basic HTML5 layout
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body onload="bodyOnload();">
</body>
</html>
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;
}
<?php
class Blog extends Eloquent
{
public function images()
{
return $this->has_many_and_belongs_to('Image')
->order_by('blog_image.id', 'asc');
}
}
@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
# CoffeeScript directive to focus an element when a property changes
# Thanks to: http://stackoverflow.com/questions/14833326/how-to-set-focus-in-angularjs
masterApp.directive "takeFocus", ["$timeout", "$parse", ($timeout, $parse) ->
link: (scope, element, attrs) ->
model = $parse(attrs.takeFocus)
scope.$watch model, (value) ->
if value is true
$timeout ->
element[0].focus()
@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 / 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 / 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 / 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"
::
:: 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%"