Month: March 2017

old netbeans api code to get line numbers

g.setColor(Color.red);
		int lastLineNo = -1;
		while (hq.moveNext()) {
			AttributeSet as = hq.getAttributes();
			if (as != null) {
				try {
					lineNo = NbDocument.findLineNumber((StyledDocument) document, hq.getStartOffset());
					if (lineNo != lastLineNo) {
						lastLineNo = lineNo;
						g.drawString(String.valueOf(lineNo + 1), 0, fontHeight * (lineNo + 1) - 3);
					}
				} catch (Exception ex) {
					ModuleLib.log(CommonLib.printException(ex));
				}
			}
		}

read count : 21

get netbeans current row highlight color

		FontColorSettings fcs = MimeLookup.getLookup(MimePath.EMPTY).lookup(FontColorSettings.class);
		Coloring c = Coloring.fromAttributeSet(fcs.getFontColors(FontColorNames.CARET_ROW_COLORING));
		g.setColor(c.getBackColor());

read count : 5

Script to browse every pages of sharepoint 2013

Add-PSSnapin Microsoft.SharePoint.PowerShell
$creds = [System.Net.CredentialCache]::DefaultCredentials
$DEBUGLOG = "c:\SharePoint.log"
$SPECIFICURLs= "c:\SharePoint.URLs.txt"

function Log([string] $msg,[string] $colour)
{
    if($colour -ne "") {
        Write-Host $msg -ForegroundColor $colour
    }
    else {
        Write-Host $msg
    }
}

function Debug([string] $msg)
{
    echo $msg >> $DEBUGLOG
}

function JoinURL([string]$a,[string]$b)
{
    if($a.EndsWith('/')) { $a=$a.Substring(0,$a.length-1) }
    if($b.StartsWith('/')) { $b=$b.Substring(1) }
    return $a + '/' + $b
}

function Fetch-WebPage([string]$url,[bool]$ignoreErrors = $false)
{
    $bypassonlocal = $false
    $proxyuri = "http://" + $env:COMPUTERNAME
    $proxy = New-Object system.Net.WebProxy($proxyuri, $bypassonlocal)

    $client = New-Object Net.WebClient
    $client.Credentials = $creds
    $client.Proxy = $proxy
    Debug "Fetching $url" 
    try {
        $pageContents = $Client.DownloadString($url) 2>&1 | Out-Null
    }
    catch {
        $msg = $error[0].ToString()
        if($ignoreErrors -eq $false) {
            Log "ERROR: $msg" "Red" 
            Debug "ERROR: $msg"
        }
    }
    $client.Dispose()
    ###Debug $pageContents
}

function ProcessWebApplication ([string]$url)
{ 
    Log "-- Root site URL: $url" "Green"
    $sitecollections = Get-SPSite $url 2>$null
    if($sitecollections -eq $null) { 
        Log "  -- No site collections found under this URL" "Cyan"
        return
    }

    $IsCA = $false
    if($sitecollections.WebApplication.IsAdministrationWebApplication) {
        Log " -- This is Central Administration" "Blue"
        $IsCA = $true
    }

    foreach($sc in $sitecollections) {
        $scUrl = JoinURL $url $sc.ServerRelativeUrl
        Log "  -- $scUrl" "Green"
        $subsites = $sc | Get-SPWeb -Limit 20
        if($subsites -eq $null) {
            Log "    -- No site collections found under this URL" "Cyan"
            continue
        }

        foreach($site in $subsites) {
            $siteUrl = JoinURL $scUrl $site.ServerRelativeUrl
            Log "    -- Fetching $siteUrl" "White"
            Fetch-WebPage $siteUrl

            # For non-Central Admin sites, try a search
            if($IsCA -eq $false) {
                # See if this site has a standard search results page
                $siteSearchUrl = JoinURL $siteUrl "/_layouts/osssearchresults.aspx?k=test"
                Log "    -- Fetching $siteSearchUrl" "White"
                Fetch-WebPage $siteSearchUrl $true

                # Bonus fetch of site search results page for Search Center sites
                $webTemplate = $site.WebTemplate
                if($webTemplate.StartsWith("SRCHCEN")) {
                    $siteSearchUrl = JoinURL $site.Url "/Pages/results.aspx?k=test"
                    Log "    -- Fetching $siteSearchUrl" "White"
                    Fetch-WebPage $siteSearchUrl
                }
            }
            $site.Dispose()
        }
    }
    Log ""
}

$zones=("Default", "Intranet", "Internet", "Custom", "Extranet")
foreach($zone in $zones) {
    Log "$zone Zone" "Yellow"
    $altURLs = Get-SPAlternateUrl -Zone $zone
    if($altURLs -eq $null) {
        Log "-- No URLs under this zone"
        continue
    }
    foreach($url in $altURLs) {
        ProcessWebApplication $url.IncomingUrl
    }
}

# Process any specific URLs
$URLFile = Get-Content $SPECIFICURLs -ErrorAction SilentlyContinue
if($URLFile -eq $null) {
    exit
}
Log ""
Log "Fetching custom URLs" "Yellow"
foreach($u in $URLFile) {
    Log "  -- Fetching $u" "White"
    Fetch-WebPage $u
}

Log "Finished."

read count : 10

Start bochs with a fixed window location

Bochs doesn’t has a parameter to specific the startup window position on screen. If you are compiling boots with SDL2. You can edit boots_source/gui/sdl2.cc, and change the first SDL_WINDOWPOS_UNDEFINED to x position and second SDL_WINDOWPOS_UNDEFINED to y position.

  window = SDL_CreateWindow(
    BOCHS_WINDOW_NAME,
    SDL_WINDOWPOS_UNDEFINED,
    SDL_WINDOWPOS_UNDEFINED,
    640,
    480,
    SDL_WINDOW_SHOWN
    );

read count : 4