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 / 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 / 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 / wrp.lasso
Last active May 2, 2017 06:15
Quick way to grap a web_request param. For Lasso 9
[
/**!
wrp
Quick way to grap a web_request param
2017-05-02 JC Added examples
2014-10-08 JC Added to Gist
2014-10-08 JC Added separate methods for queryparams and postparams
2014-08-24 JC Rewrite of the wrp method once again. This time with code suggested by Brad Lindsay in a lassotalk thread. Introduces the param -all
@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 / jc_session.lasso
Last active July 12, 2016 23:04
Lasso 9 type to handle cookie based sessions
[
/**!
jc_session
Lasso 9 type to handle cookie based sessions
NOTE, as of this release the code is using json_encode/json_decode as a replacement for json_serialize/json_deserialize. If you are running this in an environment prior to Lasso 9.3 you will have to replace all instances of json_encode with json_serialize and json_decode with json_deserialize!
NOTE, if this is an updated version you'll need to add an additional field to the session table. Run the following sql for Mysql:
ALTER TABLE `jc_session`
@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
*/
@jolle-c
jolle-c / jc_fileuploads.lasso
Last active December 17, 2015 07:03
Type for Lasso 9 to facilitate handling of uploaded files.
[
/**!
jc_fileuploads
local(myfile = jc_fileuploads(1)) // the integer is optional and will if provided restrict the method to the n:th count of uploaded files
#myfile -> size // how many files that where uploaded or handled by the type
#myfile -> contenttype // or #myfile -> contenttype(n) when targeting the n:th file // for example image/jpeg
#myfile -> fieldname // #myfile -> fieldname(n)
#myfile -> filesize // #myfile -> filesize(n)
#myfile -> filename // #myfile -> filename(n)