This code print all elements and styles of JEditorPane

This code print all elements and styles of JEditorPane

		HTMLDocument doc = (HTMLDocument) jEditorPane1.getDocument();
		printElements(doc.getRootElements(), "");
	void printElements(Element elements[], String tabs) {
		for (Element element : elements) {
			//System.out.println("element=" + element.getDocument());
			int start = element.getStartOffset();
			int end = element.getEndOffset();
			try {
				System.out.println(tabs + element.getDocument().getText(start, end - start));
			} catch (BadLocationException ex) {
				ex.printStackTrace();
			}
			AttributeSet as = element.getAttributes();
			Enumeration e = as.getAttributeNames();
			while (e.hasMoreElements()) {
				Object o = e.nextElement();
				//System.out.println("	o=" + o.getClass());
				if (o instanceof String) {
					String attrName = (String) o;
					System.out.println(tabs + "	string=" + attrName);
				} else if (o instanceof StyleConstants) {
					System.out.println(tabs + "	FontSize=" + as.getAttribute(StyleConstants.Size));
					System.out.println(tabs + "	FontFamily=" + as.getAttribute(StyleConstants.FontFamily));
					System.out.println(tabs + "	Foreground=" + as.getAttribute(StyleConstants.Foreground));
				} else if (o instanceof CSS.Attribute) {
					CSS.Attribute a = (CSS.Attribute) o;
					System.out.println(tabs + "	" + a.toString() + " - " + a.getDefaultValue());
				} else {
					System.out.println("	o=" + o.getClass());
				}
			}
			System.out.println(tabs + "------------------------------------------------------------------");
			for (int x = 0; x < element.getElementCount(); x++) {
				printElements(new Element[]{element.getElement(x)}, tabs + "   ");
			}
		}
	}

read count : 3

This c# code can connect sharepoint 2013 through restful by username and password

Thanks God, This c# code can connect sharepoint 2013 through restful by username and password

            HttpWebRequest endpointRequest = (HttpWebRequest)HttpWebRequest.Create(&quot;http://win-344c6v6tjp4:88/_api/web/lists&quot;);

            endpointRequest.Method = &quot;GET&quot;;
            endpointRequest.Accept = &quot;application/json;odata=verbose&quot;;
            NetworkCredential cred = new System.Net.NetworkCredential(&quot;administrator&quot;, &quot;this is my password&quot;);
            endpointRequest.Credentials = cred;
            HttpWebResponse endpointResponse = (HttpWebResponse)endpointRequest.GetResponse();
            try
            {
                WebResponse webResponse = endpointRequest.GetResponse();
                Stream webStream = webResponse.GetResponseStream();
                StreamReader responseReader = new StreamReader(webStream);
                string response = responseReader.ReadToEnd();
                JObject jobj = JObject.Parse(response);
                JArray jarr = (JArray)jobj[&quot;d&quot;][&quot;results&quot;];
                foreach (JObject j in jarr)
                {
                    Console.WriteLine(j[&quot;Title&quot;] + &quot; &quot; + j[&quot;Body&quot;]);
                }

                responseReader.Close();
                Console.ReadLine();
            }
            catch (Exception e)
            {
                Console.Out.WriteLine(e.Message); Console.ReadLine();
            }

read count : 15

open default editor using netbeans api

		try {
			DataObject.find(FileUtil.toFileObject(new File("/Users/peter/workspace/PeterI/kernel/kernel.cpp"))).
					getLookup().lookup(OpenCookie.class).open();
		} catch (DataObjectNotFoundException ex) {
			Exceptions.printStackTrace(ex);
		}

read count : 5

Powershell commands to upload/download a page to sharepoint 2013

Upload file:

Add-PSSnapIn "Microsoft.SharePoint.Powershell" 
# Set the variables 
$WebURL = “http://your_sharepoint/your_site” 
$DocLibName = "Pages"
$FilePath = “C:\a.aspx” 

# Get a variable that points to the folder 
$Web = Get-SPWeb $WebURL 

$List = $Web.GetFolder($DocLibName) 
$Files = $List.Files 

# Get just the name of the file from the whole path 
$FileName = $FilePath.Substring($FilePath.LastIndexOf("\")+1) 

# Load the file into a variable 
$File= Get-ChildItem $FilePath

# Upload it to SharePoint 
$Files.Add($DocLibName +"/" + $FileName,$File.OpenRead(),$false) 
$web.Dispose()

Download file (Html special characters will be escaped):

Add-PSSnapin Microsoft.Sharepoint.Powershell

$WebURL = “http://kmp21dev.emsd.hksarg/kmp21dev” 
$web = Get-SPWeb $WebURL
$file = $web.GetFile('pages/homepage.aspx');
$bytes = $file.OpenBinary();

[System.IO.File]::WriteAllBytes('c:\users\spadmin\homepage.aspx', $bytes);

read count : 7

bochs breakpoint panel

extended netbeans, auto scan .c/.cc/.cpp files to find my bochs breakpoint marco, double click it will jump to there. Small tool, but save me a lot of time.pause_bochs-panel

read count : 12

Visual c++ example to read mbr

Install windows ddk and run it using admin permission, otherwise all bytes that read from mbr are 0xcd. It can be compile using visual c++ community exition.

virus

#include "stdafx.h"
#include <cstdlib>
#include <windows.h>
#include <stdio.h>
#include <iostream>
#define FILE_SHARE_VALID_FLAGS (0x00000007) 
using namespace std;

short ReadSect
(
	const char *_dsk,    // disk to access
	char *&_buff,         // buffer where sector will be stored
	unsigned int _nsect   // sector number, starting with 0
)
{
	DWORD dwRead;
	wchar_t wdsk[100];
	size_t count;
	mbstowcs_s(&count, wdsk, sizeof(wdsk) / sizeof(wdsk[0]), _dsk, _TRUNCATE);
	HANDLE hDisk = CreateFile(wdsk, GENERIC_READ, FILE_SHARE_VALID_FLAGS, 0, OPEN_EXISTING, 0, 0);
	if (hDisk == INVALID_HANDLE_VALUE) // this may happen if another program is already reading from disk
	{
		CloseHandle(hDisk);
		return 1;
	}
	SetFilePointer(hDisk, _nsect * 512, 0, FILE_BEGIN); // which sector to read

	ReadFile(hDisk, _buff, 512, &dwRead, 0);  // read sector
	CloseHandle(hDisk);
	return 0;
}

int main()
{
	char *dsk = "\\\\.\\PhysicalDrive0";
	int sector = 0;

	char *buff = new char[512];
	ReadSect(dsk, buff, sector);
	for (int x = 0; x < 512; x++) {
		printf("%x ", buff[x] & 0xff);
	}
	if ((unsigned char)buff[510] == 0x55 && (unsigned char)buff[511] == 0xaa) {
		cout << "Disk is bootable!" << endl;
	}

	getchar();
	return 0;
}

read count : 16

ffmpeg and ffplay for logitech webcam

These command works on windows and capture video using my logitech C920 webcam

Save viewcam to a file, becareful, windows media play may not able to play mp4 in a very clean windows. You can save it to avi.

ffmpeg -f dshow -i video="Logitech HD Pro Webcam C920" -c copy -y c:\users\peter\desktop\a.mp4

Save viewcam video and play it using ffplay, but it has few seconds delay

ffmpeg -f dshow -i video="Logitech HD Pro Webcam C920" -c copy -y c:\users\peter\desktop\a.mp4 -c:v copy -copytb 1 -an -f mjpeg udp://127.0.0.1:1234/ | ffplay -f mjpeg p-rpbesize 32 udp://127.0.0.1:1234

Just play it by ffplay

ffmpeg -f dshow -i video="Logitech HD Pro Webcam C920" -c:v copy -copytb 1 -an -f mjpeg udp://127.0.0.1:1234/ | ffplay -f mjpeg -probesize 32 udp://127.0.0.1:1234

https://ffmpeg.zeranoe.com/forum/viewtopic.php?t=2421

read count : 15