Skip to content

Instantly share code, notes, and snippets.

View JohnB's full-sized avatar

John Baylor JohnB

View GitHub Profile
@JohnB
JohnB / vj.sh
Last active May 25, 2020 19:29 — forked from kljensen/vj.sh
Added location, updated link to the access-os-x-keychain-from-terminal blog post and added some explanatory text.
#!/usr/bin/env bash
# Canonical location: https://gist.github.com/kljensen/4434992
##########################################################
#
# This is a shell script for keeping a journal that is
# * plaintext,
# * time-stamped,
# * encrypted, and
@JohnB
JohnB / array_extensions.rb
Last active December 14, 2015 15:48
Array.extract
# We need to create Array.extract if it doesn't already exist
class Array
# Delete some of our items and return (or "extract") a new array holding the deleted items.
# Very similar to partition, but instead of returning copies, it modifies the original list
def extract
extracted = []
# reverse our deletion so indexes don't get messed up while we're deleting
(length - 1).downto(0) do |idx|
item = self[idx]
extracted << delete_at(idx) if yield(item)
@JohnB
JohnB / lun_check.rb
Created August 16, 2012 06:38
Ruby LUN checker
# each_with_index is useful, so why not inject_with_index?
module Enumerable
def inject_with_index(memo)
each_with_index {|obj, idx| memo = yield(memo, obj, idx)}
memo
end
end
def passes_lun?(cardnum)
digits = cardnum.gsub(/\D/,'').reverse.split('').map(&:to_i)
@JohnB
JohnB / Koch snowflake
Created October 27, 2011 16:36
Koch curve for Codify #codify
CODE_FOUND_AT = "https://gist.github.com/1320074        "
CREATED_BY = "      Created by [email protected]"
LONGLINE = 630
-- Use this function to perform your initial setup
function setup()
    print(string.format(CODE_FOUND_AT..CREATED_BY))
    iparameter("dimension",0,5)
    iparameter("sides",3,6)
    lentab = {0,0, 630, 500, 450, 450 }
    dirtab = {0,0, -120, -90, -72, -60} 
@JohnB
JohnB / sooper_seekret_encreepshun.rb
Created March 20, 2011 16:01
Just a bit of fun...
require 'base64'
class Object
def e64 str
Base64.encode64(str).chomp
end
def d64 str
Base64.decode64 str
end
def rot13 str
rotN(13,str)
// Each scrap would at least define its inputs, outputs and markup.
// Additionally, it would contain any scrap-specific functionality.
// Like Rails partials, they could be chained together to build
// higher-level functionality.
var user_form = Scrap.define({
input: {
model: 'hash containing the current state of the user being edited',
collection: 'array of all the *other* users, for uniqueness checking',
},
output: {
var user_dialog = Dialog.define({
input: {
edit: 'boolean telling us whether we are editing or adding (default)',
model: 'hash containing the current state of the user being edited',
collection: 'array of all the *other* users, for uniqueness checking',
ok_location: 'bottom (default) or top of the dialog box'
},
output: {
ok: 'boolean as to whether the user okayed their changes or not',
model: 'hash containing the updated state of the user being edited'
var user_dialog = Dlg.run({
markup: [{
div: {id: 'user_dialog', ui: {
table: [
{tr: [
{td: {_class:'field_name', value:'Name'}},
{td: [
{input: {type:'text', id:'name', size:40,
validation: 'cannot_be_blank'}},
<!-- Markup generated from simple_markup.js -->
<div id='user_dialog'>
<table>
<tr>
<td class='field_name'>Name</td>
<td>
<input type='text' id='name' size=40 />
<span id='err_msg_for_name' class='err_msg' />
</td>
</tr>
// Example markup for user edit dialog. Simple tags, with no specified class or id
// just contain an array holding their nested markup. More complex ones hold a hash
// with tag fields and a "ui" field holding their nested markup. This data would be
// recursed over to generate the expected HTML markup.
var markup = {
div: {id: 'user_dialog', ui: {
table: [
{tr: [
{td: {_class:'field_name', value:'Name'}},
{td: [