Skip to content

Instantly share code, notes, and snippets.

View ewanharris's full-sized avatar

Ewan Harris ewanharris

View GitHub Profile
@ewanharris
ewanharris / condition-based-store.fga.yaml
Last active September 17, 2024 12:00
Approaches to multi-tenant entitlements in OpenFGA
# In this store we've taken the approach of having a condition that checks the assigned org against the active org that is provided as context on the request
name: Entitlements
model: |
model
schema 1.1
type user
type organization
relations
Feature: Check folder access
Background:
Given folder:5 is a parent of folder:product-2021
* folder:product-2021 is a parent of folder:product-2021Q1
* folder:product is a parent of folder:product-2021
Scenario: user:anne can read and write but not share folder:product-2021
Given user:anne is an owner of folder:product
When she accesses folder:product-2021
@ewanharris
ewanharris / index.js
Last active June 20, 2023 22:09
Script to extract from package.json and write to package.nls.json
const fs = require('fs-extra');
const packageJson = require('./package.json');
const existing = require('./package.nls.json');
function handleStringEdit (str, obj, key) {
if (!obj[key] || obj[key]?.startsWith('%')) {
return;
}
existing[str] = obj[key];
obj[key] = `%${str}%`;
@ewanharris
ewanharris / 12.1.0.GA
Created April 27, 2023 21:28
macos errors
[TRACE] #import "TiAppiOSActivityAttributesProxy.h"
[TRACE] ^
[TRACE] /Users/awam/Documents/titanium-workspace/test-app/build/iphone/Classes/TiAppiOSActivityAttributesProxy.h:10:9: error: 'TitaniumKit/TitaniumKit.h' file not found
[TRACE] #import <TitaniumKit/TitaniumKit.h>
[TRACE] ^
[TRACE] /Users/awam/Documents/titanium-workspace/test-app/build/iphone/Classes/TiAppiOSActivityAttributesProxy.h:10:9: note: did not find header 'TitaniumKit.h' in framework 'TitaniumKit' (loaded from '/Users/awam/Documents/titanium-workspace/test-app/build/iphone/build/Products/Debug-maccatalyst')
[TRACE] #import <TitaniumKit/TitaniumKit.h>
[TRACE] ^
[TRACE] 1 error generated.
[TRACE] <unknown>:0: error: failed to emit precompiled header '/Users/awam/Documents/titanium-workspace/test-app/build/iphone/build/Intermediates/PrecompiledHeaders/test_app-Bridging-Header-swift_2S904Q57JC3MW-clang_38YETQ0XB7NQN.pch' for bridging header '/Users/awam/Documents/titanium-workspace/test-app/build/iphone/test_
@ewanharris
ewanharris / new.json
Created June 24, 2022 21:04
Old and new json output
{
"branch": {},
"branches": false,
"defaultInstallLocation": "/Users/user/Library/Application Support/Titanium",
"installLocations": [
"/Library/Application Support/Titanium",
"/Users/user/Library/Application Support/Titanium"
],
"installed": {},
"releases": [
@ewanharris
ewanharris / app.js
Created June 28, 2021 09:26
Calendar sample iOS
const win = Ti.UI.createWindow();
function createEvent() {
let calendarId;
for (const calendar of Ti.Calendar.allCalendars) {
Ti.API.info(calendar.name, calendar.id);
// This probably is not good enough for an app, the calendar most likely should be selected by the user
if (calendar.name === 'Calendar') {
calendarId = calendar.id
}
@ewanharris
ewanharris / index.mjs
Last active June 9, 2021 22:49
Check for all PRs that had more than 30 commits
/**
* Requirements:
*
* node 14
* these dependencies - npm i @octokit/rest date-fns fs-extra
*/
import fs from 'fs-extra';
import { isAfter } from 'date-fns';
import Octokit from '@octokit/rest';
@ewanharris
ewanharris / app.js
Created November 24, 2020 12:36
Image creation from LivePhoto
const win = Ti.UI.createWindow({ layout: 'vertical' });
const singleBtn = Ti.UI.createButton({ title: 'Select single', top: 50 });
singleBtn.addEventListener('click', () => {
selectImage(false);
});
win.add(singleBtn);
const multiBtn = Ti.UI.createButton({ title: 'Select multiple' });
multiBtn.addEventListener('click', () => {
selectImage(true);
});
@ewanharris
ewanharris / check-module.sh
Last active January 11, 2021 08:55
Script to check Titanium modules for references to UIWebView
#!/usr/bin/env bash
FOLDER=$1
echo "Checking $FOLDER"
# Check for references to UIWebView in the build .a files using strings
for file in "$FOLDER"/*.a; do
strings "$file" | grep UIWeb > /dev/null 2>&1
if [ $? -eq 0 ]
@ewanharris
ewanharris / Tiapp Permissions.md
Last active June 25, 2021 12:09
Download and update an APK in Titanium

Add the below to your tiapp

<android xmlns:android="http://schemas.android.com/apk/res/android">
    <manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1">
      <uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES"/>
      <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
      <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    </manifest>