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- / Short string integers
Created January 7, 2015 06:46
integer->encodeBase64Short, string->decodeBase64Short
/*
1: AQ
62: Pg
100: Z
1000: 6AM
10000: ECc
100000: oIYB
1000000: QEIP
10000000: gJaY
1000000000: AMqaOw
// Cache method result on a thread level
define whatmethod => {
return givenblock->methodname
}
define whattype => {
return givenblock->self->type
}
@Ke-
Ke- / Byte example
Last active August 29, 2015 14:13
Byte example
local(data) = bytes('Hello')
my_ds->sql("
DROP TABLE IF EXISTS bytes_example;
CREATE TABLE bytes_example (
`data` binary(16) NOT NULL
);
INSERT INTO bytes_example(data) VALUES (X'" +#data->encodehex + "');
@Ke-
Ke- / gist:54b5ba95b9490070e7a6
Last active August 29, 2015 14:22
pop type for Lasso 9 — converted from a L8.x type floating around.
<?lasso
define pop => type {
data
public pop_net = null,
public pop_mode = '',
public pop_timeout = 15,
public pop_token = '',
public pop_index = 0,
public pop_err = array,
<?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'
@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
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- / 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")
// 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- / 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')