Skip to content

Instantly share code, notes, and snippets.

@kiichi
kiichi / AuthViewController.swift
Created August 30, 2015 03:51
Finger Print Authentication in Swift 2
//
// ViewController.swift
// FingerTest
//
// Created by Kiichi Takeuchi on 8/29/15.
// Copyright (c) 2015 ObjectGraph LLC. All rights reserved.
//
import UIKit
import LocalAuthentication // add framework
@kiichi
kiichi / InterpolationExample.cs
Last active September 21, 2015 16:11
Calculating Interpolated Points between two geo coordinates
// Find interpolation points between two coordinates. e.g. 100 intervals
// You can throw the list to MapQuest, for example.
// Note : Download SphericalGeometry.cs from here
// https://github.com/kiichi/spherical-geometry-dotnet
using System;
using System.Net;
using System.Text;
namespace ElevationTest {
class MainClass {
public static void Main (string[] args) {
@kiichi
kiichi / ImageResizeTest.cs
Last active September 27, 2024 01:28
Image Resize Example in C#
// Add System.Drawing as a reference.
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
namespace ImageResizeTest {
class Program {
static void Main(string[] args) {
string path = @"C:\\Users\kiichi\work\ImageResizeTest\geo-elevation.png";
Resize(path, 600, 600);
@kiichi
kiichi / WritableBitmapExample.cs
Created September 17, 2015 12:37
Use WritableBitmapEx package in Windows Universal App
// Download WritableBitmapEx Package from NuGet
FileOpenPicker openPicker = new FileOpenPicker();
openPicker.ViewMode = PickerViewMode.Thumbnail;
openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
openPicker.FileTypeFilter.Add(".png");
StorageFile file = await openPicker.PickSingleFileAsync();
if (file != null) {
var fileStream = await file.OpenAsync(FileAccessMode.Read);
WriteableBitmap wbmp = await BitmapFactory.New(1, 1).FromStream(fileStream);
@kiichi
kiichi / MyHadoopIOTest.java
Created December 24, 2015 21:00
Simple Hadoop File IO Java Example
////////////////////////////////////////////////////////////////////////////////////////
// Environment:
// Cloudera Quickstart VM
//
// How to compile:
// export CLASSPATH=$CLASSPATH:.:/usr/lib/crunch/lib/hadoop-common.jar:/usr/lib/crunch/lib/hadoop-annotations.jar
// javac MyHadoopIOTest.java
// jar cvf MyHadoopIOTest.jar MyHadoopIOTest.class
// /usr/bin/hadoop jar MyHadoopIOTest.jar MyHadoopIOTest
//
@kiichi
kiichi / ScreenshotViewController.swift
Created January 5, 2016 04:12
Example to capture the NSView screenshot in Mac App
import Cocoa
class ScreenshotViewController: NSViewController {
override func prepareForSegue(segue: NSStoryboardSegue, sender: AnyObject?) {
if let viewController = segue.destinationController as? PreviewViewController{
viewController.image = getScreenshot()
}
}
func getScreenshot() -> NSImage {
@kiichi
kiichi / ReduceChainExample.swift
Created February 1, 2016 02:39
A bit complicated reduce() example. This pass the previous element as the 2nd element of accumulator to calculate distance of two locations.
// arr is array of CLLocation.
// Regular For-Loop Version
for (var i=0; i<arr.count-1; i++) {
totalDistance += arr[i].distanceFromLocation(arr[i+1])
}
// Reduce Example 1: with argument. Note, passing total distance and first element as tuple.
totalDistance = arr.reduce((0,arr[0])) { (accum,elem) -> (Double,CLLocation) in
return (accum.0 + accum.1.distanceFromLocation(elem),elem)
@kiichi
kiichi / MapExamples.swift
Created February 2, 2016 02:31
Mapping Example for Common Operations, such as split and convert String.
// Convert String to Int Array
"123456".characters.map{Int(String($0))!}
// Split and Convert
"1 2 3 4 5 6".characters.split(" ").map{Int(String($0))!}
@kiichi
kiichi / LinkList.swift
Created February 14, 2016 03:05
Simple LinkList Example in Swift.
@kiichi
kiichi / receive.py
Created February 17, 2016 03:26
RabbitMQ Sample Code
#!/usr/bin/env python
import pika
server = '192.168.64.2'
credentials = pika.PlainCredentials(username='test', password='test')
connection = pika.BlockingConnection(pika.ConnectionParameters(host=server,credentials=credentials))
channel = connection.channel()
channel.queue_declare(queue='hello')
def callback(ch, method, properties, body):