Skip to content

Instantly share code, notes, and snippets.

View tspycher's full-sized avatar

Thomas Spycher tspycher

View GitHub Profile
@tspycher
tspycher / MongoDB: AbstractTest.php
Created February 6, 2014 15:08
Base Clase wich drops all Collections and build the them from scratch
<?php
namespace XXX\Tests\Document;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
abstract class AbstractTest extends WebTestCase
{
static $container;
@tspycher
tspycher / gist:604834a30f7dd99e371f
Created April 5, 2015 21:15
Geo Calculations for Flight Navigation
from math import radians, cos, sin, asin, sqrt, atan2, degrees
def _c(old):
direction = {'N':1, 'S':-1, 'E': 1, 'W':-1}
new = old
new = new.split()
new_dir = new.pop(0)
new.extend([0,0,0])
x = (float(new[0])+float(new[1])/60.0+float(new[2])/3600.0) * direction[new_dir]
return x
@tspycher
tspycher / Proofing_The_Monty_Hal_Problem.py
Created December 15, 2015 12:25
The Monty Hall Problem in Python
import random
summary = {"lose_inital":0, "win_initial":0, "lose":0, "win":0}
def game(switch=False):
fields = [False,False,False]
winField = random.randint(0,2)
fields[winField] = True
setField = random.randint(0,2)
@tspycher
tspycher / _etc_init.d_selenium
Last active December 28, 2015 02:49
/etc/init.d/selenium for CentoOS 6.4
#!/bin/bash
# selenium - this script starts and stops the selenium grid
#
# chkconfig: - 85 15
# description: Selenium Grid is a distributed testing platform for browser-based automation.
# processname: selenium
# pidfile: /etc/selenium/tmp/selenium.pid
# Source function library.
. /etc/rc.d/init.d/functions
def externalPaymentAttributes():
return {
'country': 'CH',
'email': self.host_emails[0] if self.host_emails else None,
'business_name': self.name,
#'business_tax_id_provided': False,
'tos_acceptance': {
'date': int(time.time()),
'ip': "185.90.38.128",
'user_agent': 'Cathedra Backend'
@tspycher
tspycher / simple_tournament.py
Last active May 12, 2016 11:50
A fellow just asked me how simple it would be to create the most simple tournament application. this is what came out in a couple of minutes.
import random
import math
teamof = 2
def teams(people):
teams = []
for i in range(len(people) / teamof):
team = []
for i in range(teamof):
p = random.choice(people)
@tspycher
tspycher / send.py
Created May 20, 2016 08:11
Sends a message to HipChat and allows configuration by parameters
from hypchat import HypChat
import re
import sys
import argparse
import select
from hypchat.requests import HttpClientError
parser = argparse.ArgumentParser(description='Simply sends a message to a given room')
parser.add_argument('-t', '--token', action='store', dest="apitoken", default='xxxxxx')
parser.add_argument('-r', '--room', action='store', dest="room", default='rnd')
@tspycher
tspycher / array_diff_example.php
Created May 25, 2016 08:56
array_diff() example with objects instead of primitives
<?php
class X {
public $name;
public function __construct($name) {
$this->name = $name;
}
# This must be defined in order to have array_diff() working
#public function __toString() {
# return $this->name;
@tspycher
tspycher / thread.py
Created March 7, 2017 09:35
Simple Multithreaded Synchronisation routine
#!/usr/bin/python
import time
import threading
import Queue
import random
class BaseSynchronisation(object):
num_threads = 5
threads = None
@tspycher
tspycher / queue-it_example.py
Created December 19, 2017 13:02
Queue-It.org Python Flask Example
from flask import Flask, redirect, request
import hashlib
import re
app = Flask(__name__)
# plays best with ngrok proxy server https://ngrok.com/
@app.route("/")
def hello():