working on it ...


Explore Public Snippets

Sort by

Found 78k snippets matching: file

    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 sTiLL-iLL modified Dec 27, 2014  307436  0  5  14

    my nonblocking, threadsafe file writer/appender for nodejs. works great with clustered servers, and child processes that write to shared or static file-stores

    my nonblocking, threadsafe file writer/appender for nodejs. works great with clustered servers, and child processes that write to shared or static file-stores: scribbles.js
    // scribbles.js a nonblocking, threadsafe file writer/appender for nodejs
    var fs = require('fs'),
    	pth = require('path'),
    	cueMngr = {};
    function Scribbles(fileNm) {
    	this.handle = fileNm;
    	this.canWrite = false;
    	this.actionsRoster = [];
    var scribbles = Scribbles.prototype;
    scribbles.action = function (err, dta, actionCue) {
    	if (err) {
    		throw err;
    	return actionCue();
    scribbles.assign = function (func) {
    	this.action = func;
    	return this;
    scribbles.scribble = function (dta, func) {
    	if (this.canWrite) {
    		this.actionCue = dta;
    		if (func) {
    	else {
    		this.canWrite = true;
    		var slf = this,
    			taskProxy = {};
    		fs.appendFile(this.handle, dta, function (err) {
    			function actionCue() {
    				slf.canWrite = false;
    				if (slf.actionCue) {
    					var dta = slf.actionCue;
    					slf.actionCue = null;
    			slf.action(err, dta, actionCue);
    			while (taskProxy = slf.actionsRoster.shift()) {
    				return taskProxy(err);
    			if (func) {
    				return func(err);
    	return this;
    module.exports = function (fil) {
    	var nm = pth.resolve(fil);
    	return (cueMngr[nm] = cueMngr[nm] || new Scribbles(fil));

    public by lbottaro modified Sep 10, 2013  302847  30  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 modified Aug 1, 2013  303773  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 by cghersi modified Jan 10, 2017  289503  1  8  0

    How to read a file into a string in Java

    This simple snippet reads a file and put the content into a returned string
    private static String readFileAsString(String filePath) throws{
    	StringBuffer fileData = new StringBuffer(1000);
    	BufferedReader reader = new BufferedReader(new FileReader(filePath));
    	char[] buf = new char[1024];
    	int numRead=0;
    	while(( != -1){
    		String readData = String.valueOf(buf, 0, numRead);
    		buf = new char[1024];
    	return fileData.toString();

    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 cghersi modified Jul 27, 2013  338410  1  6  0

    ASP.NET Performance monitors

    The following XML file can be used to create a new user defined Data Collector Set in the Performance Monitor Tool for Windows servers. It checks the most important performance counters for the right execution of ASP.NET Web applications. The performance counters taken into account are those reported in this article:
    <?xml version="1.0" encoding="UTF-16"?>
    	<Description>Genera un rapporto con informazioni dettagliate sullo stato delle risorse hardware locali, sui tempi di risposta del sistema e sui processi eseguiti nel computer locale. Tali informazioni consentono di identificare le possibili cause dei problemi di prestazioni. Per eseguire questo Insieme agenti di raccolta dati, è necessario essere almeno membri del gruppo Administrators locale o di un gruppo equivalente.</Description>
    	<DescriptionUnresolved>Genera un rapporto con informazioni dettagliate sullo stato delle risorse hardware locali, sui tempi di risposta del sistema e sui processi eseguiti nel computer locale. Tali informazioni consentono di identificare le possibili cause dei problemi di prestazioni. Per eseguire questo Insieme agenti di raccolta dati, è necessario essere almeno membri del gruppo Administrators locale o di un gruppo equivalente.</DescriptionUnresolved>
    		<Name>NT Kernel</Name>
    		<SessionName>NT Kernel Logger</SessionName>
    				<Description>Gli eventi fino a questo livello sono attivati</Description>
    				<Description>Gli eventi con almeno una delle parole chiave specificate sono attivati</Description>
    				<Description>Gli eventi con tutte le parole chiave specificate sono attivati</Description>
    				<Description>I campi dati aggiuntivi specificati verranno raccolti con ogni evento</Description>
    		<Name>Performance Counter</Name>
    		<FileName>Performance Counter</FileName>
    		<LatestOutputLocation>C:\PerfLogs\Admin\ASP.NET\ZIOJ-PC_20130727-000002\Performance Counter20130727.csv</LatestOutputLocation>
    		<Counter>\ASP.NET Apps v4.0.30319(__Total__)\% Managed Processor Time (estimated)</Counter>
    		<Counter>\ASP.NET Apps v4.0.30319(__Total__)\Viewstate MAC Validation Failure</Counter>
    		<Counter>\ASP.NET Apps v4.0.30319(__Total__)\Errors During Compilation</Counter>
    		<Counter>\ASP.NET Apps v4.0.30319(__Total__)\Errors During Execution</Counter>
    		<Counter>\ASP.NET Apps v4.0.30319(__Total__)\Errors During Preprocessing</Counter>
    		<Counter>\ASP.NET Apps v4.0.30319(__Total__)\Errors Unhandled During Execution</Counter>
    		<Counter>\ASP.NET Apps v4.0.30319(__Total__)\Errors Unhandled During Execution/Sec</Counter>
    		<Counter>\ASP.NET Apps v4.0.30319(__Total__)\Audit Failure Events Raised</Counter>
    		<Counter>\ASP.NET Apps v4.0.30319(__Total__)\Error Events Raised</Counter>
    		<Counter>\ASP.NET Apps v4.0.30319(__Total__)\Error Events Raised/Sec</Counter>
    		<Counter>\ASP.NET Apps v4.0.30319(__Total__)\Infrastructure Error Events Raised</Counter>
    		<Counter>\ASP.NET Apps v4.0.30319(__Total__)\Infrastructure Error Events Raised/Sec</Counter>
    		<Counter>\ASP.NET Apps v4.0.30319(__Total__)\Request Error Events Raised</Counter>
    		<Counter>\ASP.NET Apps v4.0.30319(__Total__)\Request Error Events Raised/Sec</Counter>
    		<Counter>\ASP.NET Apps v4.0.30319(__Total__)\Errors Total</Counter>
    		<Counter>\ASP.NET Apps v4.0.30319(__Total__)\Errors Total/Sec</Counter>
    		<Counter>\ASP.NET v4.0.30319\Error Events Raised</Counter>
    		<Counter>\ASP.NET v4.0.30319\Infrastructure Error Events Raised</Counter>
    		<Counter>\ASP.NET v4.0.30319\Request Error Events Raised</Counter>
    		<Counter>\.NET CLR Exceptions\*</Counter>
    		<Counter>\.NET CLR Memory(_Global_)\% Time in GC</Counter>
    		<CounterDisplayName>\ASP.NET Apps v4.0.30319(__Total__)\% Tempo processore gestito (stimato)</CounterDisplayName>
    		<CounterDisplayName>\ASP.NET Apps v4.0.30319(__Total__)\Errore di convalida MAC ViewState</CounterDisplayName>
    		<CounterDisplayName>\ASP.NET Apps v4.0.30319(__Total__)\Errori di compilazione</CounterDisplayName>
    		<CounterDisplayName>\ASP.NET Apps v4.0.30319(__Total__)\Errori di esecuzione.</CounterDisplayName>
    		<CounterDisplayName>\ASP.NET Apps v4.0.30319(__Total__)\Errori di pre-elaborazione</CounterDisplayName>
    		<CounterDisplayName>\ASP.NET Apps v4.0.30319(__Total__)\Errori non gestiti durante l'esecuzione</CounterDisplayName>
    		<CounterDisplayName>\ASP.NET Apps v4.0.30319(__Total__)\Errori non gestiti durante l'esecuzione/sec</CounterDisplayName>
    		<CounterDisplayName>\ASP.NET Apps v4.0.30319(__Total__)\Eventi errore di controllo generati</CounterDisplayName>
    		<CounterDisplayName>\ASP.NET Apps v4.0.30319(__Total__)\Eventi errore generati</CounterDisplayName>
    		<CounterDisplayName>\ASP.NET Apps v4.0.30319(__Total__)\Eventi errore generati/sec</CounterDisplayName>
    		<CounterDisplayName>\ASP.NET Apps v4.0.30319(__Total__)\Eventi errore infrastruttura generati</CounterDisplayName>
    		<CounterDisplayName>\ASP.NET Apps v4.0.30319(__Total__)\Eventi errore infrastruttura generati/sec</CounterDisplayName>
    		<CounterDisplayName>\ASP.NET Apps v4.0.30319(__Total__)\Eventi errore richiesta generati</CounterDisplayName>
    		<CounterDisplayName>\ASP.NET Apps v4.0.30319(__Total__)\Eventi errore richiesta generati/sec</CounterDisplayName>
    		<CounterDisplayName>\ASP.NET Apps v4.0.30319(__Total__)\Totale errori</CounterDisplayName>
    		<CounterDisplayName>\ASP.NET Apps v4.0.30319(__Total__)\Totale errori/sec</CounterDisplayName>
    		<CounterDisplayName>\ASP.NET v4.0.30319\Eventi errore generati</CounterDisplayName>
    		<CounterDisplayName>\ASP.NET v4.0.30319\Eventi errore infrastruttura generati</CounterDisplayName>
    		<CounterDisplayName>\ASP.NET v4.0.30319\Eventi errore richiesta generati</CounterDisplayName>
    		<CounterDisplayName>\Eccezioni CLR .NET\*</CounterDisplayName>
    		<CounterDisplayName>\Memoria CLR .NET(_Global_)\Percentuale tempo in GC</CounterDisplayName>
    			<Logging level="15" file="rules.log">
    			<Import file="%systemroot%\pla\rules\Rules.System.Common.xml">
    			<Import file="%systemroot%\pla\rules\Rules.System.Summary.xml">
    			<Import file="%systemroot%\pla\rules\Rules.System.Performance.xml">
    			<Import file="%systemroot%\pla\rules\Rules.System.CPU.xml">
    			<Import file="%systemroot%\pla\rules\Rules.System.Network.xml">
    			<Import file="%systemroot%\pla\rules\Rules.System.Disk.xml">
    			<Import file="%systemroot%\pla\rules\Rules.System.Memory.xml">
    			<Report name="systemPerformance" version="1" threshold="100">
    				<Import file="%systemroot%\pla\reports\Report.System.Common.xml">
    				<Import file="%systemroot%\pla\reports\Report.System.Summary.xml">
    				<Import file="%systemroot%\pla\reports\Report.System.Performance.xml">
    				<Import file="%systemroot%\pla\reports\Report.System.CPU.xml">
    				<Import file="%systemroot%\pla\reports\Report.System.Network.xml">
    				<Import file="%systemroot%\pla\reports\Report.System.Disk.xml">
    				<Import file="%systemroot%\pla\reports\Report.System.Memory.xml">
    	<Value name="PerformanceMonitorView" type="document">
    		<OBJECT ID="DISystemMonitor" CLASSID="CLSID:C4D2D8E0-D1DD-11CE-940F-008029004347">
    			<PARAM NAME="CounterCount" VALUE="4">
    			<PARAM NAME="Counter00001.Path" VALUE="\Processor(_Total)\% Processor Time">
    			<PARAM NAME="Counter00001.Color" VALUE="255">
    			<PARAM NAME="Counter00001.Width" VALUE="2">
    			<PARAM NAME="Counter00001.LineStyle" VALUE="0">
    			<PARAM NAME="Counter00001.ScaleFactor" VALUE="0">
    			<PARAM NAME="Counter00001.Show" VALUE="1">
    			<PARAM NAME="Counter00001.Selected" VALUE="1">
    			<PARAM NAME="Counter00002.Path" VALUE="\Memory\Pages/sec">
    			<PARAM NAME="Counter00002.Color" VALUE="65280">
    			<PARAM NAME="Counter00002.Width" VALUE="1">
    			<PARAM NAME="Counter00003.Path" VALUE="\PhysicalDisk(_Total)\Avg. Disk sec/Read">
    			<PARAM NAME="Counter00003.Color" VALUE="16711680">
    			<PARAM NAME="Counter00003.Width" VALUE="1">
    			<PARAM NAME="Counter00004.Path" VALUE="\PhysicalDisk(_Total)\Avg. Disk sec/Write">
    			<PARAM NAME="Counter00004.Color" VALUE="55295">
    			<PARAM NAME="Counter00004.Width" VALUE="1">

    public by aniello modified Mar 8, 2012  261454  0  4  0

    ANT properties file for SOA deployment

    ANT properties file for SOA deployment:
    # demo = true , then no soa scripts will be called.
    # global
    # PS4
    # temp
    # my settings
    # my settings
    #demo applications
    #demo mds locations 
    # dev deployment server weblogic
    # acceptance deployment server weblogic

    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 Snippets
    • Channels Snippets