View Codes.re
module StringMap = Map.Make({ type t = string; let compare = compare; });
let mapFromList = (pairs: list((string, 'a))): StringMap.t('a) =>
List.fold_left((map, (k, v)) => StringMap.add(k, v, map), StringMap.empty, pairs);
let mapGet = (key: string, defaultValue: 'a, mapping: StringMap.t('a)): 'a =>
switch (StringMap.find(key, mapping)) {
| exception Not_found => defaultValue
| value => value
};
View puppeteer-click-by-text.js
const puppeteer = require('puppeteer');
const escapeXpathString = str => {
const splitedQuotes = str.replace(/'/g, `', "'", '`);
return `concat('${splitedQuotes}', '')`;
};
const clickByText = async (page, text) => {
const escapedText = escapeXpathString(text);
const linkHandlers = await page.$x(`//a[contains(text(), ${escapedText})]`);
View escape-xpath-string.js
function escapeXpathString(str) {
const splitedQuotes = str.replace(/'/g, `', "'", '`);
return `concat('${splitedQuotes}', '')`;
}
View 1simple-counter.js
import React from 'react';
import { build } from "./declarative-component";
const initialState = { value: 0 };
const actions = {
decrement: (num) => state => ({ ...state, value: state.value - 1 }),
increment: (num) => state => ({ ...state, value: state.value + 1 }),
};
View Counter.js
/* Simple counter example. Decorate any method that returns new state, including
lifecycle component methods. */
import React from 'react';
import { action } from './action';
class Counter extends React.PureComponent {
constructor(props) {
super(props);
this.state = { value : 0 };
}
View convert-mod-track-to-video.sh
#!/bin/bash
#
# Record a video of a mod/s3m/xm tracker song played using milkytracker.
#
# Dependencies with versions used in parenthesis:
#
# schismtracker / milkytracker
# pulseaudio
# vnc2flv
# turbovnc
View xfce4-save-session.sh
#!/bin/sh
exec dbus-send \
--session \
--dest=org.xfce.SessionManager \
--print-reply /org/xfce/SessionManager \
org.xfce.Session.Manager.Checkpoint string:""
View FeedBackToolGithub.js
/* https://github.com/eisnerd/feedback-tool + github issues
Example:
$.feedbackGithub({
token: "16222221222128357fab95ec80b56a43c9a1868b429",
issues: {
repository: "tokland/feedback-test",
title: "feedback from user",
renderBody: (body) => "my own data\n" + body,
View promise_map.js
function promiseMap(xs, f) {
const reducer = (ysAcc$, x) =>
ysAcc$.then(ysAcc => f(x).then(y => ysAcc.push(y) && ysAcc));
return xs.reduce(reducer, Promise.resolve([]));
}
/* Example */
const axios = require('axios');
View data-entry-contentscript.js
/*
Group subsections tabs (with names "section@subsection1", "section@subsection2") into a single tab "section"
Save as a contentscript in DHIS2 app customJS/CSS (https://www.dhis2.org/download/appstore/customjscss.zip)
*/
var init = function(contentEl) {
var MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
var displayingTabs = contentEl.children().size() > 0;
var observer = new MutationObserver(function(mutations, observer) {
if (!displayingTabs && contentEl.children().size() > 0) {