Skip to content

Instantly share code, notes, and snippets.

@philayres
philayres / setvpnroute.sh
Created September 23, 2021 15:43
On a Mac, set a route after connecting to a SoftEther VPN
#!/bin/bash
# Set up a route to the be used when logged into
# AWS SoftEther VPN
# VPN IP addresses should be in the 192.168.99 subnet after connection is made.
# The gateway for the route is usually set to the address received via DHCP.
# On Mac OSX the route sent by DHCP is ignored and must be set manually
echo "Setting up routing for AWS VPN interface....."
INTFC=$(/sbin/ifconfig | grep ppp | awk -F: '{print $1}')
if [ -z $INTFC ]; then
echo "No ppp interface found. Check VPN connection"
@philayres
philayres / process_pipes.rb
Last active October 4, 2022 15:43
In Ruby, how to perform process piping between commands, like `echo 'ABC12345 234234 24523' | wc | grep '1'`
#
# NOTE: this is hugely simplified from the previous version, just using the
# existing pipe between popen and Ruby to handle communication, and passing
# data from one process to the next
#
#
# Use popen to create a subprocess connected to Ruby through a pipe:
# optionally sends results to the pipe, receives results from the pipe
#
# Send to pipe (no initial piped in data):
import re
from spellchecker import SpellChecker
import csv
food_col = []
food_output = []
errors = []
line = 0
with open('Data/survey.csv', 'r') as csvfile:
@philayres
philayres / pattern-masker.js
Last active December 12, 2017 15:37
Convert HTML5 input pattern attribute to jQuery-Mask-Plugin mask
/* (Released under MIT License, copyright Phil Ayres, see LICENSE file for full license)
Convert HTML5 input pattern attribute to a jQuery-Mask-Plugin compatible mask.
This follows some basic common regex patterns, but by no means all that could be applied to
HTML5 inputs. It is sufficient for simple cases.
Obviously you will need the jQuery-Mask-Plugin
Get it from: https://github.com/igorescobar/jQuery-Mask-Plugin
Usage:
@philayres
philayres / Gemfile
Last active August 29, 2015 14:15
Testing Fog in EventMachine eventmachine_httpserver
source 'https://rubygems.org'
gem 'eventmachine'
gem 'eventmachine_httpserver', :require => 'evma_httpserver'
gem 'mysql2'
gem 'httpclient', :git=>'https://github.com/philayres/httpclient.git'
gem 'hashie'
gem 'connection_pool'
gem 'logger'
gem 'excon'
@philayres
philayres / gist:9219aed29ef2651fa2bd
Last active August 29, 2015 14:02
Alpaca form submit
// This is how I'm creating the alpaca form
_re = {};
_re.utils = {
form_auth_token: function(){
var autht = $('meta[name="csrf-token"]').attr('content');
var authh ='<div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓"><input name="authenticity_token" type="hidden" value="'+autht+'"></div>';
return authh;
@philayres
philayres / gist:653be9b1c61d041c9b78
Created May 1, 2014 17:57
Hack Alpaca checkbox fields to validate against JSON Schema
/* Include the following functions to override those in the appropriate places in the Alpaca.js code */
//Alpaca.ControlField = {
validationList: function(){
var list = this.schema.enum;
if(!list) list = this.schema.list;
return list;
},
@philayres
philayres / api_auth.rb
Created October 31, 2013 13:30
Simple One-Time-Token (nonce) generator / validator. Note: one time use of the token in the database is not included in this example, but validation of timeout and URI parameter correctness is
require 'digest'
class ApiAuth
# Pass params as hash, a secret used to salt the hash, action and controller, and any additional options
def self.generate_ottoken params, secret, action, controller, options={}
uri_set = []
sign_params = params.to_a
sign_params.sort! {|x,y| x <=> y }
@philayres
philayres / display-indicator.py
Created October 24, 2011 19:21
Unity indicator for simple clock and date display
#!/usr/bin/env python
# Unity indicator for evolution-less clock and date display
# author: phil ayres
# 24 Oct 2011
import gobject
import gtk
import appindicator
import os, sys
import time
@philayres
philayres / upc_supplemental_for_barby.rb
Created January 11, 2011 21:14
Adds support for UPC 5-Digit Supplemental barcodes to Barby barcode generator
require 'barby/barcode'
class UpcSupplementalForBarby < Barby::Barcode1D
@data = nil
attr_reader :data
START = '1011'
STOP = ''
INTER_CHAR = '01'