Skip to content

Instantly share code, notes, and snippets.

Christopher Meyer chriscdn

View GitHub Profile
@chriscdn
chriscdn / asyncArray.js
Last active Apr 9, 2019
A JavaScript Array forEach and map implementation to minimise UI blocking.
View asyncArray.js
// Curious to know more? Read here: https://stackoverflow.com/questions/36588775/are-javascript-promise-asynchronous
export function asyncForEach(items, cb) {
return new Promise(resolve => {
items.forEach((item, index, items) => {
// This is async such that we can add an await on cb.
// This ensures resolve() is called after the last iteration has completed.
setTimeout(async () => {
await cb(item, index, items)
if (index == items.length - 1) {
resolve()
@chriscdn
chriscdn / README.md
Last active Jul 24, 2018 — forked from paumoreno/README.md
Extract all messages from a Vue.js with vue-i18n app, using gettext-extractor.
View README.md

Original readme.md

This script uses the great message extraction library gettext-extractor by lukasgeiter.

The script assumes that the location of the source files is ./src. It parses both .js and .vue files. It writes the PO template file in ./i18n/messages.pot.

Some things to note:

  • It assumes that interpolations in the templates use the delimieters {{}} (it is the most commmon case).
  • It assumes that both the template and the script sections of the .vue single file components are defined inline, and not referenced by a src attribue (it is the most common case).
@chriscdn
chriscdn / valueForKeyPath.js
Last active Mar 19, 2018
A valueForKeyPath function for JavaScript objects
View valueForKeyPath.js
function valueForKeyPath(obj, keypath) {
return keypath.split('.').reduce(function(previous, current) {
return (previous != undefined) && (typeof previous === 'object') && (current in previous) ? previous[current] : undefined;
}, obj);
}
@chriscdn
chriscdn / put_as_create.py
Created Nov 12, 2015 — forked from tomchristie/put_as_create.py
PUT-as-create mixin class for Django REST framework.
View put_as_create.py
class AllowPUTAsCreateMixin(object):
"""
The following mixin class may be used in order to support PUT-as-create
behavior for incoming requests.
"""
def update(self, request, *args, **kwargs):
partial = kwargs.pop('partial', False)
instance = self.get_object_or_none()
serializer = self.get_serializer(instance, data=request.data, partial=partial)
serializer.is_valid(raise_exception=True)
@chriscdn
chriscdn / CLLocation+rhextensions.h
Last active Aug 17, 2018
A CLLocation category for determing the time zone from a location.
View CLLocation+rhextensions.h
//
// CLLocation+rhextensions.h
//
// Copyright (C) 2015 by Christopher Meyer
// http://schwiiz.org/
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
@chriscdn
chriscdn / CS10.0 Logout Link
Created Oct 16, 2014
In later versions of CS10.0 a secure token is required for logout. This snippet can be placed in the appearance header to extract the logout link and execute it.
View CS10.0 Logout Link
@chriscdn
chriscdn / super.lxe
Last active Aug 29, 2015
A function for making super calls in OpenText Content Server OScript.
View super.lxe
/**
* Christopher Meyer chris@rhouse.ch
* Copyright 2014 Red House Consulting GmbH
*
* Version: 1.3
*/
function Dynamic super(Object item, String func)
switch GetMethodType(item, func)
@chriscdn
chriscdn / beautify_oscript.lxe
Last active Sep 2, 2018
beautify_oscript.lxe - A code beautifier for OpenText Content Server OScript
View beautify_oscript.lxe
/**
* beautify_oscript.lxe - A code beautifier for OpenText Content Server OScript
*
* This script will beautify your OScript. Copy to a file within opentext/scripts/
* (e.g., opentext/scripts/beautify_oscript.lxe), restart Builder, place the focus on a
* script window, and run from the Tools menu.
*
* Some coding conventions assumed. Use at your own risk.
*
* Christopher Meyer (chris@schwiiz.org)
You can’t perform that action at this time.