working on it ...


Explore Public Snippets

Sort by

Found 64k snippets matching: how

    public by micurs  6866061  355  9  18

    Typescript: passing a class member function as parameter to another function

    Typescript introduces the class construct and the concept of member functions. However if you try to pass a instance member function as parameter to another function the binding with the instance is lost. To solve this problem you can use the capability of javascript (and Typescript) to support closures on anonymous function (or lambda expressio
    ///<reference path='../types/node.d.ts'/>
    ///<reference path='../types/underscore.d.ts'/>
    import _ = require("underscore");
    class SomePeople {
      values : string[] = [ 'John', 'Mary', 'Peter'];
      out() {
        _.each( this.values, (v) => process.stdout.write( v + '\n') );
    // This function accept a function it will execute internally
    function outSomething( outFunc : () => any ) {
    var crowd = new SomePeople();
    // This won't work since the actual crowd instance binding will be lost
    outSomething( crowd.out );
    // This will work: the closure within the lambda expression retain the
    // crowd instance and its data
    outSomething( () => crowd.out() );

    public by lbottaro  901650  60  8  1

    How to remove all checked out files in clearcase

    This cleartool command lists all the checkout files (both from the current directory and from the entire view) searching in each directory or vob path. For each element found, it invokes the command to remove the checkout.
    # Remove ALL checked out files from view in the entire vobs
    cleartool lsco -cview -me -avobs -short | xargs cleartool unco -rm 
    # Remove ALL checked out files from the current directory on only
    cleartool lsco -cview -me -rec -short | xargs cleartool unco -rm 

    public by lbottaro  529699  10  8  0

    How to get the list of all the activities comparing two UCM streams in python

    This script shows how to get the list of all the activities comparing two ucm streams. The command returns a list object you can easily loop and print.
    import os
    myView = "MyView"
    diff_act=os.popen("cleartool setview -exec \"cleartool diffbl -nmerge -activities "+bl_old+" "+ bl_new+" \" " +myView).readlines()
    for act in diff_act:
      print ("ACTIVITY: "+str(act))

    public by Justin P  407972  14  3  0

    How to setup notifications FROM Sonarr INTO Slack!!

    How to setup notifications FROM Sonarr INTO Slack!!: Sonarr-SlackNotifications
    Grab the URL for Incoming WebHooks from Slack:
    After you complete that step, it looks a little like this:
    Next create a new bash script with this code:
      curl -X POST --data-urlencode "payload={\"username\": \"Sonarr\", \"icon_emoji\": \":ghost:\", \"text\": \"$sonarr_eventtype: $sonarr_series_title S$sonarr_episodefile_seasonnumber E$sonarr_episodefile_episodenumbers ($sonarr_episodefile_quality)\"}" $1
    I personally have mine on the same drive as my Download Directories, so its all in one place - I use OS X FYI.
    Now set the permissions so it can be executed by everyone, you can modify this if you know what user Sonarr runs under on your system.
      sudo chmod a+x ~/scripts/sonarr/
    Now, go into Sonarr, Settings, "Connect" or the notifications page, and select "Custom Script"
    In the Text Fields:
      Name: <Name your notification>
      Path: <put full path to here>
      Arguments: <put your Slack Webhook URL here>
    as in:
      Name: Slack
      Path: /Volumes/Downloader/slack/scripts/
    Copied and edited liberally from <>

    public by cghersi  369762  4  6  3

    How to prettify a number with thousands or millions

    Prepares a pretty version of the given number, with the ability to match the right plural/singular form for English text
    public static string PaintNumber(int number, string followingText = "", bool numberInBold = false)
      string content = String.Format("{0:N0}", number);
      if (number >= 10000)
        double numberInThousands = number / 1000.0;
        if (numberInThousands < 100)
          content = String.Format("{0:N0}k", numberInThousands);
          content = String.Format("{0:0.#}M", numberInThousands / 1000.0);
      if (number >= 1000000)
        double numberInMillions = number / 1000000.0;
        if (numberInMillions < 100)
          content = String.Format("{0:N0}M", numberInMillions);
          content = String.Format("{0:0.#}B", numberInMillions / 1000.0);
      if (numberInBold)
        content = "<b>" + content + "</b>";
      if (!string.IsNullOrEmpty(followingText))
        content += " " + followingText + (number != 1 ? "s" : "");
      return content;

    public by lbottaro  341352  3  7  1

    How to checkout the latest tag of a Git repository

    This simple bash script allows to automatically checkout your local git repository on the latest tagged version available on the remote repository. The script assumes to be run from your local repo. The command 'git rev-list --tags' lists the tags IDs in reverse chronological order, getting the very last one on top. The command 'git describe
    # Get new tags from the remote
    git fetch --tags
    # Get the latest tag name
    latestTag=$(git describe --tags `git rev-list --tags --max-count=1`)
    # Checkout the latest tag
    git checkout $latestTag  

    public by sukhjinderkahlon  326317  7  5  0

    How to Work with Excel Files Using Apache POI

    This code will work as a utility to read and write excel files using Apache POI Library. 3.13
    import org.apache.poi.hssf.usermodel.HSSFCell;
    import org.apache.poi.hssf.usermodel.HSSFRow;
    import org.apache.poi.hssf.usermodel.HSSFSheet;
    import org.apache.poi.hssf.usermodel.HSSFWorkbook;
    import org.apache.poi.xssf.usermodel.XSSFCell;
    import org.apache.poi.xssf.usermodel.XSSFRow;
    import org.apache.poi.xssf.usermodel.XSSFSheet;
    import org.apache.poi.xssf.usermodel.XSSFWorkbook;
    public class ExcelUtils {
    	private static HSSFSheet ExcelWSheet;
    	private static HSSFWorkbook ExcelWBook;
    	private static HSSFCell Cell;
    	private static HSSFRow Row;
    	private static String filePath;
    	public static void setExcelFile(String Path,String SheetName) throws Exception {
    			try {
       			// Open the Excel file
    			FileInputStream ExcelFile = new FileInputStream(Path);
    			// Access the required test data sheet
    			ExcelWBook = new HSSFWorkbook(ExcelFile);
    			ExcelWSheet = ExcelWBook.getSheet(SheetName);
    			} catch (Exception e){
    				throw (e);
    	//This method is to read the test data from the Excel cell, in this we are passing parameters as Row num and Col num
        public static String getCellData(int RowNum, int ColNum) throws Exception{
      			Cell = ExcelWSheet.getRow(RowNum).getCell(ColNum);
      			String CellData = Cell.getStringCellValue();
      			return CellData;
      			}catch (Exception e){
      //This method is to write in the Excel cell, Row num and Col num are the parameters
    	public static void setCellData(String Result,  int RowNum, int ColNum) throws Exception	{
      			Row  = ExcelWSheet.getRow(RowNum);
    			Cell = Row.getCell(ColNum, Row.RETURN_BLANK_AS_NULL);
    			if (Cell == null) {
    				Cell = Row.createCell(ColNum);
    				} else {
      // Constant variables Test Data path and Test Data file name
      				FileOutputStream fileOut = new FileOutputStream(filePath);
    				}catch(Exception e){
    					throw (e);

    public by PLAT.ONE @ PLAT.ONE  324337  3  6  0

    How to save a custom property on PLAT.ONE, aka to enhance the data model of a device

    Custom properties are key-value pairs associated to an entity in PLAT.ONE. You can attach at runtime those new properties
    import java.util.ArrayList;
    import java.util.List;
    import com.abodata.plat1.nodeInfo.WSNNodeType;
    import com.abodata.plat1.system.ICredentialUtils;
    import com.abodata.plat1.utils.APIFilter;
    import com.abodata.plat1.velocity.client.IPlatoneAPI;
    public class AddCustomPropertyExample {
    	public void addProperty() throws Exception {
    		IPlatoneAPI apiMan = YourServiceActivator.getApiMan();
    		ICredentialUtils creds = YourServiceActivator.getCredentialUtils();
    		//let's retrieve the first available camera:
    		List<APIFilter> filters = new ArrayList<APIFilter>();
    		filters.add(new APIFilter("type", new String[] { WSNNodeType.ENDPOINT.getType() + "", WSNNodeType.ROUTER.getType() + "" }));
    		List<IProxyPhysicalNode> cameras = apiMan.DB_GetVisiblePhysicalNode(null, filters, true, 0, 1);
    		IProxyPhysicalNode camera =	cameras.get(0);
    		//get the current user:
    		IProxyPlatUser curUser = apiMan.DB_GetPlatUser(creds.getUserName(), creds.getPsw());
    		//add a property to the camera:
    		IProxyCustomProperty p = apiMan.DB_AddCustomProperty(creds.getAppGardenId(), "resolution", false, "1280x768", 
    				ProxyObjType.customProperty, curUser.getId(), camera.getId(), ProxyObjType.physNode, CPAllowable.all, 
    		if (p != null)
    			System.out.println("Property added!");
    			System.out.println("Something wrong...");

    public by lbottaro  303310  31  7  0

    How to read and parse a txt file in python

    This code shows how to read a txt file and parse the data
    import os
    import sys
    myfile = open('/some/path/to/file.txt', "r")
    # abc 123 234 456 678
    # def 122223 2333334 454446 611178
    # ghi 144423 211134 44456 61114478
    for line in myfile.readlines():
        name= ''
        numList = list()
        print line
            name = line.split()[0] # it will get 'abc'/'def'/'ghi'
            numList = line.split()[1:] # it will get all other stuff inline...
            print "Invalid file format"
        if not numList:
            print("Invalid numList format! name= " + str(name))
        print 'name='+str(name)
        print 'numList='+str(numList)

    public by lbottaro @ Amazon_AWS_Python_API  304441  0  8  0

    Amazon S3 Aws - How to download a file from a bucket to a target directory

    This code shows how to download a file from an existing bucket invoking the boto python API, saving to a target directory. You need to specify the filename and path where to save the data. [How to create a bucket]( [How to upload a file to a bucket](
    # This downloads the object foobar.pdf and saves it in /home/luca/documents/
    key = bucket.get_key('foobar.pdf')
    • Public Snippets
    • Channels Snippets