Skip to content

Instantly share code, notes, and snippets.

View dayaki's full-sized avatar
🏠
Working from home

Dayo Akinkuowo dayaki

🏠
Working from home
View GitHub Profile
@dayaki
dayaki / ionFocus
Created May 27, 2018 00:54
Set input autofocus on ionic
*imports
import { Component, ViewChild } from '@angular/core';
@ViewChild('focusInput') myInput;
*html
<ion-textarea #focusInput></ion-textarea>
ionViewDidEnter() {
setTimeout(() => {
this.keyboard.show();
@dayaki
dayaki / ionic-app-script fix
Last active March 8, 2018 18:32
fix an issue with ionic and livereload
// exports.ANDROID_PLATFORM_PATH = path.join('platforms', 'android', 'assets', 'www');
exports.ANDROID_PLATFORM_PATH = path.join('platforms', 'android', 'app', 'src', 'main', 'assets', 'www');
@dayaki
dayaki / samples.ts
Created September 20, 2017 10:37
My code samples
/// Storage
// Check if data is stored locallyget new
this.storage.ready().then(() => {
this.storage.get('articles').then((value) => {
if (value === null) {
this.article.loadData().then((data) => {
this.storage.set('articles', data)
this.newsData = data;
});
} else {
@dayaki
dayaki / generate-pushid.js
Created September 12, 2017 13:27 — forked from mikelehen/generate-pushid.js
JavaScript code for generating Firebase Push IDs
/**
* Fancy ID generator that creates 20-character string identifiers with the following properties:
*
* 1. They're based on timestamp so that they sort *after* any existing ids.
* 2. They contain 72-bits of random data after the timestamp so that IDs won't collide with other clients' IDs.
* 3. They sort *lexicographically* (so the timestamp is converted to characters that will sort properly).
* 4. They're monotonically increasing. Even if you generate more than one in the same timestamp, the
* latter ones will sort after the former ones. We do this by using the previous random bits
* but "incrementing" them by 1 (only in the case of a timestamp collision).
*/
slugify(string) {
let str = string.replace(/^\s+|\s+$/g, ''); // trim
str = str.toLowerCase();
// remove accents, swap ñ for n, etc
const from = 'àáäâèéëêìíïîòóöôùúüûñç·/_,:;';
const to = 'aaaaeeeeiiiioooouuuunc------';
for (let i=0, l=from.length ; i<l ; i++) {