Skip to content

Instantly share code, notes, and snippets.

View emiloberg's full-sized avatar
🦄

Emil Öberg emiloberg

🦄
View GitHub Profile
@emiloberg
emiloberg / promise.ts
Created September 11, 2023 10:43
Type-safe promise.allSettled where a promise may or may not be required
type PromiseObject<T> = {
promise: Promise<T>;
required: boolean;
};
type PromiseResult<T> = T extends Promise<infer U> ? U : never;
type PromiseResults<T extends readonly PromiseObject<unknown>[]> = {
[K in keyof T]: T[K]['required'] extends true
? PromiseResult<T[K]['promise']>
@emiloberg
emiloberg / extract-translations.ts
Created April 14, 2021 20:59
Extract translations from Typescript
/*
* Finds and prints all usage of t()
* Use to extract translations
* Save as file and run:
* ts-node extract-translations.ts
*
* Change ROOT_PATH in this file if needed.
*/
import { readFileSync, readdirSync, statSync } from 'fs';
@emiloberg
emiloberg / cloudSettings
Last active September 3, 2020 15:47
VSCode Settings
{"lastUpload":"2020-09-03T15:47:18.938Z","extensionVersion":"v3.4.3"}
@emiloberg
emiloberg / GaugeChart.js
Last active February 13, 2024 14:30
Gauge Chart with React Recharts (http://recharts.org)
import React from 'react';
import { Sector, Cell, PieChart, Pie } from 'recharts';
const GaugeChart = () => {
const width = 500;
const chartValue = 180;
const colorData = [{
value: 40, // Meaning span is 0 to 40
color: '#663399'
}, {
@emiloberg
emiloberg / gist:81271ba2427278aa4262
Created October 30, 2015 12:16
NativeScript Crash Report Android
java.lang.RuntimeException: Unable to start activity ComponentInfo{se.vgregion.rekapp/com.tns.NativeScriptActivity}: com.tns.NativeScriptException:
Calling js method onCreate failed
Error: android.app.Fragment$InstantiationException: Unable to instantiate fragment com.tns.gen.android.app.Fragment_frnal_prepareExtend_l60_c37__PageFragmentBody: make sure class name exists, is public, and has an empty constructor that is public
android.app.Fragment.instantiate(Fragment.java:597)
android.app.FragmentState.instantiate(Fragment.java:98)
android.app.FragmentManagerImpl.restoreAllState(FragmentManager.java:1762)
android.app.Activity.onCreate(Activity.java:904)
com.tns.Platform.callJSMethodNative(Native Method)
com.tns.Platform.dispatchCallJSMethodNative(Platform.java:821)
com.tns.Platform.callJSMethod(Platform.java:708)
@emiloberg
emiloberg / crashreport.txt
Created October 23, 2015 14:02
nativescript-email crash
Process: MailCompositionService [20544]
Path: /Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 8.1.simruntime/Contents/Resources/RuntimeRoot/Applications/MailCompositionService.app/MailCompositionService
Identifier: MailCompositionService
Version: 1.0 (1.0)
Code Type: X86-64 (Native)
Parent Process: launchd_sim [20491]
Responsible: launchd_sim [20491]
User ID: 501
Date/Time: 2015-10-23 16:01:13.073 +0200
@emiloberg
emiloberg / article.json
Created October 18, 2015 15:30
Sample, DDM Tool article
{
"articleId": "1715401",
"classNameId": 0,
"classPK": 0,
"companyId": 1712101,
"content": "<?xml version=\"1.0\"?>\n\n<root available-locales=\"en_US,sv_SE\" default-locale=\"sv_SE\">\n\t<dynamic-element name=\"heading\" index=\"0\" type=\"text\" index-type=\"keyword\">\n\t\t<dynamic-element name=\"body\" index=\"0\" type=\"text_area\" index-type=\"keyword\">\n\t\t\t<dynamic-element name=\"type\" index=\"0\" type=\"list\" index-type=\"keyword\">\n\t\t\t\t<dynamic-content language-id=\"en_US\"><![CDATA[normal]]></dynamic-content>\n\t\t\t\t<dynamic-content language-id=\"sv_SE\"><![CDATA[normal]]></dynamic-content>\n\t\t\t</dynamic-element>\n\t\t\t<dynamic-element name=\"subheading\" index=\"0\" type=\"text\" index-type=\"keyword\">\n\t\t\t\t<dynamic-content language-id=\"en_US\"><![CDATA[]]></dynamic-content>\n\t\t\t\t<dynamic-content language-id=\"sv_SE\"><![CDATA[]]></dynamic-content>\n\t\t\t</dynamic-element>\n\t\t\t<dynamic-element name=\"image\" index=\"0\" type=\"document_library\" in
@emiloberg
emiloberg / Snippets.txt
Created October 15, 2015 10:46
Snippets for Uppsala JS
DEMO 1
<StackLayout orientation="vertical">
<Button text="one"/>
<Button text="two"/>
<Button text="three"/>
<Button text="four"/>
<Button text="five"/>
</StackLayout>
@emiloberg
emiloberg / Gulpfile.js
Last active February 28, 2021 14:34
Restart node.js and reload Chrome tab(s) when files change
/**
* This Gulpfile will monitor files and restart node.js
* and reload the Chrome browser tab(s) when files changes.
*
* Dependencies:
* gulp npm install -g gulp (obviously as this is a gulp script)
* gulp-nodemon npm install gulp-nodemon
* chrome-cli brew install chrome-cli (https://github.com/prasmussen/chrome-cli)
*
* Installation
@emiloberg
emiloberg / real-time-date-stamp.ftl
Last active August 13, 2020 21:18
This is how you get a real date/time-stamp (such as article published date) in Freemarker in Liferay. With support for multilingual sites. When working with multilingual/non-English sites, date/time-stamp can be a bit of a headache as the date strings are strings with english words in them, such as Thu, 08 May 2014 11:48:00 +0000, rather than a …
<#-- ----------------------------------------------------------------- ->
-
- GETTING REAL TIME/DATE-STAMP
-
- When we ask Liferay for the create date of an article (or really we
- ask Liferay for the 'display-date' which is settable by the user) we get
- a string looking like this: 'Thu, 08 May 2014 11:48:00 +0000'. This
- string will always be in english and when we want to create a datetime
- object from it, we need to parse it with english locale.
-