Skip to content

Instantly share code, notes, and snippets.

View iamjono's full-sized avatar
🏠
Working from home in a COVID Reclusion

Jonathan Guthrie iamjono

🏠
Working from home in a COVID Reclusion
View GitHub Profile
@iamjono
iamjono / flatten.swift
Last active April 4, 2019 15:08
Flattens a nested array of integers to [Int]
/**
* Flatten
* A function designed to recursively flatten nested array of integers to a single array of integers
* - parameter: a single element of type [Any]
* - returns: an array of integers [Int]
*/
func flatten(_ a: [Any]) -> [Int] {
// Initialize the internal storage array
var container = [Int]()

Keybase proof

I hereby claim:

  • I am iamjono on github.
  • I am iamjono (https://keybase.io/iamjono) on keybase.
  • I have a public key ASBfJQnO3qiS8KTVfZOY5iv1RAh6cI9Ejo8SdkYQQoE_VQo

To claim this, I am signing this object:

import PerfectLib
import Foundation
import Cocoa
#if os(Linux)
import SwiftGlibc
#else
import Darwin
#endif
@iamjono
iamjono / numeric_string.lasso
Created July 7, 2014 16:08
2 examples of how to extract numeric strings such as phone numbers
define numeric_string(in::string) => {
local(out = string)
with char in #in->split('') where string_isNumeric(#char) and #char != '-' && #char != '+' do => { #out->append(#char) }
return #out
}
define numeric_string2(in::string) => {
return string_replaceregexp(#in, -find='\\D', -replace='')
}
numeric_string('123_456-7890')
numeric_string2('(123) 456-7890')
@iamjono
iamjono / lp_string_zap.lasso
Last active August 29, 2015 13:57
lp_string_zap - Lasso 9 method for zapping gremlins
/* ============================================
Lasso 9 port of Bil Corry's lp_string_zap for Lasso 8.
Jonathan Guthrie, Feb 2013
============================================ */
define lp_string_zap(text_to_zap, replacement_text = void, ...) => {
not local_defined('replacement_text') ? local(replacement_text = '')
return string_replaceregexp(#text_to_zap, -find = '[^\\x20-\\x7E\\x09\\x0A\\x0D]', -replace = #replacement_text)
}
@iamjono
iamjono / geoplugin.lasso
Created January 29, 2014 01:48
This Lasso 9 data type uses the JSON Webservice of http://www.geoplugin.com/ to geolocate IP addresses. See http://www.geoplugin.com/webservices/ for more specific details of this free service.
[
// ==================================
/*
@author Jonathan Guthrie (jono@treefrog.ca)
#version 1.00
This Lasso 9 data type uses the JSON Webservice of http://www.geoplugin.com/ to geolocate IP addresses
See http://www.geoplugin.com/webservices/ for more specific details of this free service
Usage:
@iamjono
iamjono / gravatar.lasso
Created January 2, 2014 19:33
Retrieves the Gravatar for the given email address (Lasso 9)
[
define gravatar => type {
/* ==============================================================
Retrieves the Gravatar for the given email address.
local(x = gravatar('user@email.com',-default='mm'))
local(x = gravatar('user@email.com',-test=true))
============================================================== */
data
private base = 'http://www.gravatar.com/avatar/',
private securebase = 'https://secure.gravatar.com/avatar/',
@iamjono
iamjono / human_filesize.lasso
Last active January 1, 2016 20:59
human_filesize returns a human readable file size from a supplied integer (bytes)
[
define human_filesize(size::integer) => {
/* =================================================================
human_filesize returns a human readable file size from a supplied integer (bytes)
================================================================= */
local(
displaysize = string,
calc = decimal,
kb = 1024,
mb = 1024 * #kb,
@iamjono
iamjono / wkhtmltopdf.lasso
Last active December 28, 2015 10:59
wkhtmltopdf Lasso 9 type
[
/* ========================================================================================
wkhtmltopdf
https://code.google.com/p/wkhtmltopdf/
wkhtmltopdf('http://www.example.com/mypage.lasso?id=83','/pdfcache/id83.pdf',-removelast)
Requires std_shellhandler trait
======================================================================================== */
define wkhtmltopdf => type {
trait {
@iamjono
iamjono / normalDist.lasso
Created November 11, 2013 15:27
Box-Muller transform normal distribution method for Lasso 9
/* ============================================================
See http://rosettacode.org/wiki/Statistics/Normal_distribution#Lasso
============================================================ */
define normalDist(mean::decimal=0.5,sdev::decimal=0.2) => {
// Uses Box-Muller transform
return ((-2 * decimal_random->log)->sqrt * (2 * pi * decimal_random)->cos) * #sdev + #mean
}