Skip to content

Instantly share code, notes, and snippets.

public int setMessage(int type, Serializable data) throws IOException {
ByteArrayOutputStream bo = new ByteArrayOutputStream();
ObjectOutputStream oo = new ObjectOutputStream(bo);
oo.writeObject(data);
oo.close();
bo.close();
this.messSize = bo.size();
this.message = new byte[bo.size()];
this.message = bo.toByteArray();
@magnetik
magnetik / php-cli.php
Created June 20, 2012 12:14
Php command line parser
function parseArguments()
{
array_shift($argv);
$out = array();
foreach($argv as $arg)
{
if(substr($arg, 0, 2) == '--')
{
$eqPos = strpos($arg, '=');
if($eqPos === false)
<?php
/**
* ManiaLib - Lightweight PHP framework for Manialinks
*
* @see http://code.google.com/p/manialib/
* @copyright Copyright (c) 2009-2011 NADEO (http://www.nadeo.com)
* @license http://www.gnu.org/licenses/lgpl.html LGPL License 3
* @version $Revision: 749 $:
* @author $Author: baptiste33 $:
* @date $Date: 2012-08-23 14:58:11 +0200 (jeu., 23 août 2012) $:
@magnetik
magnetik / Client.php
Created April 1, 2014 07:13
ManiaConnect Client.php
<?php
/**
* Maniaplanet Web Services SDK for PHP
*
* @see http://code.google.com/p/maniaplanet-ws-sdk/
* @copyright Copyright (c) 2009-2011 NADEO (http://www.nadeo.com)
* @license http://www.gnu.org/licenses/lgpl.html LGPL License 3
* @author $Author$:
* @version $Revision$:
* @date $Date$:
@magnetik
magnetik / maze.py
Created April 24, 2014 07:26
Python Maze Cheese Solver
class MazeSolver:
def __init__(self):
self.points = [Point()]
def findCheese(self, maze):
maze.initialize()
while(True):
currentPoint = self.points[-1]
if maze.testAndMove(maze, currentPoint) == False:
@magnetik
magnetik / ManiaPlanetServer
Last active August 29, 2015 14:13
Script to auto restart server after a certain duration (like 20 days)
#!/bin/bash
SERVER_DIRECTORY="/opt/maniaplanet-server/"
SERVER_TIMEOUT="298h" #298h ~= 12.4d
if [ "$(groups | grep games)" ];
then
cd $SERVER_DIRECTORY
while true; do
timeout --foreground $SERVER_TIMEOUT ./ManiaPlanetServer "$@"
RETVAL=$?
@magnetik
magnetik / gist:1cb88b1d7d3016eb35a5
Last active August 29, 2015 14:15
maniaplanet-troubleshot.bat
@echo off
setlocal ENABLEEXTENSIONS
echo Starting troubleshooting script. It may take a while. Please wait.
(
@echo on
date /t
time /t
<?php
namespace AppBundle\Utils;
use JMS\Serializer\Construction\DoctrineObjectConstructor;
use JMS\Serializer\Construction\ObjectConstructorInterface;
use JMS\Serializer\Construction\UnserializeObjectConstructor;
use JMS\Serializer\DeserializationContext;
<?php
$retries = 0;
function fetch() {
global $retries;
echo "Retry " . $retries . " | ";
$opts = array(