Skip to content

Instantly share code, notes, and snippets.

@kiichi
kiichi / intersects_test.py
Created June 7, 2016 02:24
Intersections between different objects using shapely and pyproj. Could be wrapped in geopandas
# Intersections between different objects
# This demo shows intersects function between
# Polygons (Box and Circle)
# Note that applying buffer in (m) after projection happened
#
# 1) Reproject WGS84 to Web Mercator which uses m in UnicodeTranslateError
# 2) Call intersects
from shapely.geometry import Point,Polygon
import pyproj
@kiichi
kiichi / extract_dbz_lat_lng.py
Last active May 8, 2016 16:21
PyArt Examples
import pyart
import numpy as np
radar = pyart.io.read_nexrad_level3("data/SI.kokx/sn.last")
for i in range(0,radar.nrays):
row = radar.fields['reflectivity']['data'][i]
#get index of unmask items
idx=np.where(~row.mask)
dbz = row[idx]
lat = radar.gate_latitude['data'][i][idx]
lng = radar.gate_longitude['data'][i][idx]
@kiichi
kiichi / FastParsing.swift
Created May 1, 2016 19:40
NSScanner Example: Fast Data parsing using swift
// Use by piping
// cat input22.txt | ./MyScanner
// This is very slow
// let xy = (readLine()!).characters.split(" ").map{Int(String($0))!}
import Foundation
var str = ""
while true {
@kiichi
kiichi / FindDivisor.swift
Created April 17, 2016 19:16
Find all divisors of the number.
//: c - Algorithm to find all the exact divisors of a given integer - Stack Overflow : http://stackoverflow.com/questions/11699324/algorithm-to-find-all-the-exact-divisors-of-a-given-integer
import Cocoa
func printDivisors(x:Int){
let sqr = sqrt(Double(x))
for i in 2..<Int(sqr)+1 {
if x % i == 0 {
print(i)
if i != (x/i) {
@kiichi
kiichi / GCDLCM.swift
Created April 14, 2016 01:21
Great Common Divisor and Least Common Multiple
// gcd - Eucrid Algorithm
// https://en.wikipedia.org/wiki/Greatest_common_divisor#Using_Euclid.27s_algorithm
func gcd(n1:Int, n2:Int) -> Int {
let nMax = max(n1,n2)
let nMin = min(n1,n2)
let reminder = nMax % nMin
if reminder == 0 {
return nMin
}
return gcd(nMin,n2:reminder)
@kiichi
kiichi / SpeechRecognizerExample.java
Created April 12, 2016 03:44
Speech Recognizer Android Example. I removed unrelated part of codes so it would not run if you just copy and paste it.
// Ommitted ...
public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
SpeechRecognizer mSpeech = null;
Intent mIntent;
@Override
protected void onCreate(Bundle savedInstanceState) {
@kiichi
kiichi / EPOneSample.cs
Created April 9, 2016 15:15
EPPlus Library Example. Using Nuget and Compiled on Mac using Xamarin.
using System;
using OfficeOpenXml;
using System.IO;
using System.Drawing;
using OfficeOpenXml.Drawing;
using System.Drawing;
namespace EPOneSample {
class MainClass {
public static void Main (string[] args) {
@kiichi
kiichi / n_choose_k.swift
Last active April 3, 2016 20:45
Use Pascal Triangle and Take Modulo 10^9, and it stores the triangle in array as the cache
let m = 1000000000
var arr = [[Int]]()
arr.append([1])
func nChooseK(n:Int, k:Int) {
var prev = arr.last!
if arr.count > n {
prev = arr[n]
}
else {
@kiichi
kiichi / Send.java
Created February 20, 2016 17:26
RabbitMQ Sample in Java
import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.Channel;
// See python code comment for username / password settings
//javac -cp rabbitmq-client.jar Send.java
//java -cp .:./rabbitmq-client.jar Send
public class Send {
private final static String QUEUE_NAME = "javahello";
public static void main(String[] argv) throws Exception {
@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):