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 / encodesql_full.lasso
Last active August 29, 2015 13:58
Alternative to encode_sql that also deals with escaping % and _. For Lasso 9
[
/**!
encodesql_full
Alternative to encode_sql that also deals with escaping % and _ so that the resulting string can be safely used when creating sql queries with LIKE sections.
See Bil Corrys talk from LDC Chicago 2008: All Your Base Are Belong To Us
Only needed when dealing with SQL queries using LIKE statements (or any of the other pattern- matching queries that recognize “%” and “_”).
Example usage
var(sql = 'SELECT *
@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)
@jolle-c
jolle-c / jc_eachVisibleFilePathRecursive.lasso
Last active August 29, 2015 13:58
Additions to Lasso 9 dir type that will filter out any invisible files or directories
[
/**!
Additions to Lasso 9 dir type that will filter out any invisible files or directories
The built in method dir -> eachFilePathRecursive returns all files and directories found
in the given path. Using dir -> eachVisibleFilePathRecursive will only return visible files
and directories. Very useful if you for example want to get a listing without possible
SVN directories in the path.
@jolle-c
jolle-c / string_trim.lasso
Last active August 29, 2015 13:58
Adding an optional param to string -> trim so that it works on any character.
[
/**!
Lasso 9
Adding an optional param to string -> trim so that it works on any character.
Example
local(mypath = response_filepath)
#mypath -> trim('/')
#mypath
local(mystring = 'xxxräksmörgåsxx')
@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 / Lasso_icalendar.lasso
Last active August 29, 2015 14:07
Method to create and package an Icalendar bytes object. Can handle a single ical event or an entire calendar.
[
/*
2014-10-08 JC Added to Gist
*/
/**!
ical_encodebreak
Method to ensure that the given string complies to the icalendar requirements that no row inside an icalendar object is longer than 75 octets (bytes)
@jolle-c
jolle-c / client_ip_isin.lasso
Last active August 29, 2015 14:07
Method to check if client_ip matches any of the strings in a provided staticarray
[
/**!
client_ip_isin
Will return true if client_ip matches any of the strings in the provided staticarray
Examples
client_ip_isin((: '127.*', '90.229.223.*'))
2014-10-08 JC Added to Gist
2014-09-10 JC First version
@jolle-c
jolle-c / valid_date.lasso
Last active August 29, 2015 14:07
Replacement of valid_date that adds an optional param -strict
[
/**!
valid_date
Replacement of valid_date that adds an optional param -strict. When set to true it will fail on dates that doesn't exist in the real world. Like 2010-02-31.
When used with strict assumes that date inputs are either as ISO or US date format.
2014-10-13 JC Added to Gist
@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 / movefiles.lasso
Last active August 29, 2015 14:13
Command line script to move all newly added files from the original directory to a permanent storage directory and also create a DB record for each file moved
#!/usr/bin/lasso9
database_initialize
local(
date = date,
tmp_filef = '//path/to/tmp_files/',
stored_filef = '//path/to/stored_files/',
path = #stored_filef + #date -> format(`yyyyMMddHHmmss`),
movetodir = dir(#path),