Skip to content

Instantly share code, notes, and snippets.

@d0rsha
d0rsha / snippet.ts
Last active September 6, 2019 11:02
[Console.log] Console.log #JavaScript
// JavaScript debug toolbox
// Measure
console.time() // Starts a timer (can track how long an operation takes)
console.timeEnd() // Stops a timer that was previously started by console.time()
console.count();
let start = performance.now(); // better accuracy
let execTime = start - performance.now(); // than above
@d0rsha
d0rsha / async.ts
Created February 26, 2019 21:19
[Async] Async await over promises
const random = () => { return Promise.resolve(Math.random()); }
// Callback hell
const sum randomAsyncAwait = () => {
let first;
let second;
let third;
return random.then(val => {
first = val;
@d0rsha
d0rsha / firebase_get_url.ts
Last active April 25, 2019 21:05
[getImageURL] Observable #firebase
imageObservables = {};
getImageUrl(ref: string) {
if (!ref) { return; }
const regEx: RegExp = /^[0-9]/;
if (!regEx.test(ref.charAt(0))) { return; }
if (ref in this.imageObservables) {
return this.imageObservables[ref];
} else {
@d0rsha
d0rsha / AndroidSetup.md
Last active March 28, 2019 14:44
[Environment] Ionic setup android env #ionic #android
@d0rsha
d0rsha / deployment.md
Last active March 27, 2019 19:15
[Deployment] Setting up Ionic for development #ionic

Deployment build Ionic Prototype

__ Update your version in config.xml__

Test in browser before

ionic cordova run browser --prod --release 

ionic cordova resources
ionic cordova build android --prod --release
## --prod compress apk && uses the 'prod' envrionment at build time, --release makes the app signable (so that it can be pusblished in marketplace)
@d0rsha
d0rsha / firebase.md
Last active March 14, 2019 09:11
[Firebase setup] Setup Firebase in Ionic #firebase

With Firebase you can choose between Realtime database & Cloudn Firestore depending on you pricing plan.
With the onSnapshot(..) function your client app will be updated imidiately after your server get updated, always realtime updates!
Other perks:

  • Cloud functions
  • Upgrade price plan as you grow
  • Firebase is very likely to continue be maintained in the future.

Getting started with Firebase

npm install -g firebase-tools

@d0rsha
d0rsha / authGuard.md
Last active March 27, 2019 19:08
[Plugins] Cordova plugins in Ionic #ionic #cordova

-support-google-services --save Full Instructions @ https://github.com/chemerisuk`ionic g guard guards/auth`

{ path: 'nav', canActivate: [AuthGuard], loadChildren: './navigation/navigation.module#NavigationPageModule' },
@d0rsha
d0rsha / cheatsheet.md
Last active April 25, 2019 21:05
[Markdown Cheatsheet] A markdown cheatsheet #programming

Markdown Cheatsheet

Headers
# H1
## H2
### H3
#### H4
##### H5
###### H6
@d0rsha
d0rsha / howTo.md
Last active April 25, 2019 21:06
[static service] How to use static variables by adding static services w/ variables #ionic

In mySerivce.ts make sure it is providedIn 'root'

@injectable({
  provideIn: 'root'
)}
export class myService { ... }  

In app.module.ts add the service to Providers

@d0rsha
d0rsha / cachemap.ts
Last active April 25, 2019 21:06
[cache Map] Save values to map instead of reinvoking call #programming
// Dictionary with Observable
dictionary = {};
getItem(name) {
if (name in this.dictionary) {
return this.dictionary[name]
} else {
this.dictionary[name] = getObserverableByName(name)
return this.dictionary[name]
}