Skip to content

Instantly share code, notes, and snippets.

@kiichi
kiichi / swift-timer-example.swift
Last active August 27, 2021 07:15
Swift 2.0, Protocol, Delegate and Timer Example using GC
//Swift 2.0
import UIKit
protocol SomethingDelegate {
func didUpdateSomething(SomethingHelper:SomethingHelper)
}
class SomethingHelper {
private var timer : dispatch_source_t! = nil
private var currentIntervalInSec = 0;
var delegate: SomethingDelegate?
@kiichi
kiichi / swift-accurate-timer-example.swift
Created July 7, 2015 02:28
Swift 2.0, Protocol, Delegate and "More Accurate" Timer Example using GC
import UIKit
protocol SomethingDelegate {
func didUpdateSomething(SomethingHelper:SomethingHelper)
}
// Use CADisplayLink for more "averaged" timer interval
class SomethingHelper : NSObject{
private var timer : CADisplayLink!
private var currentIntervalInSec = 0;
var delegate: SomethingDelegate?
@kiichi
kiichi / NetTopologySuite_IntersectExample.cs
Last active November 29, 2018 19:16
C# GIS Intersact Example using NetTopologySuite
using System;
using NetTopologySuite.Geometries;
using GeoAPI.Geometries;
// Not sure SRID is respected or not. because their doc says obsolete
namespace NetTopologySuiteTest {
class MainClass {
public static void Main (string[] args) {
// Check Intersection of Brooklyn Street or not
@kiichi
kiichi / NetTopologySuite_Distance_Area_Example.cs
Last active November 16, 2023 18:50
C# GIS Polygon and Distance / Area Example using NetTopologySuite
using System;
using NetTopologySuite.Geometries;
using GeoAPI.Geometries;
/*
this looks wrong. SRID is not used?
Edge (West-East) of Central Park: 0.00906435667878181
Margin Distance of Central Park: 0.0983743244869002
Central Park Area: 0.000354214827500022
*/
namespace NetTopologySuiteTest {
@kiichi
kiichi / DistanceAreaDemo.cs
Last active August 29, 2015 14:26
Distance and Area Calculation Demo
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Device.Location; // Add Reference
namespace DistanceAreaDemo
{
class Program {
@kiichi
kiichi / AreaCalc.cs
Created August 7, 2015 23:19
Area Calculation in C#
using System;
namespace DistanceAreaCalc {
class GeoCoordinate{
public double Longitude;
public double Latitude;
public GeoCoordinate(double lat, double lng) {
this.Latitude = lat;
this.Longitude = lng;
}
@kiichi
kiichi / SphericalGeometry.cs
Last active August 29, 2015 14:26
SphericalGeometry class conversion from PHP (alpha)
// Converted from http://tubalmartin.github.io/spherical-geometry-php/
// Test results look same but doesn't look like what google map does.
// Don't assume it's perfect.
/*
var poly = new List<LatLng> {
new LatLng(47.9899216674142,61.171875),
new LatLng(50.2893392532918,68.90625),
new LatLng(52.9089020477703,78.046875),
new LatLng(56.5594824837622,95.625),
new LatLng(45.5832897560063,93.515625),
@kiichi
kiichi / FileUpload.cs.aspx
Created August 12, 2015 16:33
Complete File Upload Example from Microsoft
<%@ Import Namespace="System"%>
<%@ Import Namespace="System.IO"%>
<%@ Import Namespace="System.Net"%>
<%@ Import NameSpace="System.Web"%>
<Script language="C#" runat=server>
/*
//Test code
byte[] responseArray = myWebClient.UploadFile(uriString,fileName);
Console.WriteLine("{0}",System.Text.Encoding.ASCII.GetString(responseArray));
// ... or simple curl
@kiichi
kiichi / ColorList.cs
Created August 15, 2015 19:37
List all colors in Windows Universal App
using Windows.UI;
using System.Reflection;
//...
foreach (var propertyInfo in typeof(Windows.UI.Colors).GetProperties()) {
//propertyInfo.Name
Color col = (Windows.UI.Color)propertyInfo.GetValue(this, null);
}
@kiichi
kiichi / ColorUtil.cs
Last active August 29, 2015 14:27
I could not find BrushConverter class in the latest Universal Windows App namespaces. Here is simple example to convert Hex string to Color class.
//using Windows.UI
class ColorUtil {
// ColorUtil.FromHex("#FFAABBCC")
public static Color FromHex(string hexStr) {
hexStr = hexStr.Replace("#", "");
return Color.FromArgb(
(byte)Convert.ToInt32(hexStr.Substring(0, 2), 16),
(byte)Convert.ToInt32(hexStr.Substring(2, 2), 16),
(byte)Convert.ToInt32(hexStr.Substring(4, 2), 16),
(byte)Convert.ToInt32(hexStr.Substring(6, 2), 16));