Skip to content

Instantly share code, notes, and snippets.

View ngehlert's full-sized avatar

Nicolas Gehlert ngehlert

  • Freiburg im Breisgau, Germany
View GitHub Profile
@ngehlert
ngehlert / parent.plist
Created November 9, 2019 23:47
Entitlements to read files/directories with electron
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.application-groups</key>
<string>APPLE_GROUP_STRING</string>
<key>com.apple.security.files.user-selected.read-write</key>
<true/>
@ngehlert
ngehlert / electron.js
Last active May 4, 2021 06:49
Show open dialog with security scoped bookmarks and access them
const settings = require('electron-settings');
dialog
.showOpenDialog(mainWindow, {
properties: ['openDirectory'],
securityScopedBookmarks: true,
})
.then(({ canceled, filePaths, bookmarks }) => {
// If the dialog was canceled or no directory/file selected we don't want to do anything
if (canceled || filePaths.length === 0) {
@ngehlert
ngehlert / excel-column-sort.ts
Created January 28, 2019 15:39
Helper function to create Excel-column-like alphabet sorting values; e.g. 1 --> A, 2 --> B, 27 --> AA, 28 --> AB, etc
function numberToLetters(index: number): string {
const charLimit: number = 26;
if (index > charLimit) {
if (index % charLimit === 0) {
return `${numberToLetters((index / charLimit) - 1)}${numberToLetters(charLimit)}`;
} else {
return `${numberToLetters(Math.trunc(index / charLimit))}${numberToLetters(index % charLimit)}`;
}
} else {
const a: number = 'A'.charCodeAt(0);
@ngehlert
ngehlert / event-handler.ts
Created March 23, 2018 23:32
ES6 Typescript EventHelper class that allows for easier registering/deregistering of arrow functions and adds oneTimeEventListener
/**
* Helper class for easier registering and deregistering of events
*
* This is especially great if you need to register/deregister ES6 arrow functions. Those are pretty ugly to handle.
*
* Example:
* Old:
* const myMethod = () => {} // do anything
* const myMethodListener = myMethod.bind(this);
*