Skip to content

Instantly share code, notes, and snippets.

View nanlabsweb's full-sized avatar

nanlabsweb

View GitHub Profile
@nanlabsweb
nanlabsweb / syncPets.kt
Created April 5, 2018 16:10
Sync Pets without coroutines
fun syncPets() = repository.syncPets()
@nanlabsweb
nanlabsweb / lightWeightThread.kt
Created April 5, 2018 16:08
Light Weight Thread Example
syncPets.setOnClickListener({
launch(UI) {
syncPets.isEnabled = false
val message = petViewModel.syncPets()
Toast.makeText(baseContext, message, Toast.LENGTH_LONG).show()
syncPets.isEnabled = true
}
})
@nanlabsweb
nanlabsweb / delay.kt
Created April 5, 2018 16:05
Coroutine delay example
launch {
delay(1000)
println("Hello from Kotlin Coroutines!")
}
@nanlabsweb
nanlabsweb / MainNav.jsx
Created March 20, 2018 19:39
Main navigation menu using first level Wordpress pages.
import React from 'react';
import { Link, withRouter } from 'react-router-dom';
import { graphql } from 'react-apollo';
import gql from 'graphql-tag';
const Nav = (props) => {
const { loading, pages } = props.data;
if (loading) {
@nanlabsweb
nanlabsweb / Page.jsx
Created March 20, 2018 19:31
Page component to render Wordpress pages.
import React, { Component } from 'react';
import { Redirect } from 'react-router-dom';
import { graphql } from 'react-apollo';
import gql from 'graphql-tag';
import { sanitize } from '../commons/HtmlSanitizer';
class Page extends Component {
render() {
const props = this.props;
@nanlabsweb
nanlabsweb / ApolloClientSetup.jsx
Created March 20, 2018 19:28
How to setup Apollo Client library in a React app.
import React from 'react';
import ReactDOM from 'react-dom';
import { BrowserRouter } from 'react-router-dom';
import { ApolloProvider } from 'react-apollo';
import { ApolloClient } from 'apollo-client';
import { HttpLink } from 'apollo-link-http';
import { InMemoryCache } from 'apollo-cache-inmemory';
const client = new ApolloClient({
link: new HttpLink({ uri: 'http://localhost:5010/graphql' }),
setImageSize(width, height){
if (this.props.width && !this.props.height) {
this.setState({
width: this.props.width,
height: height * (this.props.width / width)
});
} else if (!this.props.width && this.props.height) {
this.setState({
width: width * (this.props.height / height),
height: this.props.height
componentWillMount(){
if (this.props.source.uri){
Image.getSize(this.props.source.uri, (width, height) => {
this.setImageSize(width, height);
});
} else {
let {width, height} = resolveAssetSource(this.props.source);
this.setImageSize(width, height);
}
}
@nanlabsweb
nanlabsweb / index.js
Created March 13, 2018 21:51
JS native extensions - JS invoke
const hello_world = require('bindings')('hello_world')
console.log(hello_world.sayHi());
@nanlabsweb
nanlabsweb / binding.gyp
Created March 13, 2018 21:50
JS native extensions - config file
{
"targets": [
{
"cflags!": [ "-fno-exceptions" ],
"cflags_cc!": [ "-fno-exceptions" ],
"include_dirs" : [
"<!@(node -p \"require('node-addon-api').include\")"
],
"target_name": "hello_world",
"sources": [ "hello_world.cc" ],