Skip to content

Instantly share code, notes, and snippets.

View jolle-c's full-sized avatar

Jolle Carlestam jolle-c

  • Kulturfaktorn
  • Lund, Sweden
View GitHub Profile
@jolle-c
jolle-c / hash_sha512.lasso
Last active March 13, 2019 05:50
Returns a hashed string using SHA512 for hashing
[
/**!----------------------------------------------------------------------------
hash_sha512.lasso
Author: Jolle Carlestam
License: Public Domain
Description:
For when you want a hashed string using SHA512 for hashing.
Requires the Lasso 9 version of shell
@jolle-c
jolle-c / kin_slugify.lasso
Last active September 26, 2018 08:00
For when you want a string, like a headline for a news article, to be used as part of a URL
[
/*----------------------------------------------------------------------------
kin_slugify.lasso
Author: Jolle Carlestam
License: Public Domain
Description:
For when you want a string, like a headline for a news article, to be used as part of a URL. Safe to send out in the wild.
@jolle-c
jolle-c / safe_filename.lasso
Created November 10, 2017 09:31
safe_filename will take a string as input and return a string safe to use as a file name
define safe_filename(
filename::string,
-replacechar::string = '-',
-clearemoji::boolean = false,
-noleadingperiod::boolean = false,
-allowed_length::integer = 255
) => {
local(_filename = string(#filename))
@jolle-c
jolle-c / jwt.lasso
Created April 25, 2017 07:44
JSON Web Token (JWT) type for Lasso 9
[
/**!
jwt
Lasso 9 type to sign, encode and verify JSON Web Tokens (JWT).
Requires a version of Lasso that supports json_encode and json_decode.
Developed and tested on Lasso 9.3.
Inspired by methods published by Alex Betz on Lasso Talk in April 2017
2017-04-25 JC First version
@jolle-c
jolle-c / shell.lasso
Last active March 13, 2019 06:07
Wrapper for sys_process
[
/**!----------------------------------------------------------------------------
shell.lasso
Adaptation of Jason Huck's Shell tag for Lasso 8.5
Author: Jonathan Guthrie, Jolle Carlestam
Last Modified: 2018-03-20
License: Public Domain
@jolle-c
jolle-c / array -> encodesql
Created March 1, 2017 09:51
Will make sql injection safe string of each item in an array
/**!
array -> encodesql
Adds a method to the lasso 9 array and staticarray types that will run encodesql on each item in the array.
This changes the array in place.
It also alters each item to type string.
EXAMPLE USAGE
local(ids = array('1', '5', '22'))
local(sql = "SELECT * FROM mytable AS mt
@jolle-c
jolle-c / client_ip_isin.lasso
Created February 3, 2016 10:24
Lasso 9 method to check if a range of IP numbers match the current client ip
/**!
client_ip_isin
Will return true if client_ip matches any of the strings in the provided staticarray
Examples
client_ip_isin((: '127.*', '94.219.224.*'))
2014-09-10 JC First version
*/
/**!
export_csv
Will export all rows from the given table as a csv file. First row will be the column names.
Depends on Ke Carltons DS found here
https://github.com/zeroloop/ds
Some advantages
It does not rely on creating a temporary file on the server.
Will send accumulated result to the browser ongoing while looping thru the resultset and thus minimize the memory need on the server.
There’s probably no limit on how many records it can export.
@jolle-c
jolle-c / kin_exchangerates.lasso
Created March 27, 2015 22:57
Thread object to serve a fairly accurate exchange rate for a given currency
[
/**!
kin_exchangerates
Thread object to serve a fairly accurate exchange rate for a given currency
To install, go to https://www.openexchangerates.org and sign up for an account.
Insert the app_id below and store the thread file where it will be loaded at startup.
Attempts to update the rates are limited to no more than once an hour.
Call to update rates will be triggered by the first call for a rate. Not when the thread is initialized.
<?LassoScript
/**!
jc_include
Includes a file for processing but allows the call to hand over params to the included file.
Now also supports including files stored in compiled LassoApps
Examples
jc_include(file('includetest.inc'), -name = 'brad', -country = 'UK')
includetest.inc: