Skip to content

Instantly share code, notes, and snippets.

@njoyce
njoyce / generate_token.py
Last active March 23, 2021 11:47
Generate JWT for a Google Cloud Service Account
"""
Example of creating an authentication token using a Google Cloud Service
Account. This token can then be used as part of the Authorization header in the
HTTP request in the form `Authorization: Bearer {token}` to access
Signing is expensive (in terms of compute resources) so the token is valid for
1 hour before it expires and another must be generated.
"""
import time
#!/usr/bin/env python3
import os
import toml
import subprocess
def get_root_packages():
pipdeptree = subprocess.run(
"pipdeptree",
@njoyce
njoyce / HelloWorld.java
Last active April 5, 2019 11:40
Code samples for Building minimal Docker Containers for Java Applications on blog.realkinetic.com
package hello;
import org.joda.time.LocalTime;
public class HelloWorld {
public static void main(String[] args) {
LocalTime currentTime = new LocalTime();
System.out.println("The current local time is: " + currentTime);
System.out.println("Hello World");
}
KUBERNETES_PORT=tcp://10.96.0.1:443
KUBERNETES_PORT_443_TCP=tcp://10.96.0.1:443
KUBERNETES_PORT_443_TCP_ADDR=10.96.0.1
KUBERNETES_PORT_443_TCP_PORT=443
KUBERNETES_PORT_443_TCP_PROTO=tcp
KUBERNETES_SERVICE_HOST=10.96.0.1
KUBERNETES_SERVICE_PORT=443
KUBERNETES_SERVICE_PORT_HTTPS=443
@njoyce
njoyce / http.conf
Created February 6, 2018 14:53
Nginx configuration for HTTP to HTTPS service
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
return 307 https://$host$request_uri;
}
@njoyce
njoyce / gist:1407388
Created November 30, 2011 00:41
PyAMF test client using WebTest integrating with webapp2
import unittest
from pyamf.remoting.client import RemotingService
import webtest
class ResponseProxy(object):
"""
Mimics a urllib2 response from a WebOb response
import timeit
import pyamf
class Foo(tuple):
pass
list_of_foo = []
for x in xrange(1000000):
list_of_foo.append(Foo(['foo', 'bar', 'baz']))
import pyamf
class TestProtocol(object):
def connectionMade(self):
self.decoder = pyamf.get_decoder(pyamf.AMF0)
self.buffer = self.decoder.stream
self.context = self.decoder.context
def dataReceived(self, data):
self.buffer.append(data) # adds data to the end of the stream without changing the current position of the stream