Skip to content

Instantly share code, notes, and snippets.

@dorey
dorey / import_odkrank_question.py
Last active April 15, 2020 22:18
place in kpi's directory "kpi/scripts" then run
from kpi.models.asset import Asset
import json
ASSET_CONTENT = json.loads('''
{
"survey": [
{
"$autoname": "s1",
"required": false,
"kobo--rank-items": "legacyrankitems",
@dorey
dorey / gist:faf04cba96d239763d3f2dbcbf084d3f
Created April 15, 2020 22:10
place in kpi's directory "kpi/scripts"
from kpi.models.asset import Asset
ASSET_CONTENT = {'choices': [{'$autovalue': 'red',
'$kuid': 'odkr1fAsW',
'label': ['Red'],
'list_name': 'ri2bk45',
'value': 'red'},
{'$autovalue': 'yellow',
'$kuid': 'odkr2f3cX',
'label': ['Yellow'],
@dorey
dorey / test_support_external_instances.py
Created June 15, 2015 17:59
a test using the "pyxform_v1_test_case" format, as in https://github.com/XLSForm/pyxform/pull/28
from pyxform_test_case import PyxformTestCase
class TestSupportExternalInstances(PyxformTestCase):
def test_csv_externals(self):
# no choice filter
self.assertPyxformXform(
name="test_csv_externals",
md="""
#survey
| type | name | label | choice_filter |
<!-- a tm / sublime snippet to go with https://github.com/abeisgreat/-_-.js -->
<snippet>
<content><![CDATA[ಠ_ಠ( ${1} )]]></content>
<tabTrigger>oo</tabTrigger>
<scope>source.js</scope>
</snippet>
@dorey
dorey / from_jquery.js
Created May 21, 2014 23:35
yuglify breaking on jquery
// Excerpt from jQuery v2.1.1
// a comment in the middle of the Sizzle declaration causes yuglify v0.1.4 to trip up
var Sizzle =
/*!
* Sizzle CSS Selector Engine v1.10.19
* http://sizzlejs.com/
*
* Copyright 2013 jQuery Foundation, Inc. and other contributors
* Released under the MIT license
@dorey
dorey / csv to survey
Created November 25, 2013 10:07
for later reference: this avoids writing to the filesystem and allows you to pass the form_name in through the settings
import pyxform
from StringIO import StringIO
def csv_to_survey(csv_txt):
csv_io = StringIO(csv_txt)
workbook_repr = pyxform.xls2json_backends.csv_to_dict(csv_io)
try:
form_name = workbook_repr['settings'][0][u'id_string']
except KeyError, e:
form_name = "xform"
@dorey
dorey / hacky-hr-pagebreak.js
Created September 17, 2012 22:10
appending an hr into the page whenever an element exceeds a page limit
// dpi.get() code is from stackoverflow:
// http://stackoverflow.com/questions/2252030/how-can-i-find-out-a-web-page-viewers-pixels-per-inch#answer-2312609
var dpi = {
v: 0,
get: function (noCache) {
if (noCache || dpi.v == 0) {
e = document.body.appendChild(document.createElement('DIV'));
e.style.width = '1in';
e.style.padding = '0';
dpi.v = e.offsetWidth;
@dorey
dorey / dpi-gist.js
Created September 17, 2012 21:49
a basic test of logging # of inches of a given element (using a dpi method)
// dpi.get() code is from stackoverflow:
// http://stackoverflow.com/questions/2252030/how-can-i-find-out-a-web-page-viewers-pixels-per-inch#answer-2312609
var dpi = {
v: 0,
get: function (noCache) {
if (noCache || dpi.v == 0) {
e = document.body.appendChild(document.createElement('DIV'));
e.style.width = '1in';
e.style.padding = '0';
dpi.v = e.offsetWidth;
@dorey
dorey / jquery_outerhtml_and_tostring.js
Created September 13, 2012 16:12
possible jquery extension outerHTML and toString methods
$.fn.outerHtml = function() {
// edit:
// var el = $(this).get(0);
var el = this.get(0);
if (el === undefined || !(el instanceof Element)) return false;
if (el.outerHTML !== undefined) return el.outerHTML;
return $('<div>').html($(this).eq(0).clone()).html();
};
/* It could be convenient if jQuery objects had a toString method
@dorey
dorey / django compilemessages on os x
Created August 10, 2011 21:31
uses python-gettext to compile the binary of translation files instead of the shell "msgfmt" script
# after pip installing python-gettext
# these lines go in django.core.management.commands.compilemessages
# they replace the call to "os.system"
from pythongettext import msgfmt
po = msgfmt.Msgfmt(pf + '.po')
moo_file = pf + '.mo'
with open(moo_file, 'w') as f:
f.write(po.get())