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
<?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:
/**!
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.
@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),
@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 / 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 / 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 / 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 / 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 / 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 *