DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets

  • submit to reddit

Recent Snippets

                    <style type="text/css">
.break {
    -ms-word-break: break-all;
    word-break: break-all;
    word-break: break-word; 
    -webkit-hyphens: auto;
    -moz-hyphens: auto;
    hyphens: auto;
}
 
.ellipsis {
    width: 250px;
    white-space: nowrap;
    overflow: hidden;
    -ms-text-overflow: ellipsis; /* Required for IE8 */
    -o-text-overflow: ellipsis; /* Required for Opera */
    text-overflow: ellipsis;
}
</style>                
                    <style type="text/css">
.tooltip-container {
    /* Forces tooltip to be relative to the element, not the page */
    position:relative;  
    cursor:help;
}
 
.tooltip {
    display:block;
    position:absolute;
    width:150px;
    padding:5px 15px;
    left:50%;
    bottom:25px;
    margin-left:-95px;
    /* Tooltip Style */
    color:#fff;
    border:2px solid rgba(34,34,34,0.9);
    background:rgba(51,51,51,0.9);
    text-align:center;
    border-radius:3px;
    /* Tooltip Style */
    opacity:0;
    box-shadow:0px 0px 3px rgba(0, 0, 0, 0.3);
    -webkit-transition:all 0.2s ease-in-out;
    -moz-transition:all 0.2s ease-in-out;
    -0-transition:all 0.2s ease-in-out;
    -ms-transition:all 0.2s ease-in-out;
    transition:all 0.2s ease-in-out;
    -webkit-transform:scale(0);
    -moz-transform:scale(0);
    -o-transform:scale(0);
    -ms-transform:scale(0);
    transform:scale(0);
    /* Reset tooltip, to not use container styling */
    font-size:14px;
    font-weight:normal;
    font-style:normal;
}
 
.tooltip:before, .tooltip:after{
    content:"";
    position:absolute;
    bottom:-13px;
    left:50%;
    margin-left:-9px;
    width:0;
    height:0;
    border-left:10px solid transparent;
    border-right:10px solid transparent;
    border-top:10px solid rgba(0,0,0,0.1);
}
.tooltip:after{
    bottom:-12px;
    margin-left:-10px;
    border-top:10px solid rgba(34,34,34,0.9);
}
 
.tooltip-container:hover .tooltip, a:hover .tooltip {
    /* Makes the Tooltip slightly transparent, Lets the barely see though it */
    opacity:0.9;
    /* Changes the scale from 0 to 1 - This is what animtes our tooltip! */
    -webkit-transform:scale(1);
    -moz-transform:scale(1);
    -o-transform:scale(1);
    -ms-transform:scale(1);
    transform:scale(1);
}
 
/* Custom Classes */
.tooltip-style1 {
    color:#000;
    border:2px solid #fff;
    background:rgba(246,246,246,0.9);
    font-style:italic;
}
.tooltip-style1:after{
    border-top:10px solid #fff;
}
</style>
 
<i class="tooltip-container"><b>Lorem ipsum dolor sit amet</b><span class="tooltip">Hello! This is a first tooltip!</span></i>
 
<em class="tooltip-container"><b>Pellentesque id auctor sem</b><span class="tooltip tooltip-style1">This is a second tooltip!</span></em>                
                    <script language="javascript">
FormValidator = function(){
 
    // private data member (property)
    var _digits = "0123456789";
 
    // public data member (property)
    this.digits = "0123456789";
    
    // private data function (method)
    var _isEmpty = function(s){ return((s==null)||(s.length==0))};    
 
    // publick data function (method)
    this.isEmpty = function(s){ return((s==null)||(s.length==0))};        
}
 
/* create a new instance of Validator object */ 
var jsFormValidator = new FormValidator();
 
/* wrong access, errors will be produced */
alert(jsFormValidator._digits);
alert(jsFormValidator._isEmpty());
 
/* valid access */
alert(jsFormValidator.digits);
alert(jsFormValidator.isEmpty());
</script>                
                    <div id="buy-buttons">
  <label>Quantity:</label>
  <input name="txtQuantity" id="txtQuantity" type="text" value="1" />
  <input type="submit" name="btnAddToCart" value="Add To Cart" id="btnAddToCart" />
</div>
 
<script>
// First way:
$("#txtQuantity").remove();
$("#buy-buttons").append('<select name="txtQuantity" id="txtQuantity"></select>');
$("#txtQuantity").append('<option value="1" selected="selected">1</option>' +
    '<option value="2">2</option>' +
    '<option value="3">3</option>' +
    '<option value="4">4</option>' +
    '<option value="5">5</option>');
 
// Second way:
$("#txtQuantity")
    .replaceWith('<select name="txtQuantity" id="txtQuantity">' +
        '<option value="1">1</option>' +
        '<option value="2">2</option>' +
        '<option value="3">3</option>' +
        '<option value="4">4</option>' +
        '<option value="5">5</option>' +
        '</select>');
</script>                
                    <?php
$json_data = array(
   'id'=>1,'name'=>'jackson','country'=>'usa','office'=>array('google','oracle')
);
echo json_encode
($json_data);

// Result:
// {"id":1,"name":"jackson","country":"usa","office":["google","oracle"]}
?>                
                    <?php
$ip_address = '127.0.0.1';
 
if(preg_match('/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/', $ip_address)){
   echo 'IP address is valid!';
}else{
   echo 'IP address is NOT valid!';
}
?>                
                    
// read the source TIFF image
ImageInputStream iis = ImageIO.createImageInputStream(new FileInputStream("d:/pdftest/BW_MultiPage_TIFF.tif"));
Iterator<ImageReader> readers = ImageIO.getImageReaders(iis);
// create ImageReader object to parse the Image
ImageReader ir = readers.next();
// specify the input source
ir.setInput(iis);
// get the count of frames in TIFF image
int frameCount = ir.getNumImages(true);
// iterate through each TIFF frame
for (int i = 0; i < frameCount; ++i)
    // save the individual TIFF frame as separate image with JPEG compression
    ImageIO.write(ir.read(i), "jpg", new File("d:/pdftest/TIFF_JPEG_Coversion/frame" + i + ".jpg"));
// show the total count of tiff frames (optional)
// System.out.println("Tiff contains: "+frameCount+" frames");


// specify the directory containing JPEG images
String image_Directory = "d:/pdftest/TIFF_JPEG_Coversion/";
// read the files from Image directory
File f = new File(image_Directory);
// get the list of files in directory
File[] fa = f.listFiles();

//Instantiate a Pdf object by calling its empty constructor
Pdf pdf1 = new Pdf();
//Create a section in the Pdf object
Section sec1 = pdf1.getSections().add();

for (int i = 0; i < fa.length; i++)
{
    // by default each image will be added as new paragraph on new page
    //Create an image object in the section
    aspose.pdf.Image img1 = new aspose.pdf.Image(sec1);
    //Add image object into the Paragraphs collection of the section
    sec1.getParagraphs().add(img1);
    //Set the path of image file
    img1.getImageInfo().setFile(fa[i].getPath());
    //Set the image file Type
    img1.getImageInfo().setImageFileType(ImageFileType.Jpeg);
}
//Save the Pdf
pdf1.save("d:/pdftest/JPEG_image_toPDF.pdf");
// close InputStream holding TIFF image
iis.close();
                
                     package com.dataconnect.test.util;

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.ResultSet;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class SchemaDetailsTest {

   private static Logger log = LoggerFactory
       .getLogger(SchemaDetailsTest.class);

   public static void main(String args[]) throws Exception {

     String databaseName = "myDbName";
     String userName = "username";
     String password = "password";
     String mySQLPort = "3306";
     String hostUrl = "127.0.0.1";

     // Setup the connection with the DB
     Class.forName("com.mysql.jdbc.Driver");

     Connection conn = DriverManager.getConnection("jdbc:mysql://" + hostUrl
         + ":" + mySQLPort, userName, password);

     // --- LISTING DATABASE SCHEMA NAMES ---
     ResultSet resultSet = conn.getMetaData().getCatalogs();

     while (resultSet.next()) {
       log.info("Schema Name = " + resultSet.getString("TABLE_CAT"));
     }
     resultSet.close();

     // --- LISTING DATABASE TABLE NAMES ---
     String[] types = { "TABLE" };
     resultSet = conn.getMetaData()
         .getTables(databaseName, null, "%", types);
     String tableName = "";
     while (resultSet.next()) {
       tableName = resultSet.getString(3);
       log.info("Table Name = " + tableName);
     }
     resultSet.close();

     // --- LISTING DATABASE COLUMN NAMES ---
     DatabaseMetaData meta = conn.getMetaData();
     resultSet = meta.getColumns(databaseName, null, tableName, "%");

     while (resultSet.next()) {
       log.info("Column Name of table " + tableName + " = "
           + resultSet.getString(4));
     }
   }
}                
                    @Grab(group='com.jcraft', module='jsch', version='0.1.46')
import com.jcraft.jsch.*

java.util.Properties config = new java.util.Properties()
config.put "StrictHostKeyChecking", "no"

JSch ssh = new JSch()
Session sess = ssh.getSession "user", "server.domain.com", 22
sess.with {
	setConfig config
	setPassword "somecomplicatedpassword"
	connect()
	Channel chan = openChannel "sftp"
	chan.connect()
	
	ChannelSftp sftp = (ChannelSftp) chan;
	def sessionsFile = new File('c:/important_document.doc')
	sessionsFile.withInputStream { istream -> sftp.put(istream, "/home/brippe/Documents/important_document.doc") }
	chan.disconnect()
	disconnect()
}                
                    1: <footer>© simplymanas 2013
   2: <a href="mailto:simplymanas@gmail.com?Subject=From BR">Contact Me</a>
   3: <a href="http:\\www.twitter.com\simplymanas">@simplymanas</a>
   4: </footer>