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

                    SAP-EDGE is a complete vault for providing offline, online courses  Offering tranging from sap courses which are  abap, abap hr,  bw/bi, bo, bpc, fico, sd, hr, mm , web dynpro, xi, pi, basis, securities with grc,  business one.                
                    [C# Code]

//build URI to get selected link on a page
            string strURI = "http://api.saaspose.com/v1.0/pdf/input.pdf/pages/1/links/1";
            string signedURI = Sign(strURI);
            Stream responseStream = ProcessCommand(signedURI, "GET");
            StreamReader reader = new StreamReader(responseStream);
            string strJSON = reader.ReadToEnd();
            //Parse the json string to JObject
            JObject parsedJSON = JObject.Parse(strJSON);
            //Deserializes the JSON to a object. 
            PdfLinkResponse pdfLinkResponse = JsonConvert.DeserializeObject<PdfLinkResponse>(parsedJSON.ToString());
            Link tempLink = pdfLinkResponse.Link;

	    //Here is the BaseResponse class
	    public class BaseResponse
  	    {
	        public BaseResponse() { }
	        public string Code { get; set; }
	        public string Status { get; set; }
	    }

	    //Here is the PdfLinkResponse class
	    public class PdfLinkResponse : BaseResponse
	    {
	        public PdfLinkResponse() { }
	        public Link Link { get; set; }
	    }

	    //Here is the LinkResponse class
	    public class LinkResponse
	    {
	        public string Href { get; set; }
	        public string Rel { get; set; }
	        public string Title { get; set; }
	        public string Type { get; set; }
	    }

	    //Here is the Link class
	    public class Link
	    {
	        public Link() { }
	        public LinkActionType ActionType { get; set; }
	        public string Action { get; set; }
	        public LinkHighlightingMode Highlighting { get; set; }
	        public Color Color { get; set; }
	    }

	    //Here is the LinkActionType enum
	    public enum  LinkActionType
	    {
	        GoToAction,
	        GoToURIAction,
	        JavascriptAction,
	        LaunchAction,
	        NamedAction,
	        SubmitFormAction
	    }

	    //Here is the LinkHighlightingMode enum
	    public enum LinkHighlightingMode
	    {
	        None,
	        Invert,
	        Outline,
	        Push,
	        Toggle
	    }

	    //Here is the Color class
	    public class Color
	    {
	        public Color() { }
	        public List<LinkResponse> Links { get; set; }
	        public int A { get; set; }
	        public int B { get; set; }
	        public int G { get; set; }
	        public int R { get; set; }
	    }

[VB.NET Code]

'build URI to get selected link on a page
	     Dim strURI As String = "http://api.saaspose.com/v1.0/pdf/input.pdf/pages/1/links/1"
	     Dim signedURI As String = Sign(strURI)
	     Dim responseStream As Stream = ProcessCommand(signedURI, "GET")
	     Dim reader As New StreamReader(responseStream)
	     Dim strJSON As String = reader.ReadToEnd()
	     'Parse the json string to JObject
	     Dim parsedJSON As JObject = JObject.Parse(strJSON)
	     'Deserializes the JSON to a object.
	     Dim pdfLinkResponse As PdfLinkResponse = JsonConvert.DeserializeObject(Of PdfLinkResponse)(parsedJSON.ToString())
	     Dim tempLink As Link = pdfLinkResponse.Link
                
                    //build URI to replace text

string strURI = "http://api.saaspose.com/v1.0/words/input.docx/replaceText";
string signedURI = Sign(strURI);

//serialize the JSON request content
ReplaceText replacetext = new ReplaceText();

// set old string to replace
replacetext.OldValue = OldValue;

// set new string to replace
replacetext.NewValue = NewValue;

// True indicates case-sensitive comparison, false indicates case-insensitive comparision.

replacetext.IsMatchCase = IsMatchCase;

// True indicates the oldValue must be a standalone word.

replacetext.IsMatchWholeWord = IsMatchWholeWord;
string strJSON = JsonConvert.SerializeObject(replacetext);
Stream responseStream = ProcessCommand(signedURI, "POST", strJSON);
StreamReader reader = new StreamReader(responseStream);
string strResponse = reader.ReadToEnd();
//Parse the json string to JObject
JObject pJSON = JObject.Parse(strResponse);
ReplaceTextResponse baseResponse = JsonConvert.DeserializeObject<ReplaceTextResponse>(pJSON.ToString());
//sign URI
signedURI = Sign(baseResponse.DocumentLink.Href + "?format=doc");
//get response stream
responseStream = ProcessCommand(signedURI, "GET");
using (Stream fileStream = System.IO.File.OpenWrite(outputPath))
{
 CopyStream(responseStream, fileStream);
}
responseStream.Close();

//Here is the ReplaceText class
 
public class ReplaceText
{               
 public string OldValue { get; set; }
 public string NewValue { get; set; }
 public bool IsMatchCase { get; set; }
 public bool IsMatchWholeWord { get; set; }
}
                
                    -- source: http://www.apphp.com/index.php?snippet=mysql-selecting-random-row
SELECT * FROM TABLE
ORDER BY RAND()
LIMIT 1                
                    <!-- source: http://www.apphp.com/index.php?snippet=html-5-media-code -->
<form action="upload.php" method="post" enctype="multipart/form-data">
  <input name="upload_files[]" type="file" multiple>
  <input type="submit" value="Upload">
</form>
 
<?php
// PHP code
 that shows how to loop through the data as an array
foreach($_FILES["upload_files"]["name"] as $file){
    echo "<li>".$file."</li>";
}
?>                
                    <!-- source: http://www.apphp.com/index.php?snippet=html-5-media-code -->
<video poster="images/preview.png" width="800" height="600" controls="controls" preload="none"> 
  <source src="media/my_video.mp4" type="video/mp4"></source> 
  <source src="media/my_video.webm" type="video/webm"></source> 
  <source src="media/my_video.ogg" type="video/ogg"></source>
</video>
<audio controls="controls" preload="none">
  <source src="audio/my_music.ogg" type="audio/ogg">
  <source src="audio/my_music.mp3" type="audio/mpeg">
</audio>                
                    <!-- source: http://www.apphp.com/index.php?snippet=html-5-media-code -->
<video poster="images/preview.png" width="800" height="600" controls="controls" preload="none"> 
  <source src="media/my_video.mp4" type="video/mp4"></source> 
  <source src="media/my_video.webm" type="video/webm"></source> 
  <source src="media/my_video.ogg" type="video/ogg"></source>
</video>
<audio controls="controls" preload="none">
  <source src="audio/my_music.ogg" type="audio/ogg">
  <source src="audio/my_music.mp3" type="audio/mpeg">
</audio>                
                    Integer n = 100;
String[] format = new String[]{"%d\n","fizz\n","buzz\n","fizzbuzz"};
for(int i=1;i< n; i++){
    System.out.printf(format[((i%3==0)?1:0) + 2 *((i%5==0)?1:0)] + "",i);
}                
                    <style type="text/css">
/* source:  http://www.apphp.com/index.php?snippet=css-reset-browser-default-styles */ 
html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code
, del, dfn, em, img, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, b, u, i, center, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td, article, aside, canvas, details, embed, figure, figcaption, footer, header, hgroup, menu, nav, output, ruby, section, summary, time, mark, audio, video
    { margin:0; padding:0; border:0; font-size:100%; font:inherit; vertical-align:baseline; outline:none; }
html
    { height:101%; } /* always show scrollbars */
body
    { font-size:62.5%; line-height:1; font-family:Arial, Tahoma, Verdana, sans-serif; }
article, aside, details, figcaption, figure, footer, header, hgroup, menu, nav, section
    { display:block; }
img
    { border:0; max-width:100%; }
a
    { text-decoration:none; }
a:hover
     { text-decoration:underline; }
ol, ul
    { list-style:none; }
blockquote, q
    { quotes:none; }
blockquote:before, blockquote:after, q:before, q:after
     { content:""; content:none; }
strong
    { font-weight:bold; } 
input
    { outline:none; }
table
    { border-collapse:collapse; border-spacing:0; }
</style>                
                    <!-- source: http://www.apphp.com/index.php?snippet=css-alternating-table-color-rows -->
<style type="text/css">
/* technique 1 */
tbody tr:nth-child(odd){ background-color:#ccc; }
/* technique 2 */
TBODY TR.odd { background-color:#78a5d1; }
</style>
 
<table>
<tbody>
<tr><td>Row1</td><td>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</td></tr>
<tr><td>Row2</td><td>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</td></tr>
<tr><td>Row3</td><td>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</td></tr>
<tr><td>Row4</td><td>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</td></tr>
<tr><td>Row5</td><td>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</td></tr>
</tbody>
</table>
 
<table>
<tbody>
<tr class="odd"><td>Row1</td><td>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</td></tr>
<tr><td>Row2</td><td>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</td></tr>
<tr class="odd"><td>Row3</td><td>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</td></tr>
<tr><td>Row4</td><td>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</td></tr>
<tr class="odd"><td>Row5</td><td>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</td></tr>
</tbody>
</table>