working on it ...

Filters

Explore Public Snippets

Sort by

Found 3,234 snippets matching: command-line

    public by antlong  489245  15  7  1

    Extract JPG images from a PDF

    A command line tool to extract jpg images from pdf files.
    #!/usr/bin/env python
    import sys
    
    
    def main():
        """Extract JPG's from PSD's.
        
        Usage:
          python extract.py filename.pdf
        
        Note:
          All extracted images will be saved to the directory 
          the script is initialized in.
        """
        try:
            pdf = file(sys.argv[1], "rb").read()
        except Exception:
            print "Usage: `python extract.py filename.pdf`"
            return
    
        startmark, endmark = "\xff\xd8", "\xff\xd9"
        startfix, endfix, i, njpg = 0, 2, 0, 0
    
        while True:
            istream = pdf.find("stream", i)
            if istream < 0:
                break
            istart = pdf.find(startmark, istream, istream+20)
            if istart < 0:
                i = istream+20
                continue
            iend = pdf.find("endstream", istart)
            if iend < 0:
                raise Exception("Couldn't find end of stream.")
            iend = pdf.find(endmark, iend-20)
            if iend < 0:
                raise Exception("Couldn't find end of JPG.")
         
            istart += startfix
            iend += endfix
            jpg = pdf[istart:iend]
            with open("jpg%d.jpg" % njpg, "wb") as _f:
                _f.write(jpg)
            njpg += 1
            i = iend
    
        print "Extracted %s JPG files." % njpg
    
    main()
    

    public by lbottaro  21684  353  8  0

    How to programmatically convert the Visual Studio coverage file to coveragexml by command line tool in csharp

    This code shows how to programmatically export and convert the coverage data ( .coverage) generated by Visual Studio into a readable xml file (.coveragexml). The xml file can be used to generated a code coverage report, eg using the ReportGenerator tool. The conversion is done using the CoverageInfo and CoverageDS objects and invoking the metho
    using Microsoft.VisualStudio.Coverage.Analysis;
    
    namespace CodeCoverageConverter
    {
        class Program
        {
            static void Main(string[] args)
            {
                if (args == null || args.Length != 3 || args[0] == null || args[1] == null ||  args[2] == null ||
                    string.IsNullOrEmpty(args[0]) || string.IsNullOrEmpty(args[1]) || string.IsNullOrEmpty(args[2]))
                {
                    help();
                    return;
                }
                string coverageFileName = args[0];
                string dllFileName = args[1];
                string coverageXmlFileName = args[2];
                Console.WriteLine("args[0] = " + coverageFileName);
                Console.WriteLine("args[1] = " + dllFileName);
                Console.WriteLine("args[2] = " + coverageXmlFileName);
    
                using (CoverageInfo info = CoverageInfo.CreateFromFile(coverageFileName, new string[] { dllFileName }, new string[] { }))
                {
                    CoverageDS data = info.BuildDataSet();
    
                    data.WriteXml(coverageXmlFileName);
                }
            }
    
            static private void help()
            {
                Console.WriteLine("Help!");
                Console.Write(@"
                    Arguments
                        Args[0]: data coverage file name (data.coverage)
                        Args[1]: DLL to use (myProject.dll)
                        Args[2]: coveragexml file name to be generated (converted.coveragexml)
                     ");
    
            }
    
        }
    }

    public by fromano  1878  0  5  1

    Redirect a yarp read to a yarp write while filtering the data

    cut -c 5- will remove all the lines from 1 to 5 tr -d 'characters' will remove all the listed characters By piping the yarp read to the yarp write it is possible to "clean" the input format
    # Enter here the actual content of the snippet.            
    
    yarp read ... /wholeBodyDynamicsTree/floatingbasestate:o | cut -c 5- | tr -d '()' | yarp write /wbd3/clean:o
    
    

    public by lbottaro  7102  1  7  3

    Linux one liner bash code to detect file or directory from a given list

    This bash code shows how to detect if a given item in a list returned by a command is actually a file or a directory, without affecting the output format. In this case, xargs is used to pass the '{}' reference to a shell script executed for each line returned by the tree command.
    tree -if --noreport /home/ | xargs -I '{}' sh -c 'if [ -d {} ]; then echo "Dir {}"; else echo "File {}"; fi'  

    public by tearfularcher2011  32485  0  3  0

    Install GNU programs on OS X https://www.topbug.net/blog/2013/04/14/install-and-use-gnu-command-line-tools-in-mac-os-x/

    Install GNU programs on OS X https://www.topbug.net/blog/2013/04/14/install-and-use-gnu-command-line-tools-in-mac-os-x/: homebrew-install-gnu.sh
    # see https://www.topbug.net/blog/2013/04/14/install-and-use-gnu-command-line-tools-in-mac-os-x/
    
    # core
    brew install coreutils
    
    # key commands
    brew install binutils
    brew install diffutils
    brew install ed --default-names
    brew install findutils --with-default-names
    brew install gawk
    brew install gnu-indent --with-default-names
    brew install gnu-sed --with-default-names
    brew install gnu-tar --with-default-names
    brew install gnu-which --with-default-names
    brew install gnutls
    brew install grep --with-default-names
    brew install gzip
    brew install screen
    brew install watch
    brew install wdiff --with-gettext
    brew install wget
    
    # OS X ships a GNU version, but too old
    brew install bash
    brew install emacs
    brew install gdb  # gdb requires further actions to make it work. See `brew info gdb`.
    brew install gpatch
    brew install m4
    brew install make
    brew install nano
    
    # Other commands (non-GNU)
    brew install file-formula
    brew install git
    brew install less
    brew install openssh
    brew install perl518   # must run "brew tap homebrew/versions" first!
    brew install python
    brew install rsync
    brew install svn
    brew install unzip
    brew install vim --override-system-vi
    brew install macvim --override-system-vim --custom-system-icons
    brew install zsh
    
    

    public by lbottaro  2360  3  6  1

    Get the url that a local git repo was originally cloned from

    Once a repo is cloned, this snippet shows how to list the url path a local git repository was originally cloned from.
    C:\Users\testRepo>git remote show origin
    
    * Output
    * remote origin   
      Fetch URL: git@github.com:/git/repo/path/testRepo.git  
      Push  URL: git@github.com:/git/repo/path/testRepo.git  
      HEAD branch: master
      Remote branches:                        

    public by lbottaro  7230  31  8  0

    Custom diff tool for clearcase object

    This simple tcsh script allows to run a custom diff tool to view differences between file versions. The diff tool to be used can be easily configured. In this example I use kdiff3. The script will detect if one or two file paths are passed on the command line. In case of two files, the diff will be done on them. In case of one file, th
    #!/bin/tcsh -e
    set _CLEARCASE_VIEW = `cleartool pwv -short -setview`
    echo Set view: "$_CLEARCASE_VIEW"
    set my_firstversion = ""
    set my_secondversion = ""
    set my_difftool = kdiff3
    
    # check clearcase view
    if ( "$_CLEARCASE_VIEW" == "** NONE **" ) then
      echo "Error: ClearCase view not set, aborted."
      exit -1
    endif
    
    if ( "$1" == "" ) then
      echo "Error: missing 1st file argument!"
      echo "Eg: `basename $0` file1.txt -> This will diff file1.txt with its previous version"
      echo "Eg: `basename $0` file1.txt file2.txt -> This will diff file1.txt and file2.txt"
      exit -1
    endif  
    
    set my_firstversion = "$1"
    echo "my_firstversion=$my_firstversion"
    
    if ( "$2" == "" ) then
      echo "No 2nd file passed, calculating previous version of $my_firstversion"
      set my_secondversion = $my_firstversion@@`cleartool descr -pred -short $my_firstversion`
    else
      echo "Setting 2nd file to $2"
      set my_secondversion = "$2"
    endif
    echo "my_secondversion=$my_secondversion"
    
    ${my_difftool} ${my_firstversion} ${my_secondversion} &

    public by lbottaro  2169  0  8  0

    How to check the presence of argv parameter in python

    This script checks the parameters passed via command line. If the parameter is present a check on its value and cast are performed. The script handles exception as well.
    #!/usr/bin/python
    
    import sys
    
    # ------------------------------- Main program -------------------------------
    
    # The default value for command line argv parameter
    default_size = 70
    actual_value = default_size
    
    if (len(sys.argv) > 1):
        try:
            if(int(sys.argv[1]) > 0):
                actual_value = int(sys.argv[1])
                print "Actual size: " + str(actual_value)
            else:
                print("Please specify only positive integer as parameter! " + str(sys.argv[1]))
                print("Actual size set with default value: " + str(actual_value))
        except Exception:
            print("Ouch!... Please review the parameter! " + str(sys.argv[1]))
            sys.exit(-1)
    
    

    public by cghersi  2886  0  6  0

    How to copy a folder and its content in BATCH

    This is the command line used to copy an entire folder named "mySourceDir" into "myDestDir". /i option means "If Source is a directory or contains wildcards and Destination does not exist, xcopy assumes destination specifies a directory name and creates a new directory. Then, xcopy copies all specified files into the new directory. By default, xco
    xcopy F:\mySourceDir C:\myDestDir /E /i /y

    public by JKCPR  3124  2  7  6

    Gulp 'production pipeline' by gulpFile.js

    Tasks are executed concurrently hence the need to establish dependancy of tasks so the CONCATSCRIPTS task can complete before the MINIFYSCRIPTS task begins and COMPILESASS will run in parallel during BUILD task which is executed in the ANON_CALLBACK function copying all the output production ready files into the 'dist' folder as per the DEFAULT ta
    "use strict";
    //BASIC GULP REQUIREMENTS FROM NPM
     var gulp = require('gulp'),
         concat = require('gulp-concat'),
         uglify = require('gulp-uglify'),
         rename = require('gulp-rename'),
         sass = require('gulp-sass'),
         maps = require('gulp-sourcemaps'),
         del = require('del');
    
    
    //USAGE :     gulp concatScripts   -- makes single app.js file
         gulp.task("concatScripts", function() {
         	return gulp.src([   //return is being used because this task is a dependancy of minifyScripts
         		  'js/jquery.js',
             	'js/sticky/jquery.sticky.js',
          		'js/main.js'])
         	  .pipe(maps.init())        //makes the browser able to show which js file contains the js error after compiled.
          	.pipe(concat("app.js"))
          	.pipe(maps.write("./"))
          	.pipe(gulp.dest("js"));
         });
    
    //USAGE :     gulp minifyScripts   -- minifies app.js file && renames to app.min.js
         gulp.task("minifyScripts", ["concatScipts"] ,function(){
    	return gulp.src("js/app.js")
         		.pipe(uglify())
         		.pipe(rename('app.min.js'))
         		.pipe(gulp.dest('js'));
         });
    
    //USAGE :    gulp compileSass     -- compiles all Sass files imported by scss/application.scss && maps the source files && writes their routes relative to base folder hereby (./scss/) && outputs into 'css' folder
         gulp.task("compileSass",function(){
         	return gulp.src("scss/application.scss")
         		.pipe(maps.init())  //makes the browser able to show which scss file contains the css style after compiled.
         		.pipe(sass())
         		.pipe(maps.write("./"))
         		.pipe(gulp.dest('css'));
         });
    
    //USAGE: gulp build --Runs all tasks listed in array below in sequence provided
    //NOTE:  'concatScripts' isnt listed in build task because its already listed as a dependancy of minifyScripts i.e it must finish before minifySCripts can start.
         gulp.task( "build" , [ 'minifyScripts' , 'compileSass' ] , function(){
         	return gulp.src(["css/application.css" , "js/app.min.js" , "index.html"  , "img/**", "fonts/**" ] , { base: './' }) // all the production files
         		.pipe(gulp.dest('dist')); // get piped to 'dist' folder once build tasks have run. READY TO UPLOAD TO PRODUCTION SERVER.
         	});
    
    //USAGE: gulp watchSass         --This automatically compiles your scss files upon changes
         gulp.task('watchSass', function(){
         	gulp.watch( [ 'scss/**/*.scss' , 'scss/*.scss' ], ['compileSass'] ); // Provide either an array of files locations or alternatively GLOBBING PATTERNS...
         });
    
    //USAGE gulp clean    	--This automatically removes old 'dist' and processed OUTPUT files so that BUILD will have a clean space to write them in the default task's anon callback fn
         gulp.task('clean', function(){
         	del(['dist' , 'css/application.css*' , 'js/app*.js*']);
         });
    
    //DEFAULT GULP TASK TO RUN
    //USAGE:  essentially just GULP to trigger workflow pipeline.
         gulp.task("default", ["clean"] , function(){
         	gulp.start('build');
         	console.log("The default task has been executed !! :) ");
         });
         //========================================================================//
         //						GULP TASK PIPELINE:
         //========================================================================//
         //	|> DEFAULT task
         //		|_CLEAN task
         //		|_ANONYMOUS CALLBACK FN
         //			|_BUILD task
         //			 	|_MINIFYSCRIPTS task
         //			 	|	|_CONCATSCRIPTS task
         //			 	|_COMPILESASS task
         //========================================================================//
         /*
         Tasks are executed concurrently hence the need to establish dependancy of tasks so the CONCATSCRIPTS task
         can complete before the MINIFYSCRIPTS task begins and COMPILESASS will run in parallel during BUILD task
         which is executed in the ANON_CALLBACK function copying all the output production ready files into the 
         'dist' folder as per the DEFAULT task. 
          Everything is run by using :  GULP
    
         ___Required Folder Structure:
         	|>    css
              	|>    dist
              	|>    fonts
              	|>    img
              	|>    js
              	|>    node_modules
              	|>    scss
    
         ___Required Node Modules:
         	|>    gulp
         	|>    gulp-concat
         	|>    gulp-uglify
         	|>    gulp-rename
         	|>    gulp-sass
         	|>    gulp-sourcemaps
         	|>    del
    
         */   
    • Public Snippets
    • Channels Snippets