Tuesday, September 2, 2014

String Checker

A friend of mine needed to check a directory full of text files, created as a log, for a specific string of text. I wrote him up a python script.
# SEARCHES TEXT FILES IN THE CURRENT DIRECTORY. NOT RECURSIVE (diving into other directories within current directory).

# place a one line string inside the quotes in below variable to search for
search = "example"
# once done searching, program will crash. 2lazy4errorhandling

import os
n = 0
list = os.listdir(./")
while True:
active = open(list[n])
for line in active:
if line.count(search) != 0:
print list[n]
n += 1 

Thursday, March 28, 2013

Raspberry Pi Minecraft Server

This post, just like the previous one, is here solely so I have a reference that can be accessed via console web browser.

1) Flash an SD card (I'm using a 2GB) with Raspbian wheezy (follow the instructions onhttp://www.raspberrypi.org/downloads)

2) Put the SD card in the Pi, connect an Ethernet cable (I have no idea how Wifi performance is for this) and connect a Micro USB cable. You'll want to connect your Pi to a screen using HDMI or the SDTV connector before you connect the Micro USB cable.

3) raspi-config should come up on your screen. Set timezone, locale and keyboard layout, fix any overscan settings if you have to and then choose Overclock and set it to modest (this will NOT void your warranty).

4) Now, select memory split and set the GPU memory to 16mb (you won't need to run startx for this guide so you'll want to set as much RAM free as you can for the server)

5) Select Finish and restart the Pi.

(from here on in, you can ssh into the Pi using PuTTY or any other tool and do this, and unplug the Pi from your screen. If you don't like a headless pi, please don't disconnect anything)

6) Now, you'll want to set a static IP so that you can forward ports on your router afterwards.

7) Log in (username: pi, password: raspberry) and then:

cd /etc/networks
sudo nano interfaces

8) After nano comes up on your screen, change "iface eth0 inet dhcp" to:

iface eth0 inet static
address (any free network ip, for example - you'll have to check what IPs your router assigns to network devices)
gateway (your router's ip)
nameserver (your router's ip)

9) Press control+x, press Y, enter and then type sudo reboot.

10) Now, you'll want to open port 25565 on your router. Since everyone has their own router, I'm not going to post a guide for this - check your router documentation or google for instructions.

11) Unfortunately, we can't wget the official Java VM package from Oracle, so you will need to download the package to your computer and send it via SSH (use WinSCP for Windows) to /home/pi. Download link:http://jdk8.java.net/fxarmpreview/index.html

12) Once you have ssh'd the package to /home/pi, do the following:

mkdir -p /opt
sudo tar zxvf (name of package) -C /opt
rm (name of package)
sudo /opt/jdk1.8.0/bin/java -version

13) If you don't get any error messages after executing the last command, give yourself a pat on the back - you're getting there!

14) Now, you will need to go to the official Minecraft website to download the server jar: https://s3.amazonaws.com/MinecraftDownload/launcher/minecraft_server.jar (either wget this to /home/pi or ssh it from your computer to /home/pi)

15) After this, type this into the terminal: cd /home/pi

16) To run the actual server," sudo /opt/jdk1.8.0/bin/java -Xms128M -Xmx256M -jar /home/pi/minecraft_server.jar nogui"

NOTE: Change the Xms and the Xmx parameters if you haven't set memory split to 16mb GPU. The total has to be less than the 2nd value in -/+ buffer/cache when you type "free -m" into terminal. If you change the parameters, make sure you only use multiples of 8, such as 8, 16, 32, 64, 128 or 256. Xms has to be smaller than Xmx.

17) It will take a while to create a map. In my case, it took 200 seconds, which amounts to approximately 3 and a half minutes. If you turn your server on after the map has been generated (let's say, after restarting your Pi or something) it shouldn't take more than 30 seconds.

18) if you ever need to edit server.properties, type "stop" while the server is running, and then type "sudo nano /home/pi/server.properties" .

Sunday, February 24, 2013

RetroPie-Setup Annoyance

Hey there. This post is really not going to help anyone and is more of a personal resolution, my issue being that the steps to utilize the RetroPie-Setup script are not properly viewable using a console web browser. Posting those steps here will solve that problem for me later.

sudo apt-get update
sudo apt-get install -y git dialog
git clone git://github.com/petrockblog/RetroPie-Setup.git
cd RetroPie-Setup
chmod +x retropie_setup.sh
sudo ./retropie_setup.sh