Skip to content

Instantly share code, notes, and snippets.

@sdumitriu
sdumitriu / Tick
Last active June 6, 2023 18:11
A JavaScript question (easy mode)
// What does the following code return? Why?
var outcome = 1,
b = function (x) {
x && b(--x);
outcome += ' tick';
};
b(2);
return outcome;
@sdumitriu
sdumitriu / Tick
Created October 25, 2019 14:54
A JavaScript question (hard mode)
// What does the following code return? Why?
var a = 1,
b = function a(x) {
x && a(--x);
outcome += ' tick';
};
var outcome = a;
b(2);
outcome;
@sdumitriu
sdumitriu / phenotips_tomcat.sh
Last active March 19, 2019 19:28 — forked from josch/phenotips_tomcat.sh
Setting up phenotips on Ubuntu Xenial with Tomcat
#!/bin/sh
set -exu
directory=ubuntu-xenial-robot
debootstrap --variant=minbase --include=dbus,systemd-sysv xenial "$directory" http://archive.ubuntu.com/ubuntu/
systemd-nspawn --boot --directory="$directory" &
pid=$!
@sdumitriu
sdumitriu / gist:bf5c3ba0e5e9fb72d9f10eac51f63a1b
Created July 18, 2018 03:01
Set the proband_id where missing
{{velocity}}
#foreach ($i in $services.query.hql(', BaseObject f, BaseObject p, LargeStringProperty d where f.name = doc.fullName and f.className = ''PhenoTips.FamilyClass'' and p.name = doc.fullName and p.className = ''PhenoTips.PedigreeClass'' and d.id.id = p.id and d.id.name = ''data'' and d.value <> '''' and not exists (from StringProperty prob where prob.id.id = f.id and prob.id.name = ''proband_id'' and prob.value <> '''')').execute())
#set ($d = $xwiki.getDocument($i))
#set ($p = $jsontool.parseToJSONObject($d.getObject('PhenoTips.PedigreeClass').getValue('data')))
#set ($pid = $p.opt('proband'))
#set ($ms = $p.opt('members'))
#set ($pref = false)
#foreach ($m in $ms)
#if ($pid == $m.opt('id'))
#set ($pref = $m.opt('pedigreeProperties').opt('phenotipsId'))
@sdumitriu
sdumitriu / gist:009a9e7b91fcca5356c99211a2866015
Created July 13, 2017 18:24
Search for incorrectly resolved HGNC terms
{{velocity}}
#set ($h = $services.vocabularies.hgnc)
#foreach ($i in $h.search({'id':'*'}, {'rows': '100000'}))
#set ($s = $i.symbol)
#set ($rs = $h.getTerm($i.symbol).symbol)
#if ($s != $rs)
|$s|$rs
#end
#end
{{/velocity}}
@sdumitriu
sdumitriu / fix_collation.sql
Created June 22, 2017 05:15
Change tables to utf8 / utf8_bin
alter table LocalLoginToken convert to character set utf8 collate utf8_bin;
alter table PatientPushedToInfo convert to character set utf8 collate utf8_bin;
alter table PatientSourceServerInfo convert to character set utf8 collate utf8_bin;
alter table RemoteLoginData convert to character set utf8 collate utf8_bin;
alter table activitystream_events convert to character set utf8 collate utf8_bin;
alter table encryptedproperty convert to character set utf8 collate utf8_bin;
alter table feeds_aggregatorgroup convert to character set utf8 collate utf8_bin;
alter table feeds_aggregatorurl convert to character set utf8 collate utf8_bin;
alter table feeds_aggregatorurlgroups convert to character set utf8 collate utf8_bin;
alter table feeds_feedentry convert to character set utf8 collate utf8_bin;
{{comment}}
When migrating PhenoTips data from a virtual instance to another through XAR export and import,
certain inter-document references will still contain the virtual instance identifier in them,
for example "rdconnect:Studies.Ataxia", which means that links between patient records,
users, groups, and studies, will be broken. In order to fix these links, we need to manually
fix this prefix.
0. Move the data from the old instance to the new instance
1. Log in with an administrative account on the new instance
2. Put this script in a new document, for example: /bin/edit/Sandbox/FixWikiId
{{html clean="false"}}
<form action="" method="POST">
<fieldset>
<legend>Check a user's activity and collaborations</legend>
<input type="text" name="uid" class="suggestUsers"/> <span class="buttonwrapper"><input type="submit" value="Check" class="button"/></span>
</fieldset>
{{/html}}
{{velocity}}
#if ("$!request.uid" != '')
@sdumitriu
sdumitriu / README.md
Last active December 5, 2016 16:23
PhenoTips - Change permissions for all/some patient records

To change permissions for all/some patient records, including the template used for future patients, open /bin/edit/Sandbox/ChangePermissions in a browser while logged in with an administrative account, paste the following snippet, and press Preview.

WARNING: Pressing Preview doesn't preview the changes, it will actually modify the permissions!

Things you can adjust:

  • the target visibility, at line 2 replace private with the desired value (hidden, private, matchable, public, open)
  • the target owner, at line 4 replace groupname with the desired group name, or uncomment line 6 and replace username with the desired username
  • the target collaborator, at line 8 replace groupname with the desired group name, or uncomment line 10 and replace username with the desired username
  • the target access level, at line 11 replace edit with the desired value (view, edit, manage)
@sdumitriu
sdumitriu / set_study.sh
Last active November 18, 2016 16:20
PhenoTips - Set a specific study for a patient record via REST
#!/bin/bash
# Change the following three variables to what you need:
XAUTH='Admin:admin'
PATIENT='P0000001'
STUDY='Hereditary motor neuropathies'
# This is the identifier of a virtual instance in a farm
# Most installations aren't set up as farms, so the default shouldn't be changed
INSTANCE='xwiki'