Skip to content

Instantly share code, notes, and snippets.

View NickIliev's full-sized avatar

Nikolay Iliev NickIliev

  • Progress
  • Sofia, Bulgaria
View GitHub Profile
@NickIliev
NickIliev / tsconfig.json
Created November 20, 2018 11:46
Enabling JSON imports via tsconfig.json
{
"compilerOptions": {
"module": "commonjs",
"resolveJsonModule": true,
"esModuleInterop": true
}
}
@NickIliev
NickIliev / config.json
Created November 20, 2018 11:49
sample JSON file
{
"count": 42,
"users": [
{"name": "John", "age": 35},
{"name": "Ann", "age": 32},
{"name": "George", "age": 24},
{"name": "Mary", "age": 27},
{"name": "Vivian", "age": 21}
],
"env": "debug"
@NickIliev
NickIliev / home-page.ts
Created November 20, 2018 11:52
Importing JSON files using resolveJsonModule in tsconfig.json
import config from "./config.json";
console.log(config.count); // 42
console.log(config.env); // "debug"
@NickIliev
NickIliev / app.ts
Last active November 22, 2018 12:06
Firebase storage initialization
const APPSPOT_BUCKET_URL = "gs://firebase-storage-demo.appspot.com";
firebase.init({
storageBucket: APPSPOT_BUCKET_URL
// any other options
}).then(() => {
console.log("Firebase init!");
})
service firebase.storage {
match /b/{bucket}/o {
match /{allPaths=**} {
// Allow access by all users
allow read, write;
}
}
}
@NickIliev
NickIliev / main-view-model.ts
Last active November 22, 2018 13:25
Firebase Storage Upload File
import { storage } from "nativescript-plugin-firebase";
import { File, knownFolders, path } from "tns-core-modules/file-system";
import { APPSPOT_BUCKET_URL } from "./shared/link"; // e.g. gs://firebase-storage-demo.appspot.com
uploadFile() {
const appPath = knownFolders.currentApp().path;
// The path to the file we want to upload (this one is in `app/images` and is called `happy-homer-meme.png`)
const logoPath = appPath + "/images/happy-homer-meme.png";
// Upload the file with the options below:
@NickIliev
NickIliev / main-view-model.ts
Last active November 22, 2018 13:43
Firebase Storage Download a File (NativeScript)
downloadFile() {
let downloadPath: string;
let logoPath: string;
let fileName: string = "happy-homer-meme.png";
if (isAndroid) {
// use tns-platform-declarations to access the native Android & iOS APIs
downloadPath = android.os.Environment.getExternalStoragePublicDirectory(android.os.Environment.DIRECTORY_DOWNLOADS).toString();
} else if (isIOS) {
downloadPath = knownFolders.documents().path;
@NickIliev
NickIliev / main-view-model.ts
Last active November 22, 2018 13:42
Firebase Storage get Download URL (NativeScript)
getDownloadUrl() {
storage.getDownloadUrl({
// optional, can also be passed during init() as 'storageBucket' param so we can cache it
bucket: APPSPOT_BUCKET_URL,
// the full path of an existing file in your Firebase storage
remoteFullPath: 'uploads/images/happy-homer-meme.png'
}).then(downloadURL => {
console.log("Download URL: " + downloadURL);
}).catch(error => {
console.log("Error: " + error);
@NickIliev
NickIliev / main-view-model.ts
Created November 22, 2018 13:48
Firebase Storage Delete File (NativeScript)
deleteFile() {
storage.deleteFile({
// optional, can also be passed during init() as 'storageBucket' param so we can cache it
bucket: APPSPOT_BUCKET_URL,
// the full path of an existing file in your Firebase storage
remoteFullPath: 'uploads/images/firebase-storage.png'
}).then(() => {
console.log("File deleted from Firebase Storage.");
}).catch(error => {
console.log("File deletion Error: " + error);
@NickIliev
NickIliev / nativescript.sh
Last active March 29, 2019 07:28
nativescript HMR commands
tns run --hmr