Explore Public Snippets
Found 6,843 snippets matching: util
public by sukhjinderkahlon 326312 7 5 0
How to Work with Excel Files Using Apache POI
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); } } }
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.
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
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
public boolean isWithinRange(Date date, Date startDate, Date endDate) { return !(date.before(startDate) || date.after(endDate)); }
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
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):
<?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....
// 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
module.exports = { S2CLogout: function (domain, test) { console.log('Domain is:', domain); test .open(domain+'/Access/Logout') .done(); } };