Skip to content

Instantly share code, notes, and snippets.

Avatar

Tony Vu tonyvu2014

View GitHub Profile
View app.json
{
"expo": {
"name": "Balsa",
"description": "A super lightweight news feed",
"githubUrl": "https://github.com/tonyvu2014/balsa",
"sdkVersion": "25.0.0",
"icon": "balsa.png",
"version": "0.1.6",
"slug": "balsa",
"ios": {
View axios.js
axios.post(FEED_URL,
{
terms: terms,
limit: LIMIT
},
{ timeout: TIMEOUT }
)
.then(res => {
this.showFeeds(res)
console.log('FeedsScreen - loading feeds is done')
View componentDidMount.js
componentDidMount() {
this.props.navigation.setParams({
onTabFocus: this.getFeeds
});
this.getFeeds()
}
View navigationOptions.js
static navigationOptions = ({ navigation }) => {
const { params } = navigation.state;
return {
tabBarOnPress({ jumpToIndex, scene }) {
params.onTabFocus();
jumpToIndex(scene.index);
}
}
}
View Stack_Tab_Navigator.js
const FeedsStack = StackNavigator({
Feeds: {
screen: FeedsScreen,
navigationOptions: {
title: 'Feeds'
},
},
Reader: {
screen: ReaderScreen,
navigationOptions: {
View AsyncStorage_getItem.js
AsyncStorage.getItem('preferences')
.then(value => {
if (value) {
console.log('PreferencesScreen - preferences:', value)
let terms = []
let prefs = value.split(',')
for (let i = 0; i < prefs.length; i++) {
terms.push({key: i, term: prefs[i]})
}
this.setState({terms: terms})
@tonyvu2014
tonyvu2014 / send_email.cgi
Created Jul 20, 2015
A perl cgi script to collect and send plain feedback to a list of site admin emails. This script can be used for contact us form, just need to ensure that the form fields match the param names in the script and update the corresponding email addresses. CGI.pm module is required on the server.
View send_email.cgi
#!/usr/bin/perl
use CGI;
# Create a CGI.pm object
my $cgi = new CGI;
# Get the form data
my $email_address = $cgi->param('email');
my $feedback = $cgi->param('message');
my $name = $cgi->param('name');
@tonyvu2014
tonyvu2014 / Monitor.java
Last active Aug 16, 2016
Java program to monitor a web server. To use, type in Monitor <web address> <frequency> <timeout>
View Monitor.java
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
public class Monitor {
public static void main(String[] args) throws IOException {
if (args.length < 3)
throw new IllegalArgumentException("Invalid number of arguments");
@tonyvu2014
tonyvu2014 / replication_monitor.sql
Created Apr 17, 2015
Mysql replication monitor and recovery. Set up the cronjob on mysql server (slave side) to run this script daily or weekly to monitor and recover from mysql replication failure. If there is any error an notification email will be sent to the email of your choice.
View replication_monitor.sql
#!/bin/bash
USER=<your mysql username>
PASSWORD=<your mysql password>
SUBJECT="Mysql Replication Problem"
EMAIL=<your monitor email>
RESULT=`mysql -u$USER -p$PASSWORD -e 'show slave status\G' | grep Last_SQL_Error | sed -e 's/ *Last_SQL_Error: //'`
if [ -n "$RESULT" ]; then
echo "$RESULT" | mail -s "$SUBJECT" $EMAIL