Skip to content

Instantly share code, notes, and snippets.

View Ke-'s full-sized avatar

Ke Ke-

  • Zeroloop Limited
  • New Zealand
View GitHub Profile
@Ke-
Ke- / image.lasso
Last active August 6, 2019 22:18 — forked from jasonhuck/image.lasso
Replacement [image] Type for Lasso 9.x — updated to use file based approach.
[//lasso
/*
[sys_image] type for Lasso 9.x https://gist.github.com/Ke-/4fc6d3baedc760b076860d96cb102101
This is a replacement for the native [Image] type in Lasso 9.x. This version requires
[sys_process] and calls the ImageMagick command line utilities rather than relying on the
low-level libraries. Doing so mimises memory use.
Based loosely on the Lasso 8.x replacement by Jason Huck https://gist.github.com/jasonhuck/f281afaa528c82a596a9
@Ke-
Ke- / tab_to_maps.lasso
Created April 6, 2019 00:20
Tab delimited data to array of Lasso maps.
define tab_to_maps(p::staticarray) => tab_to_map(: #p )
define tab_to_maps(p::string, ...) => {
local(
delimiter = '\t',
lines = params->size > 1 ? params | #p->split('\n'),
cols = #lines->first->split(#delimiter),
out = array
)
@Ke-
Ke- / encode_yaml.lasso
Created April 5, 2019 23:01
Encode YAML for Lasso 9
define encode_yaml => type {
data public d = 0
public oncreate(p::pair, ...) => (with p in params sum .encode(#p) + '\n')
public oncreate(p::any) => .encode(#p)
public encode(p::map) => {
local(out) = array
.d++
/*/////////////////////////////////////////////////////////////////////////////
//
// JSON encoder for Lasso 9 (UTF-8)
//
///////////////////////////////////////////////////////////////////////////////
Skips encoding non-ASCII characters instead relies
on requirement specified in the spec.
From the spec: http://www.ietf.org/rfc/rfc4627.txt
@Ke-
Ke- / init.lasso
Created June 16, 2016 22:52
LassoApp reloader
/////////////////////////////////////////////////////////////////////////
//
// App type loader
//
/////////////////////////////////////////////////////////////////////////
! ::init_thread->istype
? define init_thread => thread {
public lassoapps => {
stdoutnl('init: lassoapps')
// Thread objects to store data
! ::global_store_00->istype ? define global_store_00 => thread {parent map public oncreate => ..oncreate}
! ::global_store_01->istype ? define global_store_01 => thread {parent map public oncreate => ..oncreate}
! ::global_store_02->istype ? define global_store_02 => thread {parent map public oncreate => ..oncreate}
! ::global_store_03->istype ? define global_store_03 => thread {parent map public oncreate => ..oncreate}
! ::global_store_04->istype ? define global_store_04 => thread {parent map public oncreate => ..oncreate}
// Establish store to use
define global_store(name::string) => {
@Ke-
Ke- / file_signature.lasso
Last active May 5, 2016 22:10
file_signature detection for Lasso 9.
// Base on https://en.wikipedia.org/wiki/List_of_file_signatures
define file_signature(filedata::bytes) => {
local(hex) = #filedata->sub(1, 32)->encodehex
match(true) => {
case(#hex->substring(1, 2) == "00") return (: "PIC","PIF","SEA","YTR")
case(#hex->substring(12, 16) == "0000000000000000") return (: "PDB")
case(#hex->substring(12, 16) == "0000000000000000") return (: "PDB")
var router = (function() {
var self = {}
var usehistory = window && window.history.pushState ? 1 : 0;
self.routes = {}
self.go = function(url,title,state){
self.push(url,title,state)
self.execute(url)
}
@Ke-
Ke- / gist:a453694ce1293800e6f4
Last active October 15, 2015 11:03
map vs hashtable vs match
/* Local results
Random access
array((micros = 4593.000000), (micros_average = 459.300000)) - map
array((micros = 3266.000000), (micros_average = 326.600000)) - hashtable
array((micros = 17445.000000), (micros_average = 1744.500000)) - match
"First item" D90CC508-C8B9-46CA-A527-85DE0E4CF387
array((micros = 4785.000000), (micros_average = 4.785000)) - map
array((micros = 3977.000000), (micros_average = 3.977000)) - hashtable
<?lasso
define oauth_consumer_key => 'key'
define oauth_consumer_secret => 'secret'
define oauth_request_token => 'requestkey'
define oauth_request_secret => 'requestsecret'
define oauth_access_token => 'accesskey'
define oauth_access_secret => 'accesssecret'
define oauth_realm => 'http://term.ie/'
define oauth_request_endpoint => {return 'http://term.ie/oauth/example/request_token.php'}
define oauth_access_endpoint => 'http://term.ie/oauth/example/access_token.php'