Tuesday, December 15, 2015

How to: test ElasticSearch geoLocation support

Here is a quick tutorial to setup ES 2.1 and index some earthquake data by using the REST api. and then do by query by assign the POI within couple miles and return those earthquakes count aggregated by Range.
the query looks like this.  basically query all the earthquake happened near San Diego within 300KMs.

and the results showing the individual earthquakes and the buckets aggregated.
you can grad the data source from USGS , I closed the CSV file here
to do the Indexing, first we define the mapping , I used Postman to do the REST call. My mapping looks like this,
once we have the mapping and Index, we can feed the data to ES using the Sense tool. I put a small script to parse the CSV data to JSON following the Bulk format. 
like this

And I found Sense is the best client when you do the Bulk indexing, all other REST plugin in Chome give me the encoding error.
then copy and paste the data we convered, basically tell the importer we want to create a new document called eq, then the doc itself

Thursday, May 21, 2015

Http 1.1 Chunked transfer.

If you inspect the http response with some zipped resources, you may find 2 things. I assure we are on HTTP 1.1. there is no content-length header ins the response, also the transfer-encoding is chunked.

image

and Http 1.1 have a full spec about the chunked encoding, check it here. http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.6

if you use node.js , we can write a simple test to try out the chunked transfer. here is the source code

image

and try pull the response using wget. you will notice the 3 seconds delay between Okay3 and 4.

image

and inspect the traffic in between, you can see the wirelevel bits

image

1st response returns Okay1

image

then the 2nd returns2 and 3

image

after 3 seconds delay

we get okay4

image

image

once we call the end , you can see the end trailer.

wireshark are smart enough, to tell you 4 frames invloved in this http req/res

image

Monday, May 18, 2015

Power-shell , Filter and Projection

To getstart with any command in PS, run help.

image

image

To filter it, use the where-object or use ? directly.

image

get running service

image

Or just using ? instead.

image

Using Select to run a projection, select name, status only

image

also, you can skip and tail the results

image

sellect last 5 only

image

convert the result to a Html page? using the convert*

image

to show it in a gridview

image

Friday, May 1, 2015

What's new in asp.net 5



updates for asp.net 4.6, web forms mvc5

roslyn support. .net compiler

roslen c# languae fature
var name="ss"
var messgage=$"this is a amessag  {name}"

Features

totally modular
>old days, all features on. now , you can turn on off , faster
>cloud support
>faster dev cycle. 2 seconds to compiler
>cross platform. run on mac, linux, windows
>faster. less memory



docs.asp.net
powerd by readthedocs, markdown syntax

readmedocs.org
1. turn on featues on and off, moduleer. can run on IoT

//like the nodejs
public void configure(IapplicationBuild app)
{

app.run(async (context)=>
{
await context.Response.WriteAsync("Hello World")
})
}


//add dependency .microsfot.aspnet.diagnostis

app.userErrorPage();

dnx . web //start the app

//not static handler by default. need add dependency
//add dependency
microsoft.aspnet.staticfiles

app.useStatiffiles (); // extension methods

2. roslyn engine
instead of compile cs to dll, then load it.
now load it in memory

DNX (Dontne Execution Environment)
4.5.1
5.0 core

old file have the csproj, inclue all files. cause merge issues.
now all fiels in the project

commands in package.json
like alias in npm

dnx . web  //run web command in the folder.

target framework
frameworks:{
dnx451:{}
dnxcore50:{}
}

bower support
>>>nuget not versioned

gulp support
task runner support (show gupp task)

>before build
>after build


publish the app to a disk and can run it directly. by run the web.command


3.Environment

<Environment names="Dev">

<link rel="stylesheet" href="cdnlink" asp-fall-back-ref="otherlinks">
</Environment>

model injection.
more html
<input asp-for="email" class="form-control"/>

used to be html.Textbox(m->m.Email, new {"classs=formcontrol"})

4. configuration.

new Configuration().addInifile() or addjson()



app.addUserSecretcs(), no connectionstring in web.config.
also for hosted on cloud, IT ops will asign those value

user-script //
user-script set AppSettings:SiteTitle "sec title"

5. controller

new ScrottController () , no need for base calss

public xxxController()
{

public string Index()
{
return "hello, index"
}
}

6.dotnet version manager
dnvm list
c:\users\currentuser\.dnx

7. mac

yo asp.net
dnu restore

dnx run kestrol
Mcirosfot.aspnet.serverhosting -server kestrol


8. run on rsp pi
kestrel








What's new in C# 6



Roslyn open source

  IDE Features (CTL+.)
  . lightball to remove unused namespace
    .. fix the scope , remove all unused cross the project / solutions
  . refactor
    rename, introduce local variable, show conflict
    add this automaticaly if their is conflict that could be resolved by IDE
  . Array vs ImmutableArray

  var c=new ImmutableArray(); call c.length will trigger null exception.
  //you can build code analyzer
  //tell the ide you shoudl you  ImmutableArray<int>.empty

language new features
  instead of big change, little things added.

  1.using static System.Console. //simar typescript import {WriteLine} from systemcnosole

    then you can call WriteLine methods.
  2.Immutable, auto property.
    public class Point
    {
      public int x {get;}
      public int y {get;}=default10;
    }
  3 lambda for methods
    public void string ToString()=>String.format("tostring {0}", x);

  4 $String,
    public void String toString()=>$({X}{Y})
  5. nameof(variable)
    Log.d(nameof(variable))
  6.?.
    if p!=null && p.name=="xxx"
    will be if p?.name=="xx"
    if json!=null && json['x']!=null && json['x']=="mon"
    will be
    if(json?['x']?=="mon")
  7.initlize elements
    public JObject tojson()=>return new jsonobject(){['x']=x, ['Y']=y }
  8. awit in catch block

    try
    {
    var result=await repo.DosomethingAsync();
    }
    catch(Excepton ex)
    {
      await repo.LogException(ex) //doable now
    }

  9.catch(Exception ex) when (ex.Occurences>3)


Debugging features
  1. you can edit code, even add new class , and do initialization code when debugging the app
    run linq query

    also in watch window
    people.find(p=>p.age>20)

  C# extensions toolkit in the extnsion gallery
  2. C# interactive window

      #r "System"
      #r "System.Core"
      using System.Diagnostics;
      using System.linq;
      var memoryPigs =from p in Process.getProcesses() where p.workset64 >64*1024*1024 select new
      {p.ProcessName, p.WorkingSet}
      foreach(var r in memopigs)
      {
      Console.writeline(r)7y
      }

Friday, April 24, 2015

wse 2 run windows server 2008 R2

For some legacy issues, you app stack might use WSE to do the message level authentication. and if you have to run wse 2 in your asmx hosted on windows server 2008 R2. here could be some issues and solutions.

1. If you bind multi Binary kerberos token to the request and send to the server, you might be rejected even both of them are valid. like you put host to abc and abs.fullqualifiedname.com

solution: manually downgrade the wse 2 from 2.0.3 to 2.0.1. I found since 2.0.3, the request filter does not allow 1+ tokens

2. unable to extract username from the binary token passed from client.

solution: config the application pool to run on 32 bit mode. twick the code a little bit, to remove the session key extraction.

image

if always shows me the memroy access exception when it try to do the session key marshaling.

check the code in Microsoft.Web.Services2.Security.Tokens.Kerberos.LsaServerContext.LogonUser(byte[] inToken), you might just decompile the code ,chagne it and sign it back using your own key. and update the reference to your version of wse.dll

Friday, April 3, 2015

JWT token, signed in C#, and Decode in JS

JWT is a widly used token system that we can share token info between APIs or between Apps.

i.e we can sign the token by using a shared key in C#, then verify the token in javascript by using the same sharedkey.

in C#, you can search nuget for the jwt , there are several libraries.
image

let’s I want to sign a simple clamin using the simple password.
image

we get token eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJuYW1lIjoiUGV0ZXIiLCJSb2xlIjoiQWRtaW5zLFJlYWRlciJ9.Qh2J93epa7ls0y6DAn_8YvIRoRHq28hLT9N-93fStcajCd90nLzLG6Vit-Qdfl1TsPtL56qh4jiKDOzpfs1OyA

then follow the library for different languages from jwt.io to do the decoding

Past the token into the validation box, and enter pass in the shared key, you will see token get decoded and verified

image

Friday, March 27, 2015

C# TPL some basic code

Fast win pattern, you might query several urls for the same info, which one return first , that one will be the winner.
image

Send in parallel and join together.
image
long running and cancellable task, if get canceld, try compensate it

image

“mapreduce”

image

Thursday, March 12, 2015

Vagrant, Proxy issue, centos local repo and ad-hoc testing

Vagrant is a good VM automation tool for both developers and devops, here are some basic tips that I found useful

Proxy
   if you are stand behind a proxy, you can install one vagran proxy module. the module will setup the proxy on guest machines, like yum.conf, http_proxy variable etc.
here is the plugin https://github.com/tmatilai/vagrant-proxyconf

image

 

when you boot up the vm, you can see the proxy setting applied depends on your OS type

image

Yum Repo.
   you might have one local repo in the company, you can either build all boxes internally which already assign the repo url to local. or just copy one repo to override the system one by using the provisioning scripts.

image

image

and in your local file, change the ip to internal one

image

Provision scripts to check whether package installed or not. using rpm to query package or use command to determine whether a command exists

image

Thursday, February 19, 2015

Opencart fix, show the shipping method in orders admin page and filter by shippingmethod

it turns that this should be a common feature for opencart admins, basically the operation team would like to see orders with priority shipping method and process those orders first. on 1.5, no way you can see this at once. basically the orders page looks like this by default

image

they actually want to see the UI like this, with shipping method on the overview

image

even more, they want a filter to see all orders with priority shipping selected.

image

To fix this, pretty straight forward. change the orders module/controller/template file, to include shippingmethod in the data query back. and add a filter logic to narrow down records.

I have a patch file, email me if you are interested. click about me on the page to get my email

Wednesday, February 11, 2015

C# merge sorting vs insert sorting

Quick test for a 50K random double array with random order, to soft it using the system libarry  and my own insert sorting/ merge sorting, the time takes to do the soring is quite different.

given a array with size 50K of  double values,

image

if increase to 100K, more time for insertion sorting

image

 

https://github.com/ryandh/CSharpSortingInsertedMerged/blob/master/Program.cs

Friday, February 6, 2015

Jquery , Simple plugin with default options

check this sample fiddler, http://jsfiddle.net/androidyou/dox5x8pp/

basically, we can use the $.extend to assign a default value if options are not assigned.

image

if you put default option,

image

image

Wednesday, January 7, 2015

DNS troubleshooting tools and tips - nslookp

if you are on Windows, dig is not there, you can do most DNS query through nslookup.

to see the DNS cache on your local server,  run “ipconfig /displayDNS”

image

same thing, ipconfig /flushDNS to purge the cache.

to see name server of a giving domain

image

to see all infomration like root server, try nslookup , set all

image

to see mx record of amazon.

image

to see the spf record?

image

what about debug information

image

to see all information

image

to see all the ips of a domain or even this history.

https://www.virustotal.com/en/domain/dl.dropbox.com/information/

image

 
Locations of visitors to this page