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
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++) {
@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).
*/
@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 / 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 / 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 / reload.ts
Created May 31, 2018 09:31
Reload screen in Ionic3+
// Use an Event to reload the page
this.events.subscribe('reloadPage', () => {
console.log('app reloaded');
let component = this.navCtrl.getActive().instance;
// call component.ionViewDidLoad() inside whatever data you are refreshing with
// ionViewDidLoad() {} should be where you house your setup code
this.storage.set('garage', newData).then(() => {
component.ionViewDidLoad();
});
// uncomment this if it still didnt work
@dayaki
dayaki / customFont
Created March 2, 2019 23:23
Use custom fonts in React Native
1. Put all your fonts in you React-Native project directory
`./assets/fonts/`
2. Add the following line in your package.json
```
"rnpm": {
"assets": ["./assets/fonts"]
}
```
@dayaki
dayaki / laravel
Created March 31, 2019 00:56
remove /public from laravel url
<IfModule mod_rewrite.c>
# Turn Off mod_dir Redirect For Existing Directories
DirectorySlash Off
# Rewrite For Public Folder
RewriteEngine on
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
@dayaki
dayaki / React Native debug build with RNN
Created May 6, 2019 08:51
Building a debug apk with React Native Navigation
react-native bundle --dev false --platform android --entry-file index.js --bundle-output ./android/app/src/main/assets/index.android.bundle --assets-dest ./android/app/src/main/res
cd android
./gradlew app:assembleDebug
* Generate Icons and SplashScreen
https://github.com/bamlab/generator-rn-toolbox/blob/master/generators/assets/README.md
https://medium.com/@pqkluan/how-to-implement-splash-screen-in-react-native-navigation-ee2184a1a96