Skip to content

Instantly share code, notes, and snippets.

View revox's full-sized avatar

Andy Freeman revox

View GitHub Profile
@revox
revox / get_users.py
Created January 9, 2015 14:58
Get twitter users details
import twitter
# http://mike.verdone.ca/twitter/ and Russel, MTSW, second edition, 2013
import json, csv, time, sys
# == OAuth Authentication ==
# The consumer keys can be found on your application's Details
# page located at https://dev.twitter.com/apps (under "OAuth settings")
consumer_key=""
consumer_secret=""
import java.io.*;
import java.net.*;
class evenSimplerEchoServer
{
public static void main(String[] argv) throws Exception
{
ServerSocket s = new ServerSocket(5000);
Socket t = s.accept();//wait for client to connect
InputStream b = t.getInputStream();
import java.io.*;
import java.net.*;
class evenSimplerEchoClient
{
public static void main(String[] argv) throws Exception
{
Socket s = new Socket("localhost",5000);
OutputStream p =s.getOutputStream();
InputStream i = s.getInputStream();
@revox
revox / threads.java
Created January 18, 2015 09:37
Basic threading example
class threads
{
static class t1 extends Thread
{
public void run()
{
int i=0;
@revox
revox / evenSimplerGuiClient.java
Created January 18, 2015 09:40
Basic graphical echo client
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import java.net.*;
public class evenSimplerGuiClient implements ActionListener {
private JTextField user = new JTextField("user",20);
private JTextArea server = new JTextArea("server",5,20);
@revox
revox / simpleMultiThreadedEchoServer.java
Created January 18, 2015 09:41
Multithreaded echo server
import java.io.*;
import java.net.*;
class simpleMultiThreadedEchoServer
{
public static void main(String[] argv) throws Exception
{
ServerSocket s = new ServerSocket(5000);
Transaction k;
while (true)
@revox
revox / counterThreadClash.java
Last active August 29, 2015 14:14
Thread interference example
class counterThreadClash
{
static Counter count = new Counter();
static class t1 extends Thread
{
public void run()
{
for (int i=0;i<50000;i++) {
@revox
revox / counterThreadSynchronized.java
Created February 1, 2015 21:37
Shows synchronized shared data access
class counterThreadSynchronized
{
static Counter count = new Counter();
static class t1 extends Thread
{
public void run()
{
for (int i=0;i<50000;i++) {
@revox
revox / Deadlock.java
Created February 1, 2015 23:20
Example of thread deadlock, uncomment the counter to see interleaving then uncomment the synchronised statements to see deadlock
class Friend {
String name;
public Friend(String name) {
this.name = name;
}
public /* synchronized */ void waveAt(Friend f) {
System.out.println(name + " waves...");
@revox
revox / broadcasterWithList.java
Created February 2, 2015 07:50
Threaded broadcast server showing the use of shared data to maintain a list of clients
import java.util.*;
import java.io.*;
import java.net.*;
class SynchList
{
ArrayList <OutputStream> it;
SynchList()
{