Showing posts with label Programming. Show all posts
Showing posts with label Programming. Show all posts

Saturday, November 26, 2011

Just played around with Greasemonkey

I'm not a javascript expert, but just played around using js in greasemonkey, quite funny.

// ==UserScript==
// @name FilterGuruEntry
// @description Filter Guru Entry
// @include http://www.guru.com/pro/search_results.cfm*
// ==/UserScript==


var allTRs, thisTR;
allTRs = document.getElementsByTagName('SPAN');
for (var i = 0; i < allTRs.length; i++) {

thisTR = allTRs[i];

if (thisTR.getAttribute("class") == "btblue") {

//myTBODY = thisTR.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;
myTR = thisTR.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;
myTD = thisTR.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;

if (myTR.nodeName == "TR") {
//myTR.removeChild(myTD);
//myTR.removeChild(myTR.lastChild);
myTR.removeChild(myTD);

}

//myTBODY.removeChild(myTR);
}
}

Thursday, December 2, 2010

Capture standard output (stdout) in console command running at VBS

We can use WScript.Shell.Exec( ) and WScript.Shell.StdOut.ReadLine( ) to perform the task:




Set objShell = WScript.CreateObject("WScript.Shell")
Set objExecObject = objShell.Exec("cmd /c dir")
strText=""
Do While Not objExecObject.StdOut.AtEndOfStream
strText = strText & objExecObject.StdOut.ReadLine() & chr(13)
Loop
Wscript.Echo strText

Wednesday, April 16, 2008

Enable Java assertion

Just a soft reminder in case I want to use Java assertion. Given a class Cls:

> java -ea:Cls Cls

The comment will execute Cls which assertion enabled.

Tuesday, June 19, 2007

Context level of Moodle

From lib/accesslib.php

25 // context definitions
26 define('CONTEXT_SYSTEM', 10);
27 define('CONTEXT_PERSONAL', 20);
28 define('CONTEXT_USER', 30);
29 define('CONTEXT_COURSECAT', 40);
30 define('CONTEXT_COURSE', 50);
31 define('CONTEXT_GROUP', 60);
32 define('CONTEXT_MODULE', 70);
33 define('CONTEXT_BLOCK', 80);

Sunday, June 3, 2007

Using EditItemTemplate for InsertItemTemplate in FormView (ASP.NET)

There is a nice way to reuse your hardly made EditItemTemplate in the InsertItemtemplate. Found in ASP.NET forum:
protected void FormView1_Init(object sender, EventArgs e) {

   FormView1.InsertItemTemplate = FormView1.EditItemTemplate

}

protected void FormView1_DataBound(object sender, EventArgs e) {     

  if (FormView1.CurrentMode == FormViewMode.Edit) {

       LinkButton InsertButton = FormView1.FindControl("InsertButton") as LinkButton;

       LinkButton UpdateButton = FormView1.FindControl("UpdateButton") as LinkButton;

       InsertButton.Visible = false;

       UpdateButton.Visible = true;

  } else if (FormView1.CurrentMode == FormViewMode.Insert) {

       LinkButton InsertButton = FormView1.FindControl("InsertButton") as LinkButton;

       LinkButton UpdateButton = FormView1.FindControl("UpdateButton") as LinkButton;

       InsertButton.Visible = true;

       UpdateButton.Visible = false;

  }

}

Ref: http://forums.asp.net/t/1102469.aspx

Friday, May 25, 2007

String Concatenation in SQL Server

When using '+' to concatenate two string field in SQL server (e.g. a+b), if one of them is NULL, then the whole string will become NULL. There is one solution to solve it:

COALESCE(a,'') + COALESCE(b,'')

So if any of the field is NULL, it will evaluate as an empty string. That's it!

Thursday, April 12, 2007

AutoIncrement in .NET and Autonumber in ACCESS

From my experience, try to avoid turning on both AutoIncrement (in DataColumn) in .NET and Autonumber in MSAccess at the same time. As somehow there is just no communication between them. They just work on their own.

For example, when you have records in ACCESS having ID (1,2,3,4) and suppose the next ID be 10 (as doing some record add and delete before). AutoIncrement in .NET just don't know about it as it's AutoIncrementSeed can just automatically set to 5.

Then 10 vs 5, I hope you can see how the problem being occurred. So avoid having them both at the same time.

Tuesday, April 3, 2007

Literal vs Label

When working with .NET, you may wonder the difference between Literal and Label.

Actually, when both controls are converted to become HTML, Label will add a pair of <span></span> tag, while Literal keeps everything unchanged.

So most of the time if would be better to use Literal instead of Label for the sake of simplicity.

CSP on Apache

To add CSP to root if sort of funny. The following will NOT work for most cases !!     <LocationMatch "^/$">        Header s...