Skip to content

Instantly share code, notes, and snippets.

View whitfin's full-sized avatar
🏠
Working from home

Isaac Whitfield whitfin

🏠
Working from home
View GitHub Profile
#include <conio.h> // For C stuff
#include <ctime> // For the current time
#include <fstream> // Needed for the file stream
#include <iostream> // Needed for input and output
#include <winsock2.h> // Needed for socket connection
using namespace std;
#define SERVER_PORT 12345 // Server port to connect on
#define BUF_SIZE 4096 // Block transfer size
@whitfin
whitfin / ConnectUtils.java
Last active January 4, 2016 20:49
Simple class to control connection detection. Just call `isConnected()` with the Context, and an optional URL to ping.
package com.zackehh.example;
import java.net.URI;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
@whitfin
whitfin / WriteObjectFile.java
Created January 28, 2014 21:07
Simple class to write a JSON object to a file, and read it back into JSON. Useful for data storing on Android.
package com.zackehh.example;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import android.content.Context;
@whitfin
whitfin / LinkMovementMethod.java
Created January 28, 2014 21:09
Custom Link Movement to open any clicked links inside an inline browser. Requires either a custom inline browser, or the one I created in a gist.
package com.zackehh.example;
import com.zackehh.example.MinimalBrowser;
import android.content.Context;
import android.content.Intent;
import android.text.Layout;
import android.text.Spannable;
import android.text.method.MovementMethod;
import android.text.style.URLSpan;
@whitfin
whitfin / InlineBrowser.java
Last active March 9, 2022 18:03
Inline browser loading for Android. Just extend and load your URL.
package com.zackehh.example;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.view.ContextThemeWrapper;
@whitfin
whitfin / runner.js
Last active August 29, 2015 13:57
Simple way to include all tests in Mocha with simple handling.
var fs = require('fs'),
Mocha = require("mocha"),
path = require('path');
// Our Mocha runner
var mocha = new Mocha({
ui:"bdd",
reporter:"spec",
timeout:60000,
slow:10000
@whitfin
whitfin / DirectedStream.java
Last active November 21, 2021 11:34
A simple Thread extension to control a redirection of an InputStream to an OutputStream.
package com.zackehh.example;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
/**
* A Thread extension dedicated to redirecting InputStreams
* to given OutputStreams. Feeds into the given OutputStream
* during the lifetime of this Thread.
@whitfin
whitfin / ArrayNodeCollector.java
Created September 19, 2015 22:46
Collecting to a Jackson ArrayNode from a Java 8 Stream.
package com.zackehh.example;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import java.util.EnumSet;
import java.util.Set;
import java.util.function.BiConsumer;
import java.util.function.BinaryOperator;
exports.parse = function parse(mdown) {
console.log('<p align="center" style="margin: 2em auto auto auto; width:70%;">');
mdown.match(/\[\!.*?\)\].*?\)/g).forEach(function (badge) {
var segments = badge.match(/\[!\[(.*?)\]\((.*?)\)\]\((.*?)\)/);
var altText = segments[1];
var svgPath = segments[2];
var urlHref = segments[3];
console.log(` <a href="${urlHref}">`);
@whitfin
whitfin / elasticsearch.js
Created July 6, 2016 21:25
dockserv recipes
module.exports = {
image: 'elasticsearch',
binds: [
'$DOCKSERV_DATA/elasticsearch/data:/usr/share/elasticsearch/data'
],
ports: [
'9200',
'9300'
]
};