Skip to content

Instantly share code, notes, and snippets.

View stevemu's full-sized avatar

Steve Mu stevemu

View GitHub Profile
import React, { Component } from 'react';
import { StyleSheet,
Button,
Text,
View,
TextInput,
ImageBackground,
ActivityIndicator,
Linking,
TouchableOpacity } from 'react-native';
@stevemu
stevemu / using-react-native-maps.js
Last active December 25, 2017 01:00
This file showcase how to do following features with react-native-maps: 1. show direction between two points (it use user's current coordinates and a custom set destination coordinates) 2. Show a marker 3. When click on the marker, show a call out 4. when click on the callout, launch Google Map for turn-by-turn navigation
import React, { Component } from 'react';
import {
StyleSheet,
Button,
Text,
View,
TextInput,
ImageBackground,
ActivityIndicator,
Linking,
@stevemu
stevemu / java-object-encryption-with-file.java
Last active August 13, 2021 03:15
How to encrypt an object and write it to file in Java and decrypt it
import javax.crypto.*;
import javax.crypto.spec.IvParameterSpec;
import java.io.*;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
public class Main {
@stevemu
stevemu / multiple-promise-in-async.js
Created December 9, 2018 00:41
run mutiple promises in one async function
const fetch = require('node-fetch'); // fetch polyfill in node.js; not required in front end situation
// returns an promise, so it can be used by await
async function getTodo(id) {
return new Promise((resolve, reject) => {
fetch('https://jsonplaceholder.typicode.com/todos/' + id)
.then(response => response.json())
.then(json => {
// success
// return data through resolve
@stevemu
stevemu / use await with promise.js
Created April 12, 2019 10:59
demoing using await with a promise function
const fetch = require('node-fetch'); // fetch polyfill in node.js; not required in front end situation
// returns an promise, so it can be used by await
async function getTodo(id) {
return new Promise((resolve, reject) => {
fetch('https://jsonplaceholder.typicode.com/todos/' + id)
.then(response => response.json())
.then(json => {
// success
// return data through resolve
// convert a csv like array like this:
// const tourdates = [
// ["date", "venue", "city"],
// ["jan 1", "paladium", "worcester"],
// ["jan 2", "irving", "nyc"],
// ["jan 3", "gramercy", "nyc"]
// ];
// into objects, like this:
// convert a csv file to form like texts
// Convert a csv like this:
// Name,Age, Bob,30, John,40,
// To text like this:
// Name: Bob Age: 30
// algorithm question
// how to solve the buy - sell problem
// q: [3,5,6,9,2]
// a: 6
// init best dff = 3-5
// for each number in array
// loop each number after the number
@stevemu
stevemu / MasterDetail.js
Last active May 4, 2019 21:34
a master-detail view for react
import React from 'react';
import {withStyles} from '@material-ui/core/styles';
import withResizeAware from '../../../core/withResizeAware';
const styles = {
root: {
flex: 1,
padding: 10
},
container: {
@stevemu
stevemu / withResizeAware.js
Created May 4, 2019 21:34
a HOC for react that inject height and weight of window in a component, good for the use-case that you need to show or hide something depend on the size of the window
import React from 'react';
function withResizeAware(WrappedComponent) {
return class extends React.Component {
constructor(props) {
super(props);
this.state = {
height: document.documentElement.clientHeight,
width: document.documentElement.clientWidth