Skip to content

Instantly share code, notes, and snippets.

@declaresub
declaresub / browser.js
Created December 3, 2022 16:26
Configure nuxt to use Mock Service Worker
import { setupWorker } from 'msw'
import { handlers } from './api/index'
// This configures a Service Worker with the given request handlers.
export const worker = setupWorker(...handlers)
@declaresub
declaresub / gist:e353609c3fdb99e7000d439814c0a726
Created February 28, 2022 17:52
Create Python tuple with assignment expression
# The following example demonstrates a use of a Python assignment expression in the course of parsing a str into a tuple.
# The value kid contains a key type and a key lookup id, delimited by '-'. The goal is to split them apart and
# convert the key lookup id to int, with little regard for readability.
kid = 'pwid-43'
key_type, key_sn = ((x:=kid.split('-'))[0], int(x[1]))
# To limit the scope of the variable to the expression, one can wrap the expression into a lambda function.
key_type, key_sn = (lambda kid: ((x:=kid.split('-'))[0], int(x[1])))(kid)
@declaresub
declaresub / backup.xojo_script
Created August 3, 2015 15:16
Xojo example code for backing up a folder.
Sub Backup(source as FolderItem, destination as FolderItem)
if source is nil then
dim e as new NilObjectException
e.Message = "Backup failed. source is nil."
raise e
end if
if destination is nil then
dim e as new NilObjectException
e.Message = "Backup failed. destination is nil."
raise e
@declaresub
declaresub / gist:2cf0e6f4a08129e2a4e4
Created July 17, 2014 14:19
Python logging.config.dictConfig example
#! /usr/bin/python
from logging import getLogger
from logging.config import dictConfig
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters':
@declaresub
declaresub / gist:8a056ba75395d63f9808
Created May 1, 2014 18:50
Simple javascript thunk example
var X =
{
foo: function()
{
var bar=function(){return 'Thunk!';};
this.foo = bar;
return bar.call(this);
}
};