Skip to content

Instantly share code, notes, and snippets.

View rms1000watt's full-sized avatar

Ryan M Smith rms1000watt

View GitHub Profile
@rms1000watt
rms1000watt / android-service-traffic.java
Created May 31, 2016 22:53
Get network traffic information from running services on Android
import android.net.TrafficStats;
import android.app.ActivityManager;
import android.content.pm.PackageManager;
private void getServiceTraffic() {
PackageManager pm = getPackageManager();
ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningServiceInfo> runningServices = am.getRunningServices(Integer.MAX_VALUE);
for (ActivityManager.RunningServiceInfo service : runningServices) {
@rms1000watt
rms1000watt / android-http-request.java
Created May 31, 2016 23:02
Send HTTP Request on Android
import android.util.Log;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
private void sendHTTPRequest() {
@rms1000watt
rms1000watt / android-os-execute.java
Last active May 31, 2016 23:20
Execute OS command on Android
import android.util.Log;
import java.io.BufferedReader;
import java.io.InputStreamReader;
private void executeCommand() {
String inputLine;
String output = "";
Process process = Runtime.getRuntime().exec("cat /proc/net/xt_qtaguid/stats");
BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));
while ((inputLine = in.readLine()) != null) {
@rms1000watt
rms1000watt / powershell-sync-http.ps1
Last active May 31, 2016 23:27
Send Synchronous HTTP Request Powershell 2
function sendHTTP
{
param( $uri, $message )
$postData = "{"
$postData += "`"message`":`""+$message+"`","
$postData += "`"name`":`"ryan`""
$postData += "}"
$request = [System.Net.WebRequest]::Create($uri)
$request.Method = "POST"
$request.Timeout = 5000
@rms1000watt
rms1000watt / bash-open-ports.sh
Created June 1, 2016 19:32
Display all open ports on a Linux machine
# http://askubuntu.com/questions/75852/how-do-i-see-which-ports-are-open
netstat -ntlp | grep LISTEN
@rms1000watt
rms1000watt / bash-remove-ssh-key.sh
Created June 1, 2016 19:37
Remove an SSH key if a key changes on a machine (like if a new VM is generated but had an old IP address).
# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
# @ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
# IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
# Someone could be eavesdropping on you right now (man-in-the-middle attack)!
# It is also possible that a host key has just been changed.
# The fingerprint for the RSA key sent by the remote host is
# f0:6f:50:f0:13:96:32:67:99:79:14:59:b6:32:16:16.
# Please contact your system administrator.
# Add correct host key in /Users/ryan/.ssh/known_hosts to get rid of this message.
@rms1000watt
rms1000watt / ubuntu-router-nat-dns.sh
Created June 15, 2016 20:03
Ubuntu installation as router with NAT, DNS, and isolation rules
# Ubuntu box with 2 NICs
# eth0 = WAN
# eth1 = LAN
# OR
# eth0 = larger network
# eth1 = smaller network
# Setup and install
sudo apt-get install iptables-persistent
@rms1000watt
rms1000watt / js-ajax-download.jsx
Created June 22, 2016 17:24
Javascript AJAX to server then download PDF
// This is an incomplete example but has the gist of it
successCB = (blob) => {
let objectURL = URL.createObjectURL(blob);
let a = document.createElement("a");
a.href = objectURL;
a.download = 'MyPDF';
document.body.appendChild(a);
a.click();
setTimeout(()=>{a.remove()}, 1000);
@rms1000watt
rms1000watt / haproxy-install.sh
Last active June 22, 2016 17:28
HAProxy 1.6 Install on Ubuntu 14.04
# Works fine on ubuntu 14.04. Gave me issues on 16.04.
sudo apt-get update -y
sudo apt-get upgrade -y
sudo add-apt-repository ppa:vbernat/haproxy-1.6
sudo apt-get dist-upgrade -y
sudo apt-get install haproxy -y
# Edit the haproxy config
sudo nano /etc/haproxy/haproxy.cfg
@rms1000watt
rms1000watt / js-save-html-img.jsx
Created June 22, 2016 17:32
Javascript save HTML div as img
// This example uses ReactJS but can be substituted for something else. Uses html2canvas and FileSaver.
// This example saves a leaflet map
saveMap = () => {
let mapNode = ReactDOM.findDOMNode(this.refs.leafletMap)
html2canvas(mapNode, {
useCORS: true,
onrendered: (canvas) => {
canvas.toBlob((blob) => {
FileSaver.saveAs(blob, "MyMap.png");