Skip to content

Instantly share code, notes, and snippets.

View wlkns's full-sized avatar

JW wlkns

View GitHub Profile
@wlkns
wlkns / CardTest.java
Last active December 25, 2015 10:19
Java Read Cards/Fobs using ACR122U NFC Reader
import java.io.*;
import java.util.*;
import javax.smartcardio.*;
public class CardTest {
final protected static char[] hexArray = "0123456789ABCDEF".toCharArray();
public static String bytesToHex(byte[] bytes) {
char[] hexChars = new char[bytes.length * 2];
@wlkns
wlkns / MY_Form_validation.php
Created October 15, 2013 18:32
CodeIgniter Postcode Validation Form Validation (and global call back functionality), read more at http://wlkns.co/codeigniter/global-form-validation-callback-functionality-and-postcode-checker-in-codeigniter/
<?php defined('BASEPATH') or die('Direct access to this file is not permitted.')
class MY_Form_validation extends CI_Form_validation
{
/**
* Postcode Validation Callback
*/
public function valid_postcode( $string )
{
@wlkns
wlkns / app.js
Last active January 1, 2016 09:09
Socket.IO Authentication Tutorial (Server and Client) - http://wlkns.co/?p=52
/* app.js
*
* This code is the client to connect to the Socket.IO server run in the clients browser */
jQuery(document).ready(function(){
/* Connect the socket */
socket = io.connect('http://localhost:8080', {
/* Pass the authentication token as a URL parameter */
query: $.param({token: 'i271az2Z0PMjhd6w0rX019g0iS7c2q4R'})
/* My application is more complicated, so I use jQuery's .param utility to convert the Object to an URL string e.g. 'token=abc&etc=cde' */
@wlkns
wlkns / mixins.jade
Last active August 29, 2015 14:07 — forked from shaneriley/mixins.jade
// Writing JS for everything is great and all, but I don't want to see JS
// inline in my Jade templates. Thankfully, there are ways of abstrating it
// into mixins!
// Want some Rails-like helpers?
mixin link_to(name, href)
- href = href || "#"
a(href="#{href}")= name
// How about a single editing point for a class name?
mixin csrf
div
input(type='hidden', name='_csrf', value=csrfToken)
block
mixin formErrors(form)
errors = form.nonFieldErrors().errors
for error in errors
.alert.alert-error= error
;(function() {
'use strict';
angular.module('app').filter('address', Filter);
function Filter($sce) {
return function(input, seperator, defaultValue) {
seperator = seperator || ', ';
defaultValue = defaultValue || '';
/**
* Returns the value at the given property.
*
* @param {object} - the input object
* @param {string} - the property accessor expression.
* @returns {*}
* @alias module:object-get
* @example
* > objectGet({ animal: 'cow' }, 'animal')
* 'cow'
@wlkns
wlkns / RegionRedirectCookieMiddleware.php
Created October 6, 2017 12:18
Laravel region selector (with cookies)
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Cookie;
class RegionCookieRedirect
{
@wlkns
wlkns / gulpfile.babel.js
Created March 2, 2018 10:51 — forked from nicekiwi/gulpfile.babel.js
New ES6 project with Babel, Browserify & Gulp + Bundling/Watching Multiple Files
import gulp from 'gulp';
import sourcemaps from 'gulp-sourcemaps';
import buffer from 'gulp-buffer';
import uglify from 'gulp-uglify';
import tap from 'gulp-tap';
import browserify from 'browserify';
import babel from 'babelify';
gulp.task('build', () => {
@wlkns
wlkns / gulpfile.js
Created March 4, 2018 12:23
Gulp + Babel + import
gulp.task('scripts:search', () => {
return gulp.src('./search-module/index.js', { read: false })
.pipe(tap((file) => {
file.contents = browserify(file.path, {
debug: true
}).transform(babel, {
presets: ["es2015"],
plugins: ["angularjs-annotate"]
}).bundle();
}))