working on it ...

Filters

Explore Public Snippets

Sort by

Found 6,843 snippets matching: util

    public by sukhjinderkahlon  326312  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 java.io.FileInputStream;
    import java.io.FileOutputStream;
    
    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
    				filePath=Path;
    
    			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{
    
    			try{
    
      			Cell = ExcelWSheet.getRow(RowNum).getCell(ColNum);
    
      			String CellData = Cell.getStringCellValue();
    
      			return CellData;
    
      			}catch (Exception e){
    
    				return"";
    
      			}
    
        }
    
    
        
      //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	{
    
    			try{
    
      			Row  = ExcelWSheet.getRow(RowNum);
    
    			Cell = Row.getCell(ColNum, Row.RETURN_BLANK_AS_NULL);
    
    			if (Cell == null) {
    
    				Cell = Row.createCell(ColNum);
    
    				Cell.setCellValue(Result);
    
    				} else {
    
    					Cell.setCellValue(Result);
    
    				}
    
      // Constant variables Test Data path and Test Data file name
    
      				FileOutputStream fileOut = new FileOutputStream(filePath);
    
      				ExcelWBook.write(fileOut);
    
      				fileOut.flush();
    
    					fileOut.close();
    
    				}catch(Exception e){
    
    					throw (e);
    
    			}
    
    		}
    
    	
    }
              

    public by frank  167803  0  4  1

    Utilizando o Modernizr

         IF(Modernizr.geolocation) {
           //Aceita a feature 
      } else {
          //Não aceita a feature
    }
    

    public by Geometry  87817  2  4  0

    PubKeyToScript: For POS coins - used to format wallet address pubkey to use in generation transaction's output.

    For POS coins - used to format wallet address pubkey to use in generation transaction's output. nodejs: https://github.com/zone117x/node-stratum-pool/blob/3586ec0d7374b2acc5a72d5ef597da26f0e39d54/lib/util.js#L243 nodejs: http://runnable.com/me/VCFHE0RrZnwbsQ6y
    using System;
    using System.IO;
    using System.Linq;
    using CoiniumServ.Coin.Address;
    using CoiniumServ.Coin.Address.Exceptions;
    using CoiniumServ.Cryptology;
    using CoiniumServ.Utils.Extensions;
    using CoiniumServ.Utils.Numerics;
    using Gibbed.IO;
    using Serilog;
    
    /// <summary>
    /// For POS coins - used to format wallet address pubkey to use in generation transaction's output.
    /// </summary>
    /// <param name="key"></param>
    /// <example>
    /// nodejs: https://github.com/zone117x/node-stratum-pool/blob/3586ec0d7374b2acc5a72d5ef597da26f0e39d54/lib/util.js#L243
    /// nodejs: http://runnable.com/me/VCFHE0RrZnwbsQ6y
    /// </example>
    /// <returns></returns>
    public static byte[] PubKeyToScript(string key)
    {
        var pubKey = key.HexToByteArray();
    
        if (pubKey.Length != 33)
        {
            Log.Error("invalid pubkey length for {0:l}", key);
            return null;
        }
    
        byte[] result;
    
        using (var stream = new MemoryStream())
        {
            stream.WriteValueU8(0x21);
            stream.WriteBytes(pubKey);
            stream.WriteValueU8(0xac);
            result = stream.ToArray();
        }
    
        return result;
    }

    public by sebastian.piskorski  3674  3  5  2

    [MySQL] Calculate Database size

    [MySQL] Calculate Database size using simple single query.
    SELECT table_schema "Data Base Name",
        sum( data_length + index_length ) / 1024 / 1024 "Data Base Size in MB",
        sum( data_free )/ 1024 / 1024 "Free Space in MB"
    FROM information_schema.TABLES
    GROUP BY table_schema ;

    public by markymark87  1743  8  6  0

    Util Date between two util dates

    Check to see if a util date is between two other util dates
    public boolean isWithinRange(Date date, Date startDate, Date endDate) {
    	return !(date.before(startDate) || date.after(endDate));
    }

    public by markymark87  2005  1  5  0

    Util Date to XML Greg Cal

    private XMLGregorianCalendar dateToGreg (Date date) {
    	XMLGregorianCalendar xDate = null;
    	try {
    		GregorianCalendar c = new GregorianCalendar();
    		c.setTime(date);
    		xDate = DatatypeFactory.newInstance().newXMLGregorianCalendar(c);
    	} catch (DatatypeConfigurationException e) {
    		e.printStackTrace();
    	}
    	return xDate;
    }

    public by markymark87  1582  1  6  0

    Util date generator

    Util date generator that takes a number to determine how far in the past to create date
    public static Date dateGenerator (int daysOld) {
    	long DAY_IN_MS = 1000 * 60 * 60 * 24;
      Date date = new Date(System.currentTimeMillis() - (daysOld * DAY_IN_MS));
      return date;
    }        

    public by JKCPR  3338  1  6  2

    Measure memory usage in PHP (utility script):

    You can use this code snippet to measure memory usage in PHP
    <?php 
    $time = microtime(TRUE);
    $mem = memory_get_usage();
    
    /*[the code you want to measure here]*/
    
    print_r(array(
    
      'memory' => (memory_get_usage() - $mem) / (1024 * 1024),
    
      'seconds' => microtime(TRUE) - $time
    
    ));
    ?>

    public by sTiLL-iLL @ SniPitz-KND  4771  3  7  16

    kwik dirty arraySort....

    kwik example of a complex array sort
    // sort a complex array
    
    var mehAry = [{id: 140, name: "abc", age: "twenty"},
                  {id: 62009, name: "def", age: "thirty"},
                  {id: 3030, name: "ghi", age: "forty" },
                  {id: 455, name: "jkl", age: "fifty" }];
          
    function complexSort (itm1, itm2) {
        var a = itm1.id, b = itm2.id;
        return (a - b);
    }
    
    var sortedArray = mehAry.sort(complexSort);  
    
    //  sortedArray = [{id: 140, name: "abc", age: "twenty"},{id: 455, name: "jkl", age: "fifty" },
    //                 {id: 62009, name: "def", age: "thirty"},{id: 3030, name: "ghi", age: "forty" }];                        

    public by lbottaro  3611  1  8  3

    Dalekjs - Define a simple functions file

    This file contains a sample of utility functions you can import in your web automation test file, using dalekjs testing tool. You can specify the argument to pass to the method: here the 'domain' argument is used into the method. More info about dalekjs tool here Site: dalekjs.com
    module.exports = {
    S2CLogout: function (domain, test) {
      console.log('Domain is:', domain);
      test
        .open(domain+'/Access/Logout')
        .done();
    }
    };
    • Public Snippets
    • Channels Snippets