This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?lassoscript | |
| /* | |
| Description: | |
| Restricts code from executing more frequently than the specified number of seconds. | |
| Returns the number of seconds to wait until blocks should be executed. | |
| Example: | |
| define my_thread => thread { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| protect => {inline} | |
| define keycolumn_value() => { | |
| local(c = column(keycolumn_name)) | |
| void != #c? return #c | |
| local(curMap = inline_scopeGet) | |
| #curMap && #curMap->size > 0 ? #c = #curMap->find(::currentinline)->dsInfo->forcedRowID | |
| #c->isa(::integer) && #c < 0 ? #c = 2147483648 + (2147483648 + #c) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| define set_user_password(user::string,password::string) => { | |
| #password = security_registry->encodePassword('Lasso Security',#user,#password) | |
| inline( | |
| -database = 'security_auth_registry', | |
| -sql = 'UPDATE users SET password_ha1 = "'+#password->encodesql+'" | |
| WHERE name = "'+#user->encodesql+ '" ' | |
| ) => {} | |
| } | |
| // Usage: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| define cart_id => var(cart_id) || $cart_id := lasso_uniqueid | |
| define current_cart => var(current_cart) || $current_cart := cart->oncreate('id' = cart_id) | |
| define cart => type { | |
| parent activerow | |
| public ds => ds(::example.carts) | |
| public created_column => 'created' | |
| public modified_column => 'modified' | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Inject construct similar to Ruby's inject. | |
| define trait_foreach->inject(p::any) => { | |
| local(gb) = givenblock | |
| #gb->detach | |
| .foreach => { | |
| #p = #gb(#p,#1) || #p | |
| } | |
| return #p | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| define char2int(p::string,mult::integer=1) => { | |
| match(#p) => { | |
| case('a') | |
| return 10 * #mult | |
| case('b') | |
| return 11 * #mult | |
| case('c') | |
| return 12 * #mult | |
| case('d') | |
| return 13 * #mult |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| define sys_info => ( | |
| 'sys_getthreadcount: ' + sys_getthreadcount +'\n' | |
| 'sys_getheapsize: ' + sys_getheapsize +'\n' | |
| 'sys_getheapfreebytes: ' + sys_getheapfreebytes +'\n' | |
| 'sys_getbytessincegc: ' + sys_getbytessincegc +'\n' | |
| 'sys_time: ' + sys_time '\n' | |
| 'sys_getegid: ' + sys_getegid '\n' | |
| 'sys_geteuid: ' + sys_geteuid '\n' | |
| 'sys_getlogin: ' + sys_getlogin '\n' | |
| 'sys_getpid: ' + sys_getpid '\n' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| local( | |
| query = .ds->table( | |
| ::mytable | |
| )->select( | |
| #columns | |
| )->where( | |
| #where | |
| )->orderby( | |
| #orderby | |
| )->limit( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| define sys_slow_value => 1000.0 | |
| define sys_slow_output(p=null) => { | |
| local(s) = micros | |
| define_atend({ | |
| local(t) = (micros - #s) / 1000.0 | |
| #t > sys_slow_value && web_request ? log_critical('SLOW: ' + client_url + ' — ' + #t + ' milliseconds') | |
| }) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Cache method result on a thread level | |
| define cache_method(c::capture = givenblock) => { | |
| #c->isnota(::capture) ? return #c | |
| local(v) = #c->self ? #c->self->type->asstring + '.' + #c->methodname | #c->methodname | |
| var(#v)->isa(::null) ? var(#v) = #c->detach & invoke | |
| return var(#v) | |
| } |
OlderNewer