Skip to content

Instantly share code, notes, and snippets.

@d1manson
d1manson / zotero_word_formatting.vba
Last active January 17, 2016 12:32
set color of zotero references in MSWord using VBA
Sub FormatZoteroRefs()
Set objUndo = Application.UndoRecord
objUndo.StartCustomRecord ("Format Zotero refs")
For Each myStoryRange In ActiveDocument.StoryRanges
For ii = 1 To myStoryRange.Fields.Count
If InStr(1, LTrim(myStoryRange.Fields(ii)), "ADDIN ZOTERO_ITEM CSL_CITATION") = 1 Then
Set rng = myStoryRange.Fields(ii).Result
rng.Font.ColorIndex = 9 ' this seems to be dark blue
@d1manson
d1manson / np_bench.py
Created January 28, 2016 12:11
benchmark np basic math
import timeit
import matplotlib.pylab as plt
pow2s = arange(10,22,0.25)
t_times1 = np.zeros(len(pow2s))
t_sum = np.zeros(len(pow2s))
t_cumsum = np.zeros(len(pow2s))
for ii, pow2 in enumerate(pow2s):
setup = "import numpy as np\na = np.random.rand({})".format(2**pow2)
t_times1[ii] = min(timeit.Timer('a*1.0', setup=setup).repeat(3, 100))/100
% sample data
s1 = 8192; s2 = 200;
img_a = rand(s1, s2);
img_b = rand(s1, s2);
r = 2;
% and the calculation itself
img_diff = img_a - img_b;
kernel = bsxfun(@plus, (-s1:s1).^2', (-s2:s2).^2);
kernel = 1/(2/pi/r^2) * exp(-kernel/ (2*r*2));
@d1manson
d1manson / uk d***ing test booking automated checker.js
Last active May 15, 2016 19:24
script to manually insert into the page to help find cancelations
/*
Go to https://driverpracticaltest.direct.gov.uk, and get to the
"Test time" section. Then, open the F12 developer console, and copy paste
all of the following code. If something breaks, then just refresh the page and
try again. You can modify the configuration below.
Currently date parsing is rather basic, we just get the day for a specific target month,
e.g. May 2016, and then check if that day (e.g. 23rd) is before or equal to the day you
requested. It's not hard to improve upon this but I haven't bothered.
"""
pip install
Download pyhook .whl file from:
http://www.lfd.uci.edu/~gohlke/pythonlibs/#pyhook
Note if you have python 2.7, and 64 bit you need the version:
"pyHook-1.5.1-cp27-none-win_amd64.whl"
otherwise choose the relevant one.
Then open a comand prompt, cd to your downloads folder and run
@d1manson
d1manson / vue-fetch.js
Last active February 10, 2017 17:13
like polymer's ajax component
/*
Example basic usage is something like this:
<div id="vue-mount">
<vue-fetch endpoint="/example" :id="exampleId" :model="exampleModel"></vue-fetch>
{{exampleId}} {{exampleModel.thing}} {{exampleModel.other}}
</div>
<script>
new Vue({
el: "#vue-mount"
// For info on usage, development and debugging,
// see https://docs.google.com/a/landtech.co/document/d/1eB2oH3d7mpDfK8gxTiYphxPgBM7EDu5MeUNKrQwYIrQ/ . [private]
const Painter = require('./render/painter'),
Style = require('./style/style'),
EXTENT = require('./data/extent'),
Evented = require('./util/evented'),
TileCoord = require('./source/tile_coord'),
mat4 = require('@mapbox/gl-matrix').mat4,
Source = require('./source/source'),
@d1manson
d1manson / mongoose-upsert-plugin.js
Created September 28, 2017 10:20
Unlike findOneAndUpdate, this returns both the old and the new docs, the operation is performed atomically
/*
Unlike findOneAndUpdate, this returns both the old and the new docs,
the operation is performed atomically.
Note that although it can apply defaults properly, it does not apply
pre-update hooks, with the exception of timestamps (see note in code).
Example:
Dogs.upsert({owner: 'wallace', name: 'grommit'}, {breakfast: 'eggs'})
@d1manson
d1manson / simulate_3dsecure_action.js
Last active August 31, 2021 17:22
for use in testing stripe intents server side. note this is for use with a test mode key. relies on implementation details that might change
const { STRIPE_PUBLIC_KEY } = process.env,
axios = require("axios"),
qs = require("querystring").stringify,
{ JSDOM } = require("jsdom");
module.exports.simulateAction = async function(
intentId,
clientSecret,
mode = "setup_intent"
) {
@d1manson
d1manson / if_equal.py
Last active October 20, 2021 23:09
Prefect control flow helper, similar to `case`. See https://github.com/PrefectHQ/prefect/issues/5071#issuecomment-947846404
from typing import Any, TYPE_CHECKING, Dict
import prefect
from prefect import Task, Flow
from prefect.triggers import all_successful
from prefect.tasks.control_flow.conditional import CompareValue
from prefect.engine import signals
if TYPE_CHECKING:
from prefect.engine import state # noqa
from prefect import core # noqa