Skip to content

Instantly share code, notes, and snippets.

View tonyvu2014's full-sized avatar

Tony Vu tonyvu2014

View GitHub Profile
@tonyvu2014
tonyvu2014 / replication_monitor.sql
Created April 17, 2015 01:33
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.
#!/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
@tonyvu2014
tonyvu2014 / Monitor.java
Last active August 16, 2016 14:45
Java program to monitor a web server. To use, type in Monitor <web address> <frequency> <timeout>
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 / send_email.cgi
Created July 20, 2015 11:58
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.
#!/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');
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 / Stack_Tab_Navigator.js
Created June 10, 2018 07:53
Stack and Tab Navigator
const FeedsStack = StackNavigator({
Feeds: {
screen: FeedsScreen,
navigationOptions: {
title: 'Feeds'
},
},
Reader: {
screen: ReaderScreen,
navigationOptions: {
@tonyvu2014
tonyvu2014 / navigationOptions.js
Created June 10, 2018 07:58
navigationOptions
static navigationOptions = ({ navigation }) => {
const { params } = navigation.state;
return {
tabBarOnPress({ jumpToIndex, scene }) {
params.onTabFocus();
jumpToIndex(scene.index);
}
}
}
@tonyvu2014
tonyvu2014 / componentDidMount.js
Created June 10, 2018 08:00
componentDidMount
componentDidMount() {
this.props.navigation.setParams({
onTabFocus: this.getFeeds
});
this.getFeeds()
}
axios.post(FEED_URL,
{
terms: terms,
limit: LIMIT
},
{ timeout: TIMEOUT }
)
.then(res => {
this.showFeeds(res)
console.log('FeedsScreen - loading feeds is done')
@tonyvu2014
tonyvu2014 / app.json
Created June 10, 2018 08:15
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": {