Friday, December 9, 2016

Elixir, Phoenix, React, Redux and ES6 - I'm a complete beginner again.

I started with Erlang and now progressing with Elixir, Phoenix, React, Redux and ES6 stack. Was feeling a bit lost when seeing stuff like this:

 var createStoreWithMiddleware = (0, _redux.applyMiddleware)(reduxRouterMiddleware, _reduxThunk2.default, loggerMiddleware)(_redux.createStore);

or:

const store = autoRehydrate()(createF8Store)(reducers);

Had to remind myself on a simple function chaining, like:

const p = (store)=>{console.log("I'm an almighty container, you passed me the store: " + store);};

const f = (a,b)=>{
  console.log("Thanks for a and b: " + a + ", " + b + " it helped me to build a container with I return to you. Pass a store into it!");
return p;
};

f(3,4)("Store is just a name 'John'");

With the output of:


  • "Thanks for a and b: 3, 4 it helped me to build a container with I return to you. Pass a store into it!"

  • "I'm an almighty container, you passed me the state: Store is just a name 'John'"
Beginner mind work play games with me, tendency to get lost on trivial subjects is quite high :):):).

A list of resources I really appreciated so far:

React: https://facebook.github.io/react/docs
Redux: http://redux.js.org,  https://egghead.io/lessons/javascript-redux-reducer-composition-with-combinereducers
ES6 and modules (oh, how could have I got so much behind?):
https://24ways.org/2014/javascript-modules-the-es6-way/
https://babeljs.io/learn-es2015/

I also found this article being an awesome walkthrough on getting React/Redux/ES6 and more together in Facebook's makeitopen app:
http://makeitopen.com/tutorials/building-the-f8-app

Webpack:
http://ryanchristiani.com/introduction-to-webpack/

Elixir and Phoenix: 
Pragmatic programmers - Elixir programming, Phoenix programming.
Phoenix and Trello clone: http://codeloveandboards.com/blog/2016/01/14/trello-tribute-with-phoenix-and-react-pt-1/



Wednesday, June 15, 2016

Me, a troll! My recent MS experience :)

If I had to show one example for all for my recent Microsoft experience as a developer and user, here it is. The welcome page in VS 2015 opening the xml feed when you click on "More news":

I will not be telling here how I'm trying to keep my ASUS tablet in sync with time after upgrading to Windows 10. The above is enough declaration of "we are not for humans" and "we don't really care" :). 

This is me, a troll in the MS land. I used to be a regular guy here. Sorry. I'm working hard on my escape plan now.

Stan.

P.S. To my problem with Windows 10 time. Given how different apps in windows fail differently based on that time sync problem and learning Erlang at the moment, it was quite up to point to read about Erlang time here: http://learnyousomeerlang.com/time, wishing you a good read! :).

Thursday, May 26, 2016

Symbolicating bitcode crash logs in XCode

As of Xcode version 7.3 there is still a problem with symbolicating the bitcode crash logs. I've attempted several solutions, here and here, but here is what I came to:

1. Crash logs provided are for the dSYMs that Apple also provides. Just go to the iTunes connect and download them:



Once you have them right click on the crash in xcode -> "Show in finder" and copy to some target directory - that's actually a crashpoint file you are going to get.

My target directory is now ~\Desktop\crashes and here is how it looks:



Where #1 are dSYMs as copied from the iTunes connect. #2 is the crashpoint saved from the crash organizer window in xCode. #4 is a crash log extracted from the crashpoint file (right click and "show package contents")

To get #3 - a symbolicatecrash app, execute this in the target directory (xcode 7.3):


cp /Applications/Xcode.app/Contents/SharedFrameworks/DVTFoundation.framework/Versions/A/Resources/symbolicatecrash symbolicatecrash

For different versions of xcode the location of symbolicatecrash will be different.

To get symbolicatecrash ready to operate execute:

export DEVELOPER_DIR='/Applications/Xcode.app/Contents/Developer'

Only one step is left! That's to get your crash log symbolicated:

./symbolicatecrash a.crash dSYMs/ > a.log

And the output file a.log is looking like:



Way better, is not it?

There are nuances that I would not touch here, like these dSYM files you downloaded are for different architectures and it would be the best to match your specific crash log to a corresponding dSYM. I'll leave this detail to you, my experience is that function names do match quite well, then it is just about the line of code information you'll be getting. In above picture, given crash and dSYM are matched well, you can see the line of code where the crash exactly happened. Otherwise you'd see +xyz there and that's not that helpful.

This is it. Please don't judge me strictly, I'm not an expert in any field, as I learnt over time :)! Knowing more than I do? Share your knowledge in the comments!

Yours,
Stan.

Wednesday, April 27, 2016

Erlang http response emulator

Recently I had to implement a "transparent" proxy between Tibco and Blackberry. I thought I'd share the erlang module I wrote to emulate responses from BB as you can't really expect from BB server to give you error responses or timeouts so you can test your proxy part. Here it is:


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
-module(httpemulator).
-author("stanislavdvoychenko").

-export([client/0, server/0,start/0,accept/1,enter_loop/1,loop/1]).

client() ->
  {ok, Socket} =  gen_tcp:connect("localhost", 4001,[list, {packet, 0}]),
  ok = gen_tcp:send(Socket, "packet"),
  receive
    {tcp,Socket,String} ->
      io:format("Client received = ~p~n",[String]),
      io:format("Client result = ~p~n",[String]),
      gen_tcp:close(Socket)
  after 1000 ->
    exit
  end.

server() ->
  Pid = spawn(fun()-> start() end),
  Pid.

start() ->
  io:format("Started Server:~n"),
  {ok, Socket} = gen_tcp:listen(4001, [binary, {packet, 0},{reuseaddr, true},{active, false}]),
  accept(Socket).

accept(ListenSocket) ->
  io:format("Accept Server:~n"),
  case gen_tcp:accept(ListenSocket) of
    {ok, Socket} ->
      Pid = spawn(fun() ->
        io:format("Connection accepted ~n", []),
        enter_loop(Socket)
                  end),
      io:format("Pid ~p~n",[Pid]),
      gen_tcp:controlling_process(Socket, Pid),
      Pid ! ack,
      accept(ListenSocket);
    Error ->
      exit(Error)
  end.

enter_loop(Socket) ->
  %% make sure to acknowledge owner rights transmission finished
  receive ack -> ok end,
  loop(Socket).

loop(Socket) ->
  io:format("Loop Server:~n"),
  case gen_tcp:recv(Socket, 0) of
    {ok, Data} ->
          io:format("Server got data = ~s~n", [Data]),
          Match = re:run(Data, ".*Emulator-Command:\s(.+)\r", [{capture, [1],list}]),
      case Match of
        {match, ["timeout"]} -> Response = timeout("timeout");
        {match, ["protocolviolation"]} -> Response = protocol_violation("Omitting carriage return, this should cause the protocol violation");
        {match, ["httperror"]} -> Response = http_error("500", "Internal Server Error");
        _ -> Response = response("testing")
      end,

io:format("Match: ~p~n", [Match]),
          gen_tcp:send(Socket, Response);
          %%loop(Socket);
    {error, Reason} ->
      io:format("Error on socket ~p reason: ~p~n", [Socket, Reason]),
      gen_tcp:close(Socket)
  end.

response(Str) ->
  B = iolist_to_binary(Str),
  iolist_to_binary(
    io_lib:fwrite(
      "HTTP/1.0 200 OK\r\nContent-Type: text/html\r\nContent-Length: ~p\r\n\r\n~s",
      [size(B), B])).

timeout(Str) ->
  timer:sleep(1000000000),
  B = iolist_to_binary(Str),
  iolist_to_binary(
    io_lib:fwrite(
      "HTTP/1.0 200 OK\r\nContent-Type: text/html\r\nContent-Length: ~p\r\n\r\n~s",
      [size(B), B])).

protocol_violation(Str) ->
  B = iolist_to_binary(Str),
  iolist_to_binary(
    io_lib:fwrite(
      "HTTP/1.0 200 OK\nContent-Type: text/html\nContent-Length: ~p\n\n~s",
      [size(B), B])).

http_error(Code, Str) ->
  B = iolist_to_binary(Str),
  iolist_to_binary(
    io_lib:fwrite(
      "HTTP/1.0 ~s ~s\r\nContent-Type: text/html\r\nContent-Length: ~p\r\n\r\n~s",
      [Code, B, size(B), B])).

This Erlang module expects you to sent an extra http header Emulator-Command: * where * can be:

httperror -> returns 500 and Internal Server Error
timeout -> runs a long sleep on Erlang side, causes timeout on a proxy side
protocolviolation -> As I built the proxy in ,net WCF it was funny to see that MS takes only \n in the http headers as a protocol violation, so \r\n is required to keep MS happy.

anything else there or omitting this header will just return proper http response with "testing" body.

Disclaimer. I'm only starting to learn Erlang so please take the code with caution of course!

To compile in the erlang shell:

c(httpemulator).

To start emulator server:

httpemulator:server().

To end the emulator process:

exit(pid(0,96,0), old).

Pid is returned at the server start.

Hope it can be useful :).

Thursday, April 14, 2016

xcode - Configure for analyzing. The scheme is not configured for analyzing.

I'm used to run analyzing cycle on my apps when moving closer to their public release. This time xcode (7.3 (7D175)) greeted me with:


"Edit the scheme to enable analyzing, or cancel the action." with that "Edit Scheme ..." was not opening anything and I didn't notice anything extra in the schema editor to enable analyzing.

I even created a clean new project to see if error would be present there as well, and it was.

So after scratching my head a bit I just set a RUN_CLANG_STATIC_ANALYZER as true for the target/build where I needed it:


This way I got the static analysis messages back.

Hope this can help someone!

Update. Or as Jaime Santana commented, just "launch Analysis from the menu option Menu -> Product -> Analyze". Thank you Jamie, that worked!

Thursday, February 18, 2016

Note to self - concatenating rows into string with MSSQL

Here is a sample code:

select count(a.v2_icid), a.v2_icid,
(select distinct(fullname) + ',' AS [text()] from systemuser u 
join account acc on acc.ownerid = u.systemuserid 
where acc.v2_icid = a.v2_icid For XML PATH ('')) [Users]
from account a
where statecode = 0 and a.v2_icid is not null
group by a.v2_icid
having count(a.v2_icid) > 1
order by a.v2_icid

Monday, December 7, 2015

So, here is my string dump for x64 in windbg

Based on this and that.

$$>a<"c:\_install\dumpstringtofolder.txt" 000007feed816500 1000 c:\temp\stringtest

and the script:

$$ Dumps the managed strings to a file
$$ Platform x64
$$ First argument is the string method table pointer
$$ Second argument is the Min size of the string that needs to be used filter
$$ the strings
$$ Third is the path of the file
.foreach ($string {!dumpheap -short -mt ${$arg1}  -min ${$arg2}})
{
r@$t0=  poi(${$string}+8)*2
.writemem ${$arg3}${$string}.txt ${$string}+c L? @$t0
}

The only other thing I needed this time is this on one of the strings:

!gcroot 0000000100e769f0

To see:

   ->  0000000180006d08 System.Web.Caching.CacheMultiple
            ->  00000001800069c8 System.Web.Caching.CacheCommon
            ->  00000001800034a8 System.Web.RequestTimeoutManager
....
            ->  00000004021b5740 System.Web.SessionState.InProcSessionState
            ->  00000004021b5288 System.Web.SessionState.SessionStateItemCollection
....
            ->  0000000289779a58 ASP.ordercomposer_orderedit_aspx
            ->  000000018c14fe38 XYZ.Ordering.Modules.OrderingViewStatePresister

So this time the root of the problem was in keeping viewstate in the session and not really purging not needed view state away. This was one of the legacy apps and reminded everyone the old none-tasty view state solution from MS :). Viva MVC and looking forward the day with no legacy ASP.NET apps we need to support :)!