Skip to content

Instantly share code, notes, and snippets.

View gousiosg's full-sized avatar

Georgios Gousios gousiosg

View GitHub Profile
@gousiosg
gousiosg / unix-compatible.sh
Last active November 20, 2017 10:17
How compatible is your Unix with the original one?
#!/usr/bin/env bash
TEMPFILE=/tmp/unixcount
exist=0
notexist=0
echo 0 0 > $TEMPFILE
curl "https://raw.githubusercontent.com/dspinellis/unix-v4man/master/man0/ptxx"|
grep "(I)"|
@gousiosg
gousiosg / README.md
Last active September 23, 2016 14:55
Experiments with various languages on low level file parsing

So today I was experimenting with various languages in order to make the GHTorrent MySQL "CSV" dumps to behave like RFC-compliant CSV files. This involved parsing multi-GB, UTF-8 encoded files and running a small state-machine at the character level. I started with Ruby, but it was slow:

$ time ruby csvify.rb projects.csv >/dev/null

real	0m36.714s
user	0m35.689s
# start the replset nodes
$ mongod --dbpath mongodb/ --replSet ghtorrent
$ mongod --dbpath mongodb-repl1/ --port 27018 --replSet ghtorrent
$ mongod --dbpath mongodb-repl2/ --port 27019 --replSet ghtorrent
# connect to primary
$ mongo
# In mongo shell
ghtorrent:PRIMARY> rs.initiate()
@gousiosg
gousiosg / setup_bcache.sh
Created October 14, 2015 19:54
Setting up SSD as a cache for slow cloud volumes
#!/usr/bin/env bash
lsblk
apt-get install -y lvm2 mdadm bcache-tools
# Create a linux raid autodetect primary partition
# use the following keystrokes: np1tfdw
fdisk /dev/sdc
fdisk /dev/sdd
# setup raid
@gousiosg
gousiosg / json2bson.rb
Created October 9, 2015 08:08
Convert JSON to BSON for importing into MongoDB
#!/usr/bin/env ruby
require 'json'
require 'bson' # Requires bson version > 3
json = JSON.parse(File.open(ARGV[0]).read)
w = File.open("#{ARGV[0]}.bson",'w')
json.each do |j|
@gousiosg
gousiosg / geocode.rb
Created October 8, 2015 21:27
Geocode a list of addresses using OpenStreetMaps
#!/usr/bin/env ruby
#
require 'open-uri'
require 'json'
require 'pp'
require 'uri'
File.open('locs').each_line do |location|
url=URI.escape("http://nominatim.openstreetmap.org/search/#{location}?format=json&addressdetails=1")
@gousiosg
gousiosg / buien-hue.rb
Last active December 9, 2020 10:22
Set color of a Hue lightbulb based on fine-grained rain information
#!/usr/bin/env ruby
require 'open-uri'
require 'json'
require 'hue'
delft="http://www.buienradar.nl/Json/RainForecast3Hours?lat=52.006&lon=4.355&weatherstationid=6344&streetlevel=false"
percipitation = JSON.parse(open(delft).read)['forecasts'][1]["precipation"]
@gousiosg
gousiosg / session.sh
Last active December 10, 2020 11:43
GHTorrent from scratch session
#First, install RVM as per https://rvm.io
rvm install 2.5.1
rvm use 2.5.1
git clone git@github.com:gousiosg/github-mirror.git
cp config.yaml.standalone config.yaml
# Install dependencies
gem install bundler
@gousiosg
gousiosg / analysis.R
Last active December 2, 2015 11:41
Complete machine learning example
library(reshape)
library(ggplot2)
library(corrplot)
library(caret)
source('ml.R')
# Util stuff
load.filter <- function(path) {
setAs("character", "POSIXct",
@gousiosg
gousiosg / nagios.nginx
Last active February 16, 2018 10:56
Nagios on a virtual host with nginx on Debian
server {
listen 80;
server_name nagios.tld.org;
access_log /var/log/nginx/nagios.access.log;
error_log /var/log/nginx/nagios.error.log info;
root /usr/share/nagios3/htdocs;
index index.php index.html;