Skip to content

Instantly share code, notes, and snippets.

View wadtech's full-sized avatar

Peter Mellett wadtech

View GitHub Profile
@wadtech
wadtech / main.go
Last active November 12, 2018 14:35
Using govalidator custom validation messages to implement i18n
package main
import (
"fmt"
"os"
"github.com/asaskevich/govalidator"
// my pretend module with some translation logic
"github.com/my/translations"
)
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" />
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"></script>
<style id="jsbin-css">
#map {
@wadtech
wadtech / AppDatabaseSessionHandler.php
Last active December 13, 2023 15:31
Laravel 5.3 Custom Database Session Handler Example
<?php
namespace App\Extensions;
// we have an Eloquent model that allows using the session table with the querybuilder methods and eloquent fluent interface- read only!
use App\Session;
// use the provided database session handler to avoid too much duplicated effort.
use Illuminate\Session\DatabaseSessionHandler;
class AppDatabaseSessionHandler extends DatabaseSessionHandler
@wadtech
wadtech / build_openbr.sh
Last active March 15, 2016 14:13 — forked from hfeeki/build_openbr.sh
Build openbr in ubuntu
# Install GCC 4.7.3
sudo apt-add-repository ppa:ubuntu-sdk-team/ppa
sudo apt-get update
sudo apt-get install -y build-essential
# Install CMake 2.8.10.1
sudo apt-get install -y cmake cmake-curses-gui
wget ftp://ftp.lyx.org/pub/linux/distributions/0linux/archives_sources/opencv/opencv-2.4.5.tar.gz
tar -xf opencv-2.4.5.tar.gz
@wadtech
wadtech / router.php
Created January 5, 2016 09:59
Simple and generic router file for PHP built-in webserver. Place in your project webroot and run with `php -S localhost:3000 /path/to/router.php`
<?php
$path = __DIR__ . DIRECTORY_SEPARATOR . ltrim(parse_url($_SERVER['REQUEST_URI'])['path'], '/');
if (file_exists($path) && !is_dir($path)) {
return false;
}
if (file_exists($path . '/index.php')) {
require $path . '/index.php';
}
@wadtech
wadtech / install-rbenv.sh
Last active April 14, 2022 21:39
Reinstall rbenv just how I likes it.
#!/bin/bash
RBENV_LOC=$HOME/.rbenv
if [ -d $RBENV_LOC ]; then
rm -rf $RBENV_LOC
fi
echo 'Cloning rbenv...'
git clone --depth 1 -q https://github.com/rbenv/rbenv.git $RBENV_LOC
@wadtech
wadtech / dice.rb
Created November 19, 2015 17:34
Dice example with tally for frequency of results
puts "How many times do you want to roll?"
choice = gets.chomp
puts "How many sides should dice have?"
sides = gets.chomp
c = choice.to_i
s = sides.to_i
# store our tally of results in a hash with a default value
# for uninitialized members of 0
@wadtech
wadtech / node 0.12.7
Last active October 19, 2015 20:58
npm install git://github.com/rwaldron/johnny-five.git
pete@pete-laptop ~/projects/pikelets % node -v
v0.12.7
pete@pete-laptop ~/projects/pikelets % npm install git://github.com/rwaldron/johnny-five.git
> [email protected] postinstall /home/pete/projects/node_modules/johnny-five/node_modules/firmata
> node scripts/postinstall
/
> [email protected] install /home/pete/projects/node_modules/johnny-five/node_modules/firmata/node_modules/serialport
> node-pre-gyp install --fallback-to-build
@wadtech
wadtech / magento_removeAllCategories.sql
Last active August 29, 2015 14:27 — forked from jklance/magento_removeAllCategories.sql
Magento: Remove all categories from a store
SET FOREIGN_KEY_CHECKS = 0;
TRUNCATE TABLE `catalog_category_entity`;
TRUNCATE TABLE `catalog_category_entity_datetime`;
TRUNCATE TABLE `catalog_category_entity_decimal`;
TRUNCATE TABLE `catalog_category_entity_int`;
TRUNCATE TABLE `catalog_category_entity_text`;
TRUNCATE TABLE `catalog_category_entity_varchar`;
TRUNCATE TABLE `catalog_category_product`;
TRUNCATE TABLE `catalog_category_product_index`;
@wadtech
wadtech / routes.rb
Created April 19, 2015 05:57
Survey show
#config/routes.rb
Rails.application.routes.draw do
get '/surveys', to: 'surveys#show'
end