working on it ...


Explore Public Snippets

Sort by

Found 8,438 snippets matching: launch

    public by DavidEGrayson modified Aug 2, 2015  1695  1  3  0

    Prototype, non-working MSYS2 launcher I made a while ago that adds custom entries to its taskbar entry so you can right-click on it and use it to launch different versions of MSYS2.

    Prototype, non-working MSYS2 launcher I made a while ago that adds custom entries to its taskbar entry so you can right-click on it and use it to launch different versions of MSYS2.: msys2launcher.cpp
    #define _WIN32_WINNT _WIN32_WINNT_WIN7
    #include <stdio.h>
    #include <unistd.h>
    #include <windows.h>
    #include <propvarutil.h>
    #include <shellapi.h>
    #include <propsys.h>
    #include <propkey.h>
    #include <shobjidl.h>
    #include <objectarray.h>
    wchar_t appId[] = L"davidegrayson/msys2launcher";
    int setAppId(HWND);
    int setupTaskbar(HWND);
    int setupTasks(void);
    int launchMsys2(const char * msystem);
    DWORD wmTaskbarButtonCreated = -1;
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
        LPSTR szCmdLine, int iCmdShow)
        wmTaskbarButtonCreated = RegisterWindowMessage("TaskbarButtonCreated");
        setvbuf(stderr, NULL, _IONBF, 0);
        if(strcmp(szCmdLine, "msys2") == 0)
            return launchMsys2("MSYS2");
        static char appName[] = "testwin32";
        WNDCLASSEX wndclass;
        wndclass.cbSize = sizeof(wndclass); = CS_HREDRAW | CS_VREDRAW;
        wndclass.lpfnWndProc = WndProc;
        wndclass.cbClsExtra = 0;
        wndclass.cbWndExtra = 0;
        wndclass.hInstance = hInstance;
        wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
        wndclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
        wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
        wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
        wndclass.lpszClassName = appName;
        wndclass.lpszMenuName = NULL;
        HWND hwnd = CreateWindow(appName, szCmdLine,
            NULL, NULL, hInstance, NULL);
        ShowWindow(hwnd, iCmdShow);
            MSG msg;
            BOOL bRet = GetMessage(&msg, NULL, 0, 0);
            if (bRet == -1)
                // Error
                fprintf(stderr, "GetMessage returned -1\n");
                return 1;
            else if (bRet == 0)
                // WM_QUIT message
                return msg.wParam;
    int setAppId(HWND hwnd)
        PROPVARIANT pv;
        HRESULT result = InitPropVariantFromString(appId, &pv);
        if (result != S_OK)
            fprintf(stderr, "InitPropVariantFromString error\n");
            return -1;
        IPropertyStore* pps;
        result = SHGetPropertyStoreForWindow(hwnd, IID_PPV_ARGS(&pps));
        if (result != S_OK)
            fprintf(stderr, "SHGetPropertyStoreForWindow failed\n");
            return -1;
        result = pps->SetValue(PKEY_AppUserModel_ID, pv);
        if (result != S_OK)
            fprintf(stderr, "SetValue failed\n");
            return -1;
        result = pps->Commit();
        if (result != S_OK)
            fprintf(stderr, "Commit failed\n");
            return -1;
        return 0;
    LRESULT CALLBACK WndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
        switch (iMsg)
        case WM_CREATE:
            return 0;
        case WM_PAINT:
            PAINTSTRUCT ps;
    	HDC hdc = BeginPaint(hwnd, &ps);
    	TextOut(hdc, 100, 100, "Hello, world!", 13);
    	EndPaint(hwnd, &ps);
    	return 0;
        case WM_DESTROY:
    	return 0;
        if (iMsg == wmTaskbarButtonCreated)
        return DefWindowProc(hwnd, iMsg, wParam, lParam);
    int setupTaskbar(HWND hwnd)
        fprintf(stderr, "Taskbar button created\n");
        ITaskbarList3 * ptl;
        HRESULT result = CoCreateInstance(
            CLSID_TaskbarList, NULL, CLSCTX_ALL,
            IID_ITaskbarList3, (void**)&ptl);
        if (FAILED(result))
            fprintf(stderr, "CoCreateInstance for TaskBarList3 failed\n");
            return 1;
        return 0;
    int setupTasks()
        HRESULT result;
        ICustomDestinationList * cdl;
        result = CoCreateInstance(CLSID_DestinationList, NULL, CLSCTX_ALL, IID_PPV_ARGS(&cdl));
        if (FAILED(result))
            fprintf(stderr, "CoCreateInstance for CustomDestinationList failed.\n");
            return 1;
        result = cdl->SetAppID(appId);
        if (FAILED(result))
            fprintf(stderr, "Setting app ID for CDL failed.\n");
            return 1;
        IObjectArray * removedItems;
        UINT minSlots;
        result = cdl->BeginList(&minSlots, IID_PPV_ARGS(&removedItems));
        if (FAILED(result))
            fprintf(stderr, "BeginList failed\n");
            return 1;
        IObjectCollection * tasks;
        result = CoCreateInstance(CLSID_EnumerableObjectCollection, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&tasks));
        if (FAILED(result))
            fprintf(stderr, "Creating collection failed\n");
            return 1;
            IShellLinkW * shellLink;
            result = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&shellLink));
            if (FAILED(result))
                fprintf(stderr, "Creating a ShellLink failed.\n");
                return 1;
            shellLink->SetDescription(L"Launch the MSYS2 Shell");
            shellLink->SetIconLocation(L"C:\\msys64\\msys2.ico", 0);
            IPropertyStore * propertyStore;
            if (FAILED(shellLink->QueryInterface(&propertyStore)))
                fprintf(stderr, "Converting ShellLink to IPropertyStore failed.\n");
                return 1;
            PROPVARIANT propertyValue;
            InitPropVariantFromString(L"MSYS2 Shell", &propertyValue);
            propertyStore->SetValue(PKEY_Title, propertyValue);
        IObjectArray * tasksArray;
        result = tasks->QueryInterface(&tasksArray);
        if (FAILED(result))
            fprintf(stderr, "Converting to array failed\n");
            return 1;
        result = cdl->AppendCategory(L"Tasks", tasks);
        if (FAILED(result))
            fprintf(stderr, "Appending category failed: %#lx\n", result);
            return 1;
        result = cdl->CommitList();
        if (result != S_OK)
            fprintf(stderr, "CommitList failed\n");
            return 1;
        return 0;
    int launchMsys2(const char * msystem)
        fprintf(stderr, "Launching msys2 shell\n");
        STARTUPINFO startupInfo;
        ZeroMemory(&startupInfo, sizeof(startupInfo));
        startupInfo.cb = sizeof(startupInfo);
        // TODO: fill in startupInfo
        ZeroMemory(&info, sizeof(info));
        BOOL success = SetEnvironmentVariable("MSYSTEM", msystem);
        if (!success)
            fprintf(stderr, "Failed to set MSYSTEM.\n");
            return 0;
        char commandLine[] = "mintty --option AppID=davidegrayson/msys2launcher -i /msys2.ico /usr/bin/bash --login";
        success = CreateProcess(
            NULL,  // lpEnvironment
            NULL,  // lpCurrentDirectory
        if (!success)
            fprintf(stderr, "CreateProcess failed\n");
            return 1;
        return 0;

    public by DennisTerrell modified Jul 23, 2015  432  0  3  0

    Launch Sublime Text 2 from the Mac OS X Terminal

    Launch Sublime Text 2 from the Mac OS X Terminal: launch_sublime_from_terminal.markdown
    # Launch Sublime Text 2 from the Mac OS X Terminal
    Sublime Text 2 ships with a CLI called **subl** (why not "sublime", go figure). This utility is hidden in the following folder (assuming you installed Sublime in `/Applications` like normal folk. If this following line opens Sublime Text for you, then bingo, you're ready.
    `open /Applications/Sublime\ Text\`
    You can find more (official) details about subl here:
    ## Installation
    The official documentation I linked to above recommends creating a ~/bin folder (in your home directory). That's weird, I don't recall ever being asked to do that on OS X since most people install binaries within `/usr/local/bin` which – if you're a developer – is likely to already have tons of other binaries.
    So contrary to the Sublime team recommendation, we're not going to create a `bin` folder in your home directory:
    `ln -s /Applications/Sublime\ Text\ /usr/local/bin/sublime`
    This will simply create a [symlink]( called `sublime` (remember, we like names that don't suck to type 500 times a day) between the `subl` binary stashed in the Sublime application package, and a folder where your system usually looks for binaries to execute (launch). Think of it as a wormhole of awesome.
    Now let's do a check to see if everything will run smoothly. Enter this:
    `open ~/.bash_profile`.
    You should see at the top of the file a line that starts with:
    `export PATH=`
    This contains all the directories that will be looked into for executable binaries when you type a command in Terminal. Since we create a symlink to `subl` called `sublime` in the `/usr/local/bin` directory let's check if this directory is listed on that same line. 
    If it is, perfect. Let's keep going. If not, simply add it like this and save the file:
    `export PATH=/usr/local/bin:(...)`
    Note: The "(...)" in this example represents other folders that would be listed on the same line and separated by a colon.
    If you had to add `/usr/local/bin` to your PATH, run the following command before continuing:
    `source ~/.bash_profile`
    This will reload your `.bash_profile` with the newly added directory.
    ## Testing
    Open a Terminal window and run:
    `sublime filename` (replace "filename" by an actual file name)
    `sublime foldername` (replace "foldername" by an actual folder name)
    or even
    `sublime .` (to open the entire current directory)
    ## Conclusion
    Now you don't need to get out of Terminal to simply open a file or a folder, you didn't have to add an "alias" or yet another bin directory to your `.bash_profile` which you would have needed with the official instructions given by the Sublime team.
    Have fun, Sublime is a great editor showing a lot of promise.

    public by PBMCube modified Jan 10, 2019  76  0  3  1

    Global Game Object

    Assigning a global namespace variable with delegation into Phaser.Game
    var game = new Phaser.Game(config);

    public by mporru modified Feb 18, 2013  2422  1  6  0

    Batch: save current path then move to the local path of the launched file

    Example: I'm here: C:\bar\ I launch C:\test\foo.bat (either with the full path or double clicking on the batch file). This batch file is made as below. This script will do the following: 1) save the current path 2) change directory to C:\test 3) execute the commands 4) go back to C:\bar\ before quitting
    :: save current path
    pushd .
    cd /d %~dp0
    REM put here the commands...
    :: restore original path

    public by qxshower modified Apr 24, 2015  1770  0  6  0


    Goes to the given URL
    using System;
    using System.Collections.Generic;
    using EnvDTE;
    using Microsoft.Win32;
    using System.Windows.Forms;
    using Microsoft.VisualStudio.Shell.Interop;
    public static void LaunchUrl(string url)
        var dte = SqlCeToolboxPackage.GetGlobalService(typeof(EnvDTE.DTE)) as EnvDTE.DTE;
        if (dte != null)
            dte.ItemOperations.Navigate(url, vsNavigateOptions.vsNavigateOptionsDefault);

    public by pradithya modified Dec 9, 2017  558  1  4  0

    Launching Image Picker

    self.present(UIImagePickerController(), animated:true, completion: nil);

    public by pradithya modified Dec 9, 2017  369  1  4  0

    Launching Activity View Controller

    let image = UIImage()
    let viewController = UIActivityViewController(activityItems:[image], applicationActivities: nil)
    self.present(viewController, animated:true, completion: nil);

    public by lbottaro modified Sep 4, 2013  3373  4  6  0

    Basic code to manage threading in python

    This simple example shows how to launch N threads in parallel and handle their execution. Please note the object Thread, where you can define the method to be executed and parameter to be passed. The main program will launch threads and wait for all to complete before continuing execution.
    import datetime
    import threading
    from threading import Thread
    my_data_List = ["abc", "123", "bar", "foo"]
    for data in my_data_List:
          print "Going to start thread for data = " + data
          t = Thread(target=methodToRunInParallel, args=(data,))
          #Join all existing threads to main thread.
          for thread in threading.enumerate():
              if thread is not threading.currentThread():
          print "Completed!"
    def methodToRunInParallel(data):
         print "Working on data = " + data
         #Do some stuff here...

    public by cghersi modified May 12, 2014  3178  1  6  1

    Test harness for Multithread lock management strategies

    This test suite provides a simple way to check the performances of locks vs. synchronized syntax in case of multithread safe run of a task. The parameters are added as static variable at the top of the class, MAX_LOOPS is the number of times the task is performed, and MAX_SET_SIZE is the number of simultaneous threads launched and insisting on th
    import java.util.ArrayList;
    import java.util.List;
    import java.util.concurrent.ArrayBlockingQueue;
    import java.util.concurrent.locks.ReentrantLock;
    public class SafeLocks {
    	private static int MAX_LOOPS = 1000;
    	private static int MAX_SET_SIZE = 10000;
    	 * @param args
    	public static void main(String[] args) {
    		System.out.println("Starting ReentrantLock test bench at " + System.currentTimeMillis());
    		TestSuite suite1 = new ReentrantlockEx();
    		System.out.println("Starting Synchronized test bench at " + System.currentTimeMillis());
    		TestSuite suite2 = new SynchronizedEx();
    	private static void testBench(final TestSuite test) {
    		for (int thIdx = 0; thIdx < MAX_SET_SIZE; thIdx++) {
    			Thread t = new Thread(new Runnable() {			
    				public void run() {
    					long summedSpentTime = 0;
    					for (int i = 0; i < MAX_LOOPS; i++) {
    						long startTime = System.currentTimeMillis();
    						summedSpentTime += (System.currentTimeMillis() - startTime);
    		while (test.threadsFinished() < MAX_SET_SIZE) {
    			try {
    			} catch (InterruptedException e) {
    		List<Long> times = test.getTimes();
    		long totalTime = 0;
    		for (long l : times) {
    			totalTime += l;
    		System.out.println("Suite finished: # of threads: " + MAX_SET_SIZE + "; # of running cycles of single task: " + 
    				MAX_LOOPS + "; avg time is " + (totalTime / times.size()));
    	public static abstract class TestSuiteImpl implements TestSuite {
    		private ArrayBlockingQueue<Long> runTimes = new ArrayBlockingQueue<Long>(MAX_SET_SIZE + 1);
    		public void addTime(long time) {
    		public List<Long> getTimes() {
    			List<Long> res = new ArrayList<>();
    			return res;
    		public int threadsFinished() {
    			return runTimes.size();
    	public static class ReentrantlockEx extends TestSuiteImpl implements TestSuite {
    		private ReentrantLock lock = new ReentrantLock();
    		public final boolean doStuff(int number) {
    			boolean result = false;
    			//do something not completely stupid so that compiler will not get rid of it
    			String test = "abc0";
    			result = (test.hashCode() == number);
    			return result;
    	public static class SynchronizedEx extends TestSuiteImpl implements TestSuite {
    		private final Object syncObj = new Object();
    		public final boolean doStuff(int number) {
    			boolean result = false;
    			synchronized (syncObj) {
    				//do something not completely stupid so that compiler will not get rid of it
    				String test = "abc0";
    				result = (test.hashCode() == number);
    			return result;
    	public static interface TestSuite {
    		public boolean doStuff(int number);
    		public void addTime(long time);
    		public List<Long> getTimes();
    		public int threadsFinished();

    public by cghersi modified Sep 23, 2013  2758  0  5  0

    Autorestart JVM on OutOfMemoryError

    Applying this VM arg enable the capability to launch a script when OutOfMemory error occurs. Hey, remeber to fix the issue, anyway!! :)
    • Public Snippets
    • Channels Snippets