Skip to content

Instantly share code, notes, and snippets.

@dsternlicht
dsternlicht / feeds.model.js
Last active January 29, 2019 13:25
Feeds model before cache
// Feeds model before cache
import DB from '../db';
const FeedModel = {
getUserFeeds(userID) {
const selectQuery = `SELECT * FROM feeds WHERE userID = ${userID}`;
return DB.then((connection) =>
@dsternlicht
dsternlicht / cache.service.js
Created September 17, 2017 07:33
Cache service wrapper for node-cache module
import NodeCache from 'node-cache';
class Cache {
constructor(ttlSeconds) {
this.cache = new NodeCache({ stdTTL: ttlSeconds, checkperiod: ttlSeconds * 0.2, useClones: false });
}
get(key, storeFunction) {
const value = this.cache.get(key);
@dsternlicht
dsternlicht / feeds.model.js
Created September 17, 2017 07:45
Initializing cache service in feeds model
// Initializing cache service in feeds model
import DB from '../db';
import CacheService from '../cache.service';
const ttl = 60 * 60 * 1; // cache for 1 Hour
const cache = new CacheService(ttl); // Create a new cache service instance
const FeedModel = {
...
@dsternlicht
dsternlicht / feeds.model.js
Last active August 5, 2019 08:00
getFeedById with cache
// Feeds model after cache
import DB from '../db';
import CacheService from '../cache.service';
const ttl = 60 * 60 * 1; // cache for 1 Hour
const cache = new CacheService(ttl); // Create a new cache service instance
const FeedModel = {
// ...
@dsternlicht
dsternlicht / feeds.model.js
Last active January 5, 2021 10:24
Feeds model with cache
// Feeds model after cache
import DB from '../db';
import CacheService from '../cache.service';
const ttl = 60 * 60 * 1; // cache for 1 Hour
const cache = new CacheService(ttl); // Create a new cache service instance
const FeedModel = {
@dsternlicht
dsternlicht / en.json
Last active November 13, 2017 08:07
Example of locale file structure
// en.json
{
"login": {
"welcome": "Welcome {{name}} to our localized app!",
"login_button": "Login",
"signup_button": "Sign Up"
},
"user_profile": {
"title": "Your Profile"
}
@dsternlicht
dsternlicht / he.json
Last active November 13, 2017 08:07
Example of locale file structure (Hebrew)
// he.json
{
"login": {
"welcome": "{{name}}, ברוך הבא לאפליקציה המתורגמת!",
"login_button": "התחבר",
"signup_button": "הרשם"
},
"user_profile": {
"title": "הפרופיל שלך"
}
@dsternlicht
dsternlicht / i18n.js
Last active November 13, 2017 08:58
i18n.js file example
import ReactNative from 'react-native';
import I18n from 'react-native-i18n';
// Import all locales
import en from './en.json';
import he from './he.json';
// Should the app fallback to English if user locale doesn't exists
I18n.fallbacks = true;
@dsternlicht
dsternlicht / login.js
Last active November 13, 2017 08:05
Login screen (no localization)
import React, { Component } from 'react';
import {
View,
Text,
Button
} from 'react-native';
class LoginScreen extends Component {
constructor(props) {
super(props);
@dsternlicht
dsternlicht / login.js
Created November 13, 2017 08:10
Login screen with localization
import React, { Component } from 'react';
import {
View,
Text,
Button
} from 'react-native';
import { strings } from '../locales/i18n';
class LoginScreen extends Component {