Skip to content

Instantly share code, notes, and snippets.

@TomTasche
TomTasche / GTalkOAuthSASLMechanism.java
Last active December 17, 2015 04:08
this gist describes how to 1. get an OAuth token from Android's AccountManager, 2. use this token to connect with GTalk via XMPP. Blog post about it: http://blog.tomtasche.at/2013/05/gtalk-and-oauth-on-android.html
// taken from: http://stackoverflow.com/a/10712949/198996
// note: you don't have to change anything in this class
public class GTalkOAuthSASLMechanism extends SASLMechanism {
public static final String NAME = "X-GOOGLE-TOKEN";
public GTalkOAuthSASLMechanism(SASLAuthentication saslAuthentication) {
super(saslAuthentication);
}
@TomTasche
TomTasche / appengine.java
Created May 9, 2013 15:16
a demonstration of a file upload without any additional libraries on Android. More information here: http://blog.tomtasche.at/2013/05/android-upload-file-to-appengine.html
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
try {
InputStream stream = req.getInputStream();
// do whatever you want with the stream now
} catch (Exception ex) {
throw new ServletException(ex);
}
@TomTasche
TomTasche / appengine_static_file.java
Created November 10, 2013 10:36
reading a file from WEB-INF folder in AppEngine. lots of answers on StackOverflow are actually incorrect (most of them missing the leading slash)
InputStream stream = getServletContext().getResourceAsStream("/WEB-INF/file.txt");
@TomTasche
TomTasche / Gruntfile.js
Created December 27, 2015 22:35
dispatcher for multi-module appengine setups
// ...
var proxySnippet = require("grunt-connect-proxy/lib/utils").proxyRequest;
gruntConfig.connect = {
server: {
options: {
port: 9000,
hostname: "0.0.0.0",
keepalive: true,
middleware: function(connect, options) {
@TomTasche
TomTasche / debug_log.cpp
Last active December 31, 2015 22:29
console output in C++
std::cout << "debug message: " << array.size() << std::endl;
List<String> data = new LinkedList<String>();
// or if you know the amount of data upfront:
List<String> data = new ArrayList<String>(3);
data.add("hello");
data.add("hello");
data.add("bye");
System.out.println(data.size()); // 3
// in order to lookup data you always have to iterate the whole list until you find the value you're looking for
#!/bin/bash
sudo apt-get update --yes
sudo apt-get upgrade --yes
curl -sSO https://dl.google.com/cloudagents/install-logging-agent.sh
sudo bash install-logging-agent.sh
sudo rm install-logging-agent.sh
sudo apt-get install git default-jdk maven --yes
#!/bin/bash
logger "started"
sudo apt-get update --yes
sudo apt-get upgrade --yes
cd worker/
git clean -fdx
git checkout master
Compute compute = ComputeOptions.defaultInstance().service();
String instanceName = "bla";
String projectId = "blu";
String zone = "ble"; // e.g. europe-west1-d
InstanceId instanceId = InstanceId.of(projectId, zone, instanceName);
Instance instance = compute.getInstance(instanceId);
try {
#!/bin/bash
# install node
curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash -
sudo apt-get install git nodejs --yes
# fix npm permissions: https://docs.npmjs.com/getting-started/fixing-npm-permissions
mkdir ~/.npm-global
npm config set prefix '~/.npm-global'
echo "export PATH=~/.npm-global/bin:\$PATH" >> ~/.profile