Skip to content

Instantly share code, notes, and snippets.

View xicalango's full-sized avatar
☀️
It's summer!

Alexander Weld xicalango

☀️
It's summer!
  • Zurich, CH
View GitHub Profile
@xicalango
xicalango / journal.sh
Last active November 1, 2016 15:47
A small script for managing a journal.
#!/usr/bin/env bash
set -e
if [ -z ${XX_NOTES_PATH} ]; then
echo "Please set XX_NOTES_PATH environment variable"
exit 1
fi
FILE_ID=$(date +%F)

Flip Result <-> Option

Used for converting an Result<Option, E> into an Option<Result<R, E>> and back.

Example

let re = try!(regex::Regex::new(...));
let captures = re.captures().unwrap()
let parse_result = try!(captures.name("group").map(|captured| captured.parse()).flip())
@xicalango
xicalango / dectime.sh
Last active August 29, 2015 14:25
Decimal time formatter
#!/usr/bin/env bash
DATE=( $(date +'%_H %_M %_S') )
totalSec=$(( ${DATE[2]} + (${DATE[1]}*60) + (${DATE[0]}*3600) ))
totalDSec=$(( (1000 * totalSec) / 864 ))
dHrs=$(( totalDSec / 10000 ))
dMin=$(( (totalDSec % 10000) / 100 ))
@xicalango
xicalango / Image2Spreadsheet.java
Last active August 29, 2015 14:21
A java (8) script that converts any image java can load into a Open Office Spreadsheet file. (you'll need the libs mentioned here: http://incubator.apache.org/odftoolkit/simple/gettingstartguide.html)
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.Iterator;
import java.util.stream.IntStream;
import javax.imageio.ImageIO;
import org.odftoolkit.odfdom.type.Color;
import org.odftoolkit.simple.SpreadsheetDocument;
import org.odftoolkit.simple.table.Table;
@xicalango
xicalango / planet.bas
Created January 23, 2014 20:50
A small game turnbased planet exploring game in qbasic glory
DECLARE SUB Pause ()
DECLARE FUNCTION BuildingMenu! (withres!)
DECLARE FUNCTION CheckResources! (needed AS ANY, have AS ANY)
DECLARE SUB SubtractResources (a AS ANY, b AS ANY)
DECLARE FUNCTION Menu! (menuItems$(), length!)
DECLARE SUB printcoor (c AS ANY)
DECLARE SUB Initialize ()
DECLARE SUB PrintPlayer (pi AS INTEGER)
DECLARE SUB PrintPlanet (pi!)
DECLARE SUB TurnBuilding (ip!, ib!)
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char** argv)
{
const char* wget_command = "wget ""%s"" -O ""%s""";
char run_command[1000] = {0};
@xicalango
xicalango / MemoryDataStream.cpp
Created May 26, 2013 09:47
MemoryDataStream
/*
* File: MemoryDataStream.cpp
* Author: alexx
*
* Created on 24. Mai 2013, 13:15
*/
#include <cstring>
#include <cassert>
//#include <glog/logging.h>
@xicalango
xicalango / Extensions.cs
Last active December 15, 2015 12:58
Some C#--Language extensions
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Extensions
{
public static class Extensions
{
public static void Times(this int t, Action<int> f)