Skip to content

Instantly share code, notes, and snippets.

View gist:f208a6216a6fb40e08906234601b831a
class PostcodesRequest
require 'open-uri'
require 'nokogiri'
def postcode_file_name
page = Nokogiri::HTML(open('http://www.posti.fi/webpcode/unzip/'))
href = page.css('p').css('a')
text = href.text
splits = text.split('webpcode/')
names = splits[1].split('.dat')
@zmilojko
zmilojko / gist:9343394
Last active May 11, 2020
C# XML (de)serialization made simple. I am sick of C# approach to use 12 lines of code where one would suffice. These two functions will (de)serialize string <=> object and with nice format two.
View gist:9343394
string Serialize(object o)
{
XmlWriterSettings Settings = new XmlWriterSettings()
{
Indent = true,
IndentChars = " ",
NewLineHandling = NewLineHandling.None,
NewLineChars = "\n",
};
var sb = new StringBuilder();
@zmilojko
zmilojko / gist:5756502
Last active May 11, 2020
Here is how you can make C# WebRequests asynchronously. The version on MSDN is overcomplicated and utterly sucks. This one is minimal and doesn't suck.
View gist:5756502
/*
* ----------------------------------------------------------------------------
* "THE BEER-WARE LICENSE" (Revision 42):
* Guoxun Yang and Zeljko Milojkovic wrote this file. As long as you retain this
* notice you can do whatever you want with this stuff. If we meet some day, and
* you think this stuff is worth it, you can buy us beer in return.
* ----------------------------------------------------------------------------
*/
using System;
@zmilojko
zmilojko / UDPer.cs
Last active Sep 11, 2021
C# sends and receives UDP broadcasts
View UDPer.cs
using System;
using System.Net.Sockets;
using System.Net;
using System.Text;
using System.Threading;
namespace UDPer
{
class UDPer
{
@zmilojko
zmilojko / SpeedActivity.java
Created Feb 8, 2013
Minimalistic Android GPS app - shows speed on the screen - but mainly shows how to read GPS data in Android
View SpeedActivity.java
package com.zwr.speed;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.view.Menu;
import android.widget.TextView;
View gist:3181545
#duplicate{dst="transcode{vfilter={rotate{angle=270}:croppadd{croptop=120,cropbottom=0,cropleft=740,cropright=610}},live-caching=80,network-caching=0,vcodec=VP80,vb=4000,height=1080,width=1920,fps=15,acodec=none}:standard{access=http,mux=webm,dst=0.0.0.0:8090/main.webm}",dst="transcode{vfilter={rotate{angle=270}:croppadd{croptop=120,cropbottom=0,cropleft=740,cropright=610}},live-caching=80,network-caching=0,vcodec=h264,venc=x264{ultrafast},vb=4000,height=1080,width=1920,fps=15,acodec=none}:standard{access=http,mux=ts,dst=0.0.0.0:8090/main.mp4}",dst="transcode{vfilter={rotate{angle=270}:croppadd{croptop=120,cropbottom=0,cropleft=740,cropright=610}},live-caching=80,network-caching=0,vcodec=theo,vb=4000,height=1080,width=1920,fps=15,acodec=none}:standard{access=http,mux=ogg,dst=0.0.0.0:8090/main.ogg}"}
@zmilojko
zmilojko / ZGacInst.cs
Created Jul 25, 2012
Source of the ZGacInst - my little utility that will add assemblies to and remove them from GAC. Replaces GacUtil, which MS for some reason keeps weirdly licensed.
View ZGacInst.cs
// GacUtil my own way.
// Since GacUtil is not distributed with .NET framework (after 1.1.), should yo uwant to install your assemblies to GAC,
// you are likely to need this code.
using System;
// Add reference: System.EnterpriseServices
namespace ZGacInst
@zmilojko
zmilojko / setup.nsi
Created Jul 25, 2012
NSIS package for a C# application - a package file I used in Zaws, with comments on how to use it for your own application
View setup.nsi
; Full script for making an NSIS installation package for .NET programs,
; Allows installing and uninstalling programs on Windows environment, and unlike the package system
; integrated with Visual Studio, this one does not suck.
;To use this script:
; 1. Download NSIS (http://nsis.sourceforge.net/Download) and install
; 2. Save this script to your project and edit it to include files you want - and display text you want
; 3. Add something like the following into your post-build script (maybe only for Release configuration)
; "$(DevEnvDir)..\..\..\NSIS\makensis.exe" "$(ProjectDir)Setup\setup.nsi"
; 4. Build your project.