Skip to content

Instantly share code, notes, and snippets.

def _set_files(files):
if current.request.ajax:
current.response.js = (current.response.js or '') + """;(function ($) {
var srcs = $('script').map(function(){return $(this).attr('src');}),
hrefs = $('link').map(function(){return $(this).attr('href');});
$.each(%s, function() {
if ((this.slice(-3) == '.js') && ($.inArray(this.toString(), srcs) == -1)) {
var el = document.createElement('script'); el.type = 'text/javascript'; el.src = this;
document.body.appendChild(el);
} else if ((this.slice(-4) == '.css') && ($.inArray(this.toString(), hrefs) == -1)) {
script = SCRIPT("""
jQuery(function() { var t = 10; (function run() {if ((function() {
var el = jQuery("#%(id)s");
if (el.AnyTime_picker == undefined) { return true; }
el.AnyTime_noPicker().AnyTime_picker(
jQuery.extend({format: "%%Y-%%m-%%d", labelTitle: "%(title)s"},
%(date_option)s));
})()) {setTimeout(run, t); t = 2*t;}})();});
""" % dict(id=_id, title=current.T('Choose date'),
date_option=_get_date_option()))
@kenji4569
kenji4569 / gist:1326961
Created October 31, 2011 05:28
descendants_from_node
def descendants_from_node(self, node, include_self=False):
db, table_node = self.db, self.settings.table_node
node = self._load_node(node)
left, right = node.left, node.right
if include_self:
left -= 1
right += 1
return db(table_node.left > left)(table_node.right < right)(
--- a/modules/plugin_lazy_options_widget.py
+++ b/modules/plugin_lazy_options_widget.py
@@ -37,6 +37,9 @@ class lazy_options_widget(SQLFORM.widgets.options):
self.keyword = self.keyword % dict(fieldname=field.name)
requires = field.requires
+
+ if isinstance(requires, IS_EMPTY_OR):
+ requires = requires.other
if not isinstance(requires, (list, tuple)):
@kenji4569
kenji4569 / gist:4123139
Created November 21, 2012 05:09
simple block-based task queue
NSMutableArray *tasks = [[NSMutableArray alloc] init];
[tasks addObject: ^() {
NSLog(@"task1");
}];
[tasks addObject: ^() {
NSLog(@"task2");
}];
for (void (^task)() in tasks) {
task();
}
@kenji4569
kenji4569 / gist:4123150
Created November 21, 2012 05:11
simple block-based task queue with cascade
NSMutableArray *tasks = [[NSMutableArray alloc] init];
void (^nextTask)() = ^() {
[tasks removeObjectAtIndex: 0];
if ([tasks count] > 0) {
void (^task)() = [tasks objectAtIndex: 0];
task();
}
};
[tasks addObject: ^() {
NSLog(@"task1");
@kenji4569
kenji4569 / gist:4123263
Created November 21, 2012 05:36
simple block-based task queue with cascade and async trail processing
dispatch_queue_t trail_queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_group_t trail_group = dispatch_group_create();
NSMutableArray *tasks = [[NSMutableArray alloc] init];
void (^nextTask)() = ^() {
[tasks removeObjectAtIndex: 0];
if ([tasks count] > 0) {
void (^task)() = [tasks objectAtIndex: 0];
task();
} else {
@kenji4569
kenji4569 / gist:4256217
Created December 11, 2012 05:57
Breadcrumbs; My first winrt custom control.
//////////////////////////////////////////////////////
// In SamplePage.xaml
//////////////////////////////////////////////////////
<local:Breadcrumbs Height="25" MaxWidth="475"
ItemsSource="{Binding Source={StaticResource sampleBreadcrumbsViewSource}}"
>
<local:Breadcrumbs.ItemTemplate>
<DataTemplate>
<Button VerticalAlignment="Top" Margin="0,0,5,0"
@kenji4569
kenji4569 / ulid_converter.sql
Last active October 8, 2024 06:42
ULID (26 characters in Crockford's base32) conversion for MySQL function
# Define ULID_DECODE and ULID_ENCODE which convert a ulid string to a binary and vice versa.
delimiter //
DROP FUNCTION IF EXISTS ULID_DECODE//
CREATE FUNCTION ULID_DECODE (s CHAR(26)) RETURNS BINARY(16) DETERMINISTIC
BEGIN
DECLARE s_base32 CHAR(26);
SET s_base32 = REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(UPPER(s), 'J', 'I'), 'K', 'J'), 'M', 'K'), 'N', 'L'), 'P', 'M'), 'Q', 'N'), 'R', 'O'), 'S', 'P'), 'T', 'Q'), 'V', 'R'), 'W', 'S'), 'X', 'T'), 'Y', 'U'), 'Z', 'V');
RETURN UNHEX(CONCAT(LPAD(CONV(SUBSTRING(s_base32, 1, 2), 32, 16), 2, '0'), LPAD(CONV(SUBSTRING(s_base32, 3, 12), 32, 16), 15, '0'), LPAD(CONV(SUBSTRING(s_base32, 15, 12), 32, 16), 15, '0')));
END//

Resize Vagrant Disk

Step 1: Create VDI disk from VMDK disk type

# Turn off your Vagrant machine
$ vagrant halt

# Comment out this line in Vagrantfile
# config.disksize.size = '30GB'