### Install NT Service Source: https://github.com/jinghuazhao/jinghuazhao.github.io/blob/master/docs/iop/jinghua/winprog/win32_2.md Installs a new NT service using the CreateService function. Ensure the executable path is correct and the service name/label are appropriate. ```c #include #include void ErrorHandler(char *s, DWORD err) { cout << s << endl; cout << "Error number: " << err << endl; ExitProcess(err); } void main(int argc, char *argv[]) { SC_HANDLE newService, scm; if (argc != 4) { cout << "Usage:\n"; cout << " install service_name \ service_label executable\n"; cout << " service_name is the \n name used internally by the SCM\n"; cout << " service_label is the \n name that appears in the Services applet\n"; cout << " (for multiple \n words, put them in double quotes)\n"; cout << " executable is the \n full path to the EXE\n\n"; return; } // open a connection to the SCM scm = OpenSCManager(0, 0, SC_MANAGER_CREATE_SERVICE); if (!scm) ErrorHandler("In OpenScManager", GetLastError()); // Install the new service newService = CreateService( scm, argv[1], // eg "beep_srv" argv[2], // eg "Beep Service" SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS, SERVICE_DEMAND_START, SERVICE_ERROR_NORMAL, argv[3], // eg "c:\\winnt\\xxx.exe" 0, 0, 0, 0, 0); if (!newService) ErrorHandler("In CreateService", GetLastError()); else cout << "Service installed\n"; // clean up CloseServiceHandle(newService); CloseServiceHandle(scm); } ``` -------------------------------- ### Install a Windows Service Source: https://github.com/jinghuazhao/jinghuazhao.github.io/blob/master/docs/iop/jinghua/winprog/win32_2.md Use OpenSCManager to connect to the SCM and CreateService to install a new service. Ensure the account has sufficient privileges. SERVICE_WIN32_OWN_PROCESS indicates a single service per EXE, and SERVICE_DEMAND_START means manual startup. ```command-line install BeepService "Beeper" c:\\winnt\\beep.exe ``` -------------------------------- ### Jekyll Build and Serve Scripts Source: https://context7.com/jinghuazhao/jinghuazhao.github.io/llms.txt Provides bash commands for installing dependencies, serving the Jekyll site locally, and building for production. Includes npm script equivalents and Docker-based development setup. ```bash # Install Ruby gems bundle install # Serve locally (default, port 4000) bundle exec jekyll serve -H 0.0.0.0 # Build for production JEKYLL_ENV=production bundle exec jekyll build # --- OR using npm scripts --- npm install # install Node dev deps (eslint, stylelint, etc.) npm run serve # equivalent to bundle exec jekyll serve npm run build # JEKYLL_ENV=production bundle exec jekyll build # --- Docker development (no local Ruby needed) --- docker-compose -f docker/docker-compose.dev.yml up # --- Lint JavaScript and SCSS --- npm run eslint npm run stylelint ``` -------------------------------- ### Install R Package from Local Repository Source: https://github.com/jinghuazhao/jinghuazhao.github.io/blob/master/docs/r-progs.md Use this command to install the 'kinship' package from a local repository. Ensure the contriburl points to the correct software location. ```r install.packages("kinship",contriburl="http://jhz22.user.srcf.net/software") ``` -------------------------------- ### SAS Environment Setup (SAS Macro) Source: https://github.com/jinghuazhao/jinghuazhao.github.io/blob/master/docs/software/go/programs.htm This program sets up SAS environment by defining libnames for data locations and defining utility macros. It also includes a format for age grouping. ```sas options replace=yes mprint spool nocenter ps=max ls= max; libname affy500k '/data/genetics/GWA/annotate'; libname obesity '/data/genetics/scratch/obesity500k'; libname scratch '/data/genetics/scratch'; libname epic5k '.'; %let home=/data/genetics/GWA/Obesity/apr-2007/; %global nobs cases controls; %macro count(dsn); data _null_; if 0 then set &dsn nobs=count; call symput('nobs',left(put(count,16.))); stop; run; %mend count; %include ds2text; proc format; value agefmt low-<50='1' 50-<60='2' 60-<70='3' 70-high='4'; run; ``` -------------------------------- ### Advanced SST Program Setup Source: https://github.com/jinghuazhao/jinghuazhao.github.io/blob/master/docs/iop/jinghua/winprog/sst.md Includes necessary headers for labels and buttons for a more advanced SST application. This sets up the structure for an incrementing counter program. ```c // Counter program #include #include #include "button.h" #include "input.h" #include "label.h" #include "rect.h" #include "window.h" class App: public Window { Label *number; int count; public: App( char *s, Rect &r ); virtual void HandleEvent( Event &event ); }; App app( "Test", Rect(1, 1, 80, 24) ); const int QUIT = 100; const int COUNT = 101; App::App( char *s, Rect &r ): Window( s, r ), count( 0 ) { ``` -------------------------------- ### App Constructor with Button Insertion Source: https://github.com/jinghuazhao/jinghuazhao.github.io/blob/master/docs/iop/jinghua/winprog/sst.md Implement the App constructor to insert controls into the window. This example adds a 'Quit' button with a specific ID and position. ```c const int QUIT = 100; App::App( char *s, Rect &r ): Window( s, r ), count( 0 ) { Insert( new Button(" Quit", Rect(50, 18, 57, 20), QUIT) ); } ``` -------------------------------- ### Create and Wait for a Simple Thread Source: https://github.com/jinghuazhao/jinghuazhao.github.io/blob/master/docs/iop/jinghua/winprog/win32_1.md This example shows how to create a background thread that performs a task (beeping) a specified number of times. The main thread waits for the background thread to complete using WaitForSingleObject. ```c #include #include #include // The function to run in a thread void HonkThread(DWORD iter) { DWORD i; for (i=0; i < iter; i++) { Beep(200, 50); Sleep(1000); } } void main(void) { HANDLE honkHandle; DWORD threadID; DWORD iterations; CHAR iterStr[100]; cout << "Enter the number of beeps to produce: "; cin.getline(iterStr, 100); // convert string into integer iterations=atoi(iterStr); // create a thread which // executes the "HonkThread" function honkHandle=CreateThread(0, 0, (LPTHREAD_START_ROUTINE) HonkThread, (VOID *) iterations, 0, &threadID); // wait until the thread has finished int count=0; while ( WaitForSingleObject(honkHandle, 0) == WAIT_TIMEOUT) { cout << "waiting for the thread to finish " << count++ << endl; } } ``` -------------------------------- ### Install R Package from GitHub Source: https://github.com/jinghuazhao/jinghuazhao.github.io/blob/master/docs/r-progs.md Install R packages directly from GitHub using the devtools package. This is a convenient way to get the latest versions or packages not available on CRAN. ```r library(devtools) install_github("cran/kinship") ``` -------------------------------- ### CStatic Text Appearance Example Source: https://github.com/jinghuazhao/jinghuazhao.github.io/blob/master/docs/iop/jinghua/winprog/part3.md This C++ code demonstrates the creation of a CStatic object within a CFrameWnd. It includes application initialization and window setup, culminating in the creation of a centered, bordered static label. ```c++ #include // Declare the application class class CTestApp : public CWinApp { public: virtual BOOL InitInstance(); }; // Create an instance of the application class CTestApp TestApp; // Declare the main window class class CTestWindow : public CFrameWnd { CStatic* cs; public: CTestWindow(); }; // The InitInstance function is called // once when the application first executes BOOL CTestApp::InitInstance() { m_pMainWnd = new CTestWindow(); m_pMainWnd->ShowWindow(m_nCmdShow); m_pMainWnd->UpdateWindow(); return TRUE; } // The constructor for the window class CTestWindow::CTestWindow() { CRect r; // Create the window itself Create(NULL, "CStatic Tests", WS_OVERLAPPEDWINDOW, CRect(0,0,200,200)); // Get the size of the client rectangle GetClientRect(&r); r.InflateRect(-20,-20); // Create a static label cs = new CStatic(); cs->Create("hello world", WS_CHILD|WS_VISIBLE|WS_BORDER|SS_CENTER, r, this); } ``` -------------------------------- ### Connect to Named Pipe Server (C) Source: https://github.com/jinghuazhao/jinghuazhao.github.io/blob/master/docs/iop/jinghua/winprog/win32_3.md Demonstrates creating a named pipe client using CreateFile to connect to a server. Use this when an application needs to send data to or receive data from a named pipe server. ```c #define PIPE_NAME "\\\\.\\pipe\\MyPipe" // ... inside a function ... HANDLE hPipe = CreateFile( PIPE_NAME, // pipe name GENERIC_READ | GENERIC_WRITE, // read and write access 0, // no sharing NULL, // default security attributes OPEN_EXISTING, // opens existing pipe 0, // default attributes NULL); // no template file if (hPipe == INVALID_HANDLE_VALUE) { // Handle error return 1; } // ... proceed with reading/writing ... CloseHandle(hPipe); ``` -------------------------------- ### Install R Package to Specific Library Source: https://github.com/jinghuazhao/jinghuazhao.github.io/blob/master/docs/r-progs.md Installs the 'kinship' package into the 'R' library directory. This is useful for managing multiple R library locations. ```r install.packages("kinship","R",contriburl="http://jhz22.user.srcf.net/software") ``` -------------------------------- ### Define App Class and Instance Source: https://github.com/jinghuazhao/jinghuazhao.github.io/blob/master/docs/iop/jinghua/winprog/sst.md Derive the application class from Window, declare its members, and create a global instance. This sets up the basic structure for an SST application. ```c #include #include #include "button.h" #include "rect.h" #include "window.h" class App: public Window { public: App( char *s, Rect &r ); virtual void HandleEvent( Event &event ); }; App app( "Test", Rect(1, 1, 80, 24) ); ... void main() { app.Execute(); } ``` -------------------------------- ### MFC "Hello World" Program Source: https://github.com/jinghuazhao/jinghuazhao.github.io/blob/master/docs/iop/jinghua/winprog/mfc1.md This C++ code defines a minimal MFC application that displays a "Hello World!" window with a static text label. It includes the necessary includes, application and window class definitions, and the main initialization logic. ```cpp //hello.cpp #include // Declare the application class class CHelloApp : public CWinApp { public: virtual BOOL InitInstance(); }; // Create an instance of the application class CHelloApp HelloApp; // Declare the main window class class CHelloWindow : public CFrameWnd { CStatic* cs; public: CHelloWindow(); }; // The InitInstance function is called each // time the application first executes. BOOL CHelloApp::InitInstance() { m_pMainWnd = new CHelloWindow(); m_pMainWnd->ShowWindow(m_nCmdShow); m_pMainWnd->UpdateWindow(); return TRUE; } // The constructor for the window class CHelloWindow::CHelloWindow() { // Create the window itself Create(NULL, "Hello World!", WS_OVERLAPPEDWINDOW, CRect(0,0,200,200)); // Create a static label cs = new CStatic(); cs->Create("hello world", WS_CHILD|WS_VISIBLE|SS_CENTER, CRect(50,80,150,150), this); } ``` -------------------------------- ### MFC "Hello World" Application Code Source: https://github.com/jinghuazhao/jinghuazhao.github.io/blob/master/docs/iop/jinghua/winprog/mfc2.md This is the complete source code for a simple MFC "Hello World" application. It demonstrates the basic structure including application and window class definitions, initialization, and window creation. ```cpp 1 //hello.cpp 2 #include 3 // Declare the application class 4 class CHelloApp : public CWinApp 5 { 6 public: 7 virtual BOOL InitInstance(); 8 }; 9 // Create an instance of the application class 10 CHelloApp HelloApp; 11 // Declare the main window class 12 class CHelloWindow : public CFrameWnd 13 { 14 CStatic* cs; 15 public: 16 CHelloWindow(); 17 }; 18 // The InitInstance function is called each 19 // time the application first executes. 20 BOOL CHelloApp::InitInstance() 21 { 22 m_pMainWnd = new CHelloWindow(); 23 m_pMainWnd->ShowWindow(m_nCmdShow); 24 m_pMainWnd->UpdateWindow(); 25 return TRUE; 26 } 27 // The constructor for the window class 28 CHelloWindow::CHelloWindow() 29 { 30 // Create the window itself 31 Create(NULL, 32 "Hello World!", 33 WS_OVERLAPPEDWINDOW, 34 CRect(0,0,200,200)); 35 // Create a static label 36 cs = new CStatic(); 37 cs->Create("hello world", 38 WS_CHILD|WS_VISIBLE|SS_CENTER, 39 CRect(50,80,150,150), 40 this); 41 } ``` -------------------------------- ### PM+ Data File Format Example Source: https://github.com/jinghuazhao/jinghuazhao.github.io/blob/master/docs/software/pm.md Example of the data file format for PM+, showing individual IDs, affection status, and observed alleles for three markers. Column 1 is ID, Column 2 is affection status (1=case, 0=control), and Columns 3-8 are alleles. ```plaintext 1 1 2 10 5 1 1 5 2 1 7 7 1 4 4 4 3 1 1 4 1 2 4 1 4 1 2 12 5 1 1 5 5 1 12 12 1 3 5 2 ... ... 270 0 2 4 2 5 2 1 271 0 12 12 1 1 5 5 ``` -------------------------------- ### Create Named Pipe Server (C) Source: https://github.com/jinghuazhao/jinghuazhao.github.io/blob/master/docs/iop/jinghua/winprog/win32_3.md Demonstrates creating a named pipe server using CreateNamedPipe. Specifies pipe access modes and types. Use this when setting up a server to listen for client connections. ```c #define PIPE_NAME "\\\\.\\pipe\\MyPipe" // ... inside a function ... HANDLE hPipe = CreateNamedPipe( PIPE_NAME, // pipe name PIPE_ACCESS_DUPLEX, // read/write access PIPE_TYPE_MESSAGE | // message type pipe PIPE_READMODE_MESSAGE | // message-read mode PIPE_WAIT, // blocking mode PIPE_UNLIMITED_INSTANCES, // max. instances 0, // output buffer size 0, // input buffer size 0, // client time-out NULL); // default security attribute if (hPipe == INVALID_HANDLE_VALUE) { // Handle error return 1; } // Wait for the client to connect if (!ConnectNamedPipe(hPipe, NULL) && GetLastError() != ERROR_PIPE_CONNECTED) { // Handle error CloseHandle(hPipe); return 1; } // ... proceed with reading/writing ... DisconnectNamedPipe(hPipe); CloseHandle(hPipe); ``` -------------------------------- ### EHPLUS Input Data Source: https://github.com/jinghuazhao/jinghuazhao.github.io/blob/master/docs/software/pm.md Example 'ehplus.dat' file format for EHPLUS, combining genotype identifiers with subject counts. ```text 2 2 2 4 2 2 4 3 0 3 5 2 1 1 6 1 0 1 8 1 0 1 9 1 1 0 ``` -------------------------------- ### PM Analysis Screen Output Source: https://github.com/jinghuazhao/jinghuazhao.github.io/blob/master/docs/software/pm.md Example screen output from the PM analysis program, showing analysis settings and parameters. ```text Permutation & Model-free analysis PM 1.0 15-JUN-1998 Maximum number of loci = 30 Maximum number of individuals = 800 Number of loci in this analysis = 2 Permutation procedure will not be invoked Number of alleles at these loci and their selection/permutation statuses [1=yes,0=no]: locus 1: alleles= 2 selection= 1 permutation= 0 ``` -------------------------------- ### Create Simplest SST Application Source: https://github.com/jinghuazhao/jinghuazhao.github.io/blob/master/docs/iop/jinghua/winprog/sst.md This code demonstrates the creation of a basic SST application with labels, buttons, and event handling for counting and quitting. It initializes UI elements and defines event handlers for button clicks. ```cpp Insert( new Label("Count: ", Rect(20, 5, 30, 7)) ); number = new Label("0", Rect(31, 5, 40, 7)); Insert( number ); Insert( new Button(" Increment", Rect(28, 18, 40, 20), COUNT) ); Insert( new Button(" Quit", Rect(50, 18, 57, 20), QUIT) ); } void main() { app.Execute(); } void App::HandleEvent( Event &event) { char t[100]; ostrstream ostr ( t, 100 ); Window::HandleEvent( event ); if( event.type == COMMAND ) { switch( event.message ) { case COUNT: count++; ostr.width(4); ostr << count << ends; number->SetTitle( t ); break; case QUIT: Close(); screen.Clear(); break; } } event.type = CLEAR; ``` -------------------------------- ### EH Case-Control Analysis Output Source: https://github.com/jinghuazhao/jinghuazhao.github.io/blob/master/docs/software/pm.md Example output from EH for a case-control analysis, including hypotheses for marker association and independence from disease. ```text #param Ln(L) Chi-square -------------------------------------------------- H0: No Association 2 -23.84 0.00 H1: Markers Asso., Indep. of Disease 3 -23.75 0.18 H2: Markers and Disease Associated 6 -23.74 0.20 ``` -------------------------------- ### Implement InitInstance for MFC Application Source: https://github.com/jinghuazhao/jinghuazhao.github.io/blob/master/docs/iop/jinghua/winprog/mfc2.md Overrides the InitInstance function to create and display the main window for a new application instance. Returns TRUE on successful initialization. ```cpp 18 // The InitInstance function is called each 19 // time the application first executes. 20 BOOL CHelloApp::InitInstance() 21 { 22 m_pMainWnd = new CHelloWindow(); 23 m_pMainWnd->ShowWindow(m_nCmdShow); 24 m_pMainWnd->UpdateWindow(); 25 return TRUE; 26 } ``` -------------------------------- ### EH Standard Analysis Output Source: https://github.com/jinghuazhao/jinghuazhao.github.io/blob/master/docs/software/pm.md Example output from the EH program for a standard analysis, showing likelihoods and chi-square values for different association hypotheses. ```text #param Ln(L) Chi-square ------------------------------------------------- H0: No Association 2 -23.84 0.00 H1: Allelic Associations Allowed 3 -23.75 0.18 ``` -------------------------------- ### MFC Application with Timer and Button Source: https://github.com/jinghuazhao/jinghuazhao.github.io/blob/master/docs/iop/jinghua/winprog/mfc4.md This C++ code demonstrates setting up a timer and handling window messages in an MFC application. It includes creating a main window, a button, and responding to timer events by beeping. Use this for applications requiring periodic actions or timed events. ```cpp #include #define IDB_BUTTON 100 #define IDT_TIMER1 200 // Declare the application class class CButtonApp : public CWinApp { public: virtual BOOL InitInstance(); }; // Create an instance of the application class CButtonApp ButtonApp; // Declare the main window class class CButtonWindow : public CFrameWnd { CButton *button; public: CButtonWindow(); afx_msg void HandleButton(); afx_msg void OnSize(UINT, int, int); afx_msg void OnTimer(UINT); DECLARE_MESSAGE_MAP() }; // A message handler function void CButtonWindow::HandleButton() { MessageBeep(-1); } // A message handler function void CButtonWindow::OnSize(UINT nType, int cx, int cy) { CRect r; GetClientRect(&r); r.InflateRect(-20,-20); button->MoveWindow(r); } // A message handler function void CButtonWindow::OnTimer(UINT id) { MessageBeep(-1); } // The message map BEGIN_MESSAGE_MAP(CButtonWindow, CFrameWnd) ON_BN_CLICKED(IDB_BUTTON, HandleButton) ON_WM_SIZE() ON_WM_TIMER() END_MESSAGE_MAP() // The InitInstance function is called once // when the application first executes BOOL CButtonApp::InitInstance() { m_pMainWnd = new CButtonWindow(); m_pMainWnd->ShowWindow(m_nCmdShow); m_pMainWnd->UpdateWindow(); return TRUE; } // The constructor for the window class CButtonWindow::CButtonWindow() { CRect r; // Create the window itself Create(NULL, "CButton Tests", WS_OVERLAPPEDWINDOW, CRect(0,0,200,200)); // Set up the timer SetTimer(IDT_TIMER1, 1000, NULL); // 1000 ms. // Get the size of the client rectangle GetClientRect(&r); r.InflateRect(-20,-20); // Create a button button = new CButton(); button->Create("Push me", WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON, r, this, IDB_BUTTON); } ``` -------------------------------- ### Create File with Custom Security Descriptor (C) Source: https://github.com/jinghuazhao/jinghuazhao.github.io/blob/master/docs/iop/jinghua/winprog/win32_4.md This C code snippet demonstrates creating a file with a custom security descriptor that grants only read access to the 'guest' user. Ensure your disk is formatted with NTFS for this to function correctly. ```c #include #include SECURITY_ATTRIBUTES sa; SECURITY_DESCRIPTOR sd; BYTE aclBuffer[1024]; PACL pacl=(PACL)&aclBuffer; BYTE sidBuffer[100]; PSID psid=(PSID) &sidBuffer; DWORD sidBufferSize = 100; char domainBuffer[80]; DWORD domainBufferSize = 80; SID_NAME_USE snu; HANDLE file; void main(void) { InitializeSecurityDescriptor(&sd, SECURITY_DESCRIPTOR_REVISION); InitializeAcl(pacl, 1024, ACL_REVISION); LookupAccountName(0, "guest", psid, &sidBufferSize, domainBuffer, &domainBufferSize, &snu); AddAccessAllowedAce(pacl, ACL_REVISION, GENERIC_READ, psid); SetSecurityDescriptorDacl(&sd, TRUE, pacl, FALSE); sa.nLength= sizeof(SECURITY_ATTRIBUTES); sa.bInheritHandle = FALSE; sa.lpSecurityDescriptor = &sd; file = CreateFile("c:\\testfile", GENERIC_READ | GENERIC_WRITE, 0, &sa, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, 0); CloseHandle(file); } ``` -------------------------------- ### Rect Class Definition Source: https://github.com/jinghuazhao/jinghuazhao.github.io/blob/master/docs/iop/jinghua/winprog/sst.md Defines the Rect class with constructors and methods for getting height and width, and setting size. Used for representing rectangular areas. ```cpp Rect( int x1, int y1, int x2, int y2 ); char Height(); void SetSize( Rect &r ); char Width(); }; #endif ``` -------------------------------- ### Read from Named Pipe (C) Source: https://github.com/jinghuazhao/jinghuazhao.github.io/blob/master/docs/iop/jinghua/winprog/win32_3.md Reads data from a named pipe. This example assumes the pipe is in message mode, so ReadFile returns when a complete message is received. ```c char buffer[1024]; DWORD dwRead; if (ReadFile(hPipe, buffer, sizeof(buffer) - 1, &dwRead, NULL)) { buffer[dwRead] = '\0'; // Null-terminate the string // Process the received message in buffer } else { // Handle error } ``` -------------------------------- ### Initialize Gitalk Comments Source: https://github.com/jinghuazhao/jinghuazhao.github.io/blob/master/docs/_includes/comments-providers/gitalk.html This snippet initializes Gitalk with necessary credentials and renders it into a specified container. Ensure all required site variables (clientID, clientSecret, repository, owner, admin) and page key are configured. ```javascript {%- assign _admin = '' -%} {%- for _admin_id in site.comments.gitalk.admin -%} {%- assign _admin = _admin | append: ", '" | append: _admin_id | append: "'" -%} {%- endfor -%} {%- assign _last = _admin | size | minus: 1 -%} {%- assign _admin = _admin | slice: 2, _last -%} window.Lazyload.css('{{ _sources.gitalk.css }}'); window.Lazyload.js('{{ _sources.gitalk.js }}', function() { var gitalk = new Gitalk({ clientID: '{{ site.comments.gitalk.clientID }}', clientSecret: '{{ site.comments.gitalk.clientSecret }}', repo: '{{ site.comments.gitalk.repository }}', owner: '{{ site.comments.gitalk.owner }}', admin: [{{ _admin }}], id: '{{ page.key }}' }); gitalk.render('js-gitalk-container'); }); ``` -------------------------------- ### Run fastsimcoal2 simulation Source: https://context7.com/jinghuazhao/jinghuazhao.github.io/llms.txt Execute fastsimcoal2 with specified template, sample size, estimation, and other options. Ensure the 'fsc27' module is loaded. ```bash module load fsc2 fsc27 -t model.tpl -n 1000 -e model.est -M -q ``` -------------------------------- ### Resize Image using ImageMagick Source: https://github.com/jinghuazhao/jinghuazhao.github.io/blob/master/docs/_posts/2021-02-16-hello-world.md Use the `convert` command from ImageMagick to resize an image. This example resizes 'sunflower.jpg' to 15% of its original size and saves it as 'sun15.jpg'. ```bash convert sunflower.jpg -resize 15% sun15.jpg ```