working on it ...


Explore Public Snippets

Sort by

Found 30k snippets matching: files

    public by lbottaro modified May 2, 2013  899711  41  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 antlong modified Aug 10, 2015  488587  10  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.
          python filename.pdf
          All extracted images will be saved to the directory 
          the script is initialized in.
            pdf = file(sys.argv[1], "rb").read()
        except Exception:
            print "Usage: `python filename.pdf`"
        startmark, endmark = "\xff\xd8", "\xff\xd9"
        startfix, endfix, i, njpg = 0, 2, 0, 0
        while True:
            istream = pdf.find("stream", i)
            if istream < 0:
            istart = pdf.find(startmark, istream, istream+20)
            if istart < 0:
                i = istream+20
            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:
            njpg += 1
            i = iend
        print "Extracted %s JPG files." % njpg

    public by sukhjinderkahlon modified Mar 9, 2016  325907  6  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 Drowze modified Nov 3, 2015  279255  1  3  0

    Compress all files in a folder into individual 7z files

    Compress all files in a folder into individual 7z files: Compress_individual_files.txt
    FOR %i IN (*.*) DO 7z.exe a -m0=LZMA2 -mmt=x "%~ni.7z" "%i"
    where x = number of cores

    public by mporru @ Amazon_AWS_PHP_API modified Jul 23, 2013  320196  0  5  0

    Amazon AWS - PHP: Generate signed expiring download URL

    This snippet demonstrates how to generate a download URL for a file stored in your S3 Bucket. This will work for all files, even ACL private files. Download URL will be active for the specified time. In order to use this service you must enable Amazon Simple Storage Service (Amazon S3) in your account.
    $s3 = new AmazonS3();
    $fileName = 'test1.txt';
    $bucketName = 'myBucketName';
    $url = $s3->get_object_url($bucketName, $fileName, '1 hour');
    echo("Download url: <a href=\"$url\">$url</a>\n");

    public by Charles Peter Nystrom modified Feb 19, 2016  201496  2  3  0

    Replace string in all files within the current directory. - PowerShell

    Replace string in all files within the current directory. - PowerShell: gistfile1.txt
    $stringToReplace = "foo"
    $replaceWith = "bar"
    Get-ChildItem | ForEach-Object{ $pathToFile = $_.FullName; (get-content $pathToFile) | % { $_ -replace $stringToReplace, $replaceWith } | set-content $pathToFile }

    public by strykerraven modified Sep 22, 2016  187928  3  5  1

    WordPress safely defining and executing functions

    Handy safe way to include functions in your WordPress Themes functions.php file. This is even more useful if you are using a child theme and don't want to conflict with functions already defined by the parent theme. Even better; These functions can be executed within the same if(function_exists()) block that defines them creating a neater to manage
    // Lets get rid of the versioning on static .js and .css files.
    // It looks tacky anyway for static files.
    	 * Strips Version query strings
    	 * @param type $src
    	 * @return type
    	if(!function_exists('remove_css_js_versions')){ // if the function doesnt exist then...
    		function remove_css_js_versions($src){ // define the function
    			return remove_query_arg('ver', $src); // call built-in wordpress function to remove query named "ver" from whatever is passed as $src
    		add_filter('script_loader_src', 'remove_css_js_versions'); // Pass a hook as $src for js to function listed above named "remove_css_js_versions"
    		add_filter('style_loader_src', 'remove_css_js_versions'); // Pass a hook as $src for css to function listed above named "remove_css_js_versions"
    	} // All scripts and styles will be filtered to have ?ver=1.2.3 stripped from urls. Function defined and executed in same if() statement.
      * Need to debug? Instead of just using print_r($array) you just do preprint_r($array)
      * the array will be output neatly instead of wrapped and messy.
    		function preprint_r($val){
    			echo '<pre>' . PHP_EOL;
    			print_r($val) . PHP_EOL;
    			echo '</pre>' . PHP_EOL;
    	/** Remove the WP Icon (Menu) from profile and admin pages. */
      		function remove_wp_logo($wp_admin_bar){
      		add_action('admin_bar_menu', 'remove_wp_logo', 33);
    	 * Wordpress Login Page fixes. By default WordPress shows its logo on your login pages and links to its own site.
    	 * A visitor logging into your site don't need this potential roadblock so lets show WordPress that we mean business!
    	# Fix Login Page WordPress URL
    		function fix_wp_login_img_url($url){
    			return get_bloginfo('url');
    		add_filter('login_headerurl', 'fix_wp_login_img_url');
    	# Fix Login Page WordPress Title (Text displayed on hover defaults to Powered By WordPress)
    		function fix_wp_login_img_title($title){
    			return get_bloginfo('description');
    		add_filter('login_headertitle', 'fix_wp_login_img_title');
    		Change Login Page WordPress Logo, You will need to update path and point to a valid image.
    		WordPress adds this with a CSS background image for your anchor link. It first applys a PNG and then a SVG override if your browser is modern and supports svg
    		In your themes custom stylesheet you can change default Wordpress image by supplying a new background image:
    		.login h1 a {
    			background-image: none,url(images/your_image.png);
    		Hint: WordPress uses an 64x64 image but you can adapt size to your need. You might want to use SVG like WordPress did because it will scale best at any resolution.
    	 * Simple Actions that use wp_head hook to cleanup WP header Junk/Bloat
    	 * that is included with WordPress by default.
    	remove_action('wp_head', 'wp_generator');
    	remove_action('wp_head', 'rsd_link');
    	remove_action('wp_head', 'wlwmanifest_link');
    	remove_action('wp_head', 'wp_shortlink_wp_head');            

    public by sherazam modified Jun 8, 2016  182061  1  5  0

    How to Delete Messages in Bulk or One by One from Outlook PST in .NET Apps

    This technical tip explains how .NET developers can Delete Messages from outlook PST. Add Messages to PST Files showed how to add messages to PST files. It is, of course, also possible to delete items (contents) from a PST file and it may also be desirable to delete messages in bulk. Items from a PST file can be deleted using the FolderInfo.DeleteC
    // Enter here the actual content of the snippet.            
    //Deleting Messages from PST Files
    //The code snippets below delete messages from a PST file's Sent subfolder.
    //[C# Code Sample]
    // Get the Sent items folder
    FolderInfo folderInfo = pst.GetPredefinedFolder(StandardIpmFolder.SentItems);
    MessageInfoCollection msgInfoColl = folderInfo.GetContents();
    foreach (MessageInfo msgInfo in msgInfoColl)
        Console.WriteLine(msgInfo.Subject + ": " + msgInfo.EntryIdString);
        if (msgInfo.Subject.Equals("some delete condition") == true)
            // Delete this item
            Console.WriteLine("Deleted this message");
    //[VB.NET Code Sample]
    ' Get the Sent items folder
    Dim folderInfo As FolderInfo = pst.GetPredefinedFolder(StandardIpmFolder.SentItems)
    Dim msgInfoColl As MessageInfoCollection = folderInfo.GetContents()
    For Each msgInfo As MessageInfo In msgInfoColl
    	Console.WriteLine(msgInfo.Subject & ": " & msgInfo.EntryIdString)
    	If msgInfo.Subject.Equals("some delete condition") = True Then
    		' Delete this item
    		Console.WriteLine("Deleted this message")
    	End If
    Next msgInfo
    //Delete Items in Bulk from PST File
    //Aspose.Email API can be used to delete items in bulk from a PST file. This is achieved using the DeleteChildItems method which accepts a list of Entry ID items referring to the items to be deleted.
    //[C# Code Sample]
    using (PersonalStorage pst = PersonalStorage.FromFile(@"test.pst"))
        FolderInfo inbox = pst.RootFolder.GetSubFolder("Inbox");
        // find messages having From = "" 
        PersonalStorageQueryBuilder queryBuilder = new PersonalStorageQueryBuilder();
        MessageInfoCollection messages = inbox.GetContents(queryBuilder.GetQuery());
        IList<string> deleteList = new List<string>();
        foreach (MessageInfo messageInfo in messages)
        // delete messages having From = ""
    //[VB.NET Code Sample]
    Using pst As PersonalStorage = PersonalStorage.FromFile("test.pst")
    	Dim inbox As FolderInfo = pst.RootFolder.GetSubFolder("Inbox")
    	' find messages having From = "" 
    	Dim queryBuilder As New PersonalStorageQueryBuilder()
    	Dim messages As MessageInfoCollection = inbox.GetContents(queryBuilder.GetQuery())
    	Dim deleteList As IList(Of String) = New List(Of String)()
    	For Each messageInfo As MessageInfo In messages
    	' delete messages having From = ""
    End Using

    public by DanielOgbuagu modified Jun 28, 2015  201418  1  5  0

    Adding a *.jar file (originating from java-wrapped C++ code) to an SBT project classpath

    I thought using unmanaged dependencies in SBT projects was simply dropping a jar file into the lib directory, until I bought an SDK for a biometric device. Both the C++ and the Java packages were provided. I opted for the Java package, copying the provided jar file and the JNI (*.so) files into the appropriate locations and configuring the ja
     * In my <code>build.sbt</code> file, I appended a blank line and then the following:
    libraryDependencies += "groupID" % "artifactId" % "revision" from "file:///home/Danogbuagu/Projects/biometric-lib/filename.jar"
    // where,
    // groupID for example is like: com.zigzagcompany 
    // artifactId for example is like: zigzag
    // revision for example is like: 1.3.4
    // Remember the line befor the code and that after.

    public by lbottaro modified Oct 30, 2013  13671  43  8  0

    How to list files changed in clearcase ucm stream activities

    This script lists the files changed in all the activities delivered on a specific stream, with no duplicates. The stream is the one currently set on the clearcase view.
    #!/usr/bin/tcsh -f
    # This script lists the activities of a stream and saves on the following file the changed files without duplicates.
    set tmpoutput = "$HOME/.tmp_AllChangedFilesInStream.txt"
    set output = "$HOME/AllChangedFilesInStream.txt"
    rm -rf $tmpoutput
    touch $tmpoutput
    rm -rf $output
    touch $output
    foreach act ( `cleartool lsact -s | grep -v rebase` )	
        set changeset = `cleartool lsact -fmt "%[versions]p" $act`
        echo $changeset | tr ' ' '\n' >> $tmpoutput
    foreach line ( "`cat $tmpoutput`" )	
        set file=`echo $line | sed -e "s|\(.*\)@@.*|\1|"`
        set isPresent = `grep "$file" "$output"`
        if ("$isPresent" == "") then
          echo $file >> $output
    rm -rf $tmpoutput
    exit 0
    • Public Snippets
    • Channels Snippets