Skip to content

Instantly share code, notes, and snippets.

@jcrubino
jcrubino / battleship.py
Last active August 29, 2015 14:11
Battleship NG in Python
"""
TODO:
move fit function to GameBoard
assert all ships on playing board
game board keeps record of players ships
players call to game board and get proper access to game state and own board.
create frp board
ship observes its own location for hits
posts damage or detroyed signal to location on the board
create temporary sequence predictor_seq;
CREATE temporary TABLE linear_systems_test_data( id INTEGER NOT NULL, lhs DOUBLE PRECISION[], rhs DOUBLE PRECISION);
insert into linear_systems_test_data values (nextval('predictor_seq'), '{352137.0,84.7067061967771,-150.185137392799,122.050417659229,-74.0884874537119,99.7911494563722,-3.7907455558484,181224.690513009,106938.029173016,69336.1362009346,18335.0,12.7007088793537,-250.440511627437,-62.5561474971013,-292.703374755409,-167.012940969203,-78.511449979818,9451.24681999999,5585.85191537643,3628.50938401}'::float[], 88920344.0 );
insert into linear_systems_test_data values (nextval('predictor_seq'), '{84.7067061967771,176105.544243727,61.0252088296143,-73.1971959184637,7.54222162981446,-48.6063990056131,-37.7170700467655,-11006.0678697046,-11871.4874441653,-10787.6157862104,12.7007088793537,9313.85168737771,-31.2780737485506,-85.9645308238089,-89.8568249242787,-78.6462830692247,10.8622991388217,-566.613529886409,-617.49619500345,-565.289335368564}'::float[]
@jcrubino
jcrubino / gist:6007affdea9f871f481c
Created December 4, 2014 20:10
Gogs Http Client
import requests
from lxml import html # would prefer not to parse html but currently this is the only option
# set these to whatever your gogs account is
username = "username"
password = "password"
cookie_filename = "gogs.cookies"
gogs_url = "your_gogs_url"
gogs_port = "3000"
@jcrubino
jcrubino / gist:70a38ae46b034ae8f056
Last active August 29, 2015 14:10
Command Pattern Continued
/*
Command Pattern Continued
Adapted from https://en.wikipedia.org/wiki/Command_pattern#JavaScript
& http://www.onjava.com/pub/a/onjava/2006/04/05/ajax-mutual-exclusion.html
Application: Wallace Variation for Lamports Bakery Algorithm for implementing mutex in javascript
*/
@jcrubino
jcrubino / gist:5bd10e19fe7b661ad51c
Last active August 29, 2015 14:10
Generic Command Pattern Javascript
/* Generic Command Pattern in Javascript */
/* Adapted from https://en.wikipedia.org/wiki/Command_pattern#JavaScript */
/* Application: Wallace Variation for Lamports Bakery Algorithm for implementing mutex in javascript */
/* The Invoker function */
var Invoke = function(){
var _commands = [];
this.storeAndExecute = function(command){
_commands.push(command);
command.execute();
@jcrubino
jcrubino / gist:880a73ce75b5e341acd7
Created November 27, 2014 12:36
Start of OkCoin Websocket Api
package main
import "fmt"
type OkCoin struct {
futures map[string]map[string]map[string]string
spot map[string]map[string]map[string]string
}
func OkCoinApi() OkCoin {
from pylab import *
from scipy.ndimage import measurements
import numpy as np
import matplotlib.pyplot as plt
import time
import sys
import signal
def signal_handler(signal, frame):
sys.exit(0)
@jcrubino
jcrubino / gist:347108b2541263fab6cc
Last active August 29, 2015 14:10
Basic Linear Regression Class and Function for Streaming and Static Data
# basic linear regression in pure python (no numpy!)
# class and function usable for streams
# refactored from http://code.activestate.com/recipes/578914-simple-linear-regression-with-pure-python/
import math
def mean(series):
return sum(series) / len(series)
def standard_deviation(series, ave):
def GetSleepTime(self, resources):
'''Determines the minimum number of seconds that a program must wait
before hitting the server again without exceeding the rate_limit
imposed for the currently authenticated user.
Returns:
The minimum seconds that the api must have to sleep before query again
'''
if resources[0] == '/':
resources = resources[1:]
# hello world in GAS syntax
# to compile and run
# $ yasm -f elf -p gas helloGAS.s 2>&1
.text # section declaration
# we must export the entry point to the ELF linker or
.global _start # loader. They conventionally recognize _start as their
# entry point. Use ld -e foo to override the default.
_start: