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
Recent Snippets
- Add Watermark Text to a Word doc
- Watermark Text in Word documennt
- Watermark Text
- build URI to add watermark text
Watermark Text Addition To Word Documents In .NET Applications
11/28/12 by Sherazam Khan in C#//build URI to add watermark text string strURI = "api.saaspose.com/v1.0/words/input.docx/insertWatermarkText"; string signedURI = Sign(strURI); //serialize the JSON request content WatermarkText watermark = new WatermarkText(); watermark.Text = "Watermark Text Here"; watermark.RotationAngle = 45.0; string strJSON = JsonConvert.SerializeObject(watermark); 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); BaseResponse baseResponse = JsonConvert.DeserializeObject<BaseResponse>(pJSON.ToString()); if (baseResponse.Code == "200" && baseResponse.Status == "OK") Console.WriteLine("Watermark text has been added successfully"); //Here is the WatermarkText class public class WatermarkText { public string Text { get; set; } public double RotationAngle { get; set; } } //Here is the BaseResponse class public class BaseResponse { public BaseResponse() { } public string Code { get; set; } public string Status { get; set; } }
0 Replies
- javascript
Toggling Default Value Of Textbox On Focus
11/28/12 by Arvind Bhardwaj in JavaScriptvar t = document.getElementById('ID'); t.onfocus = hideText; t.onblur = showText; function hideText() { if(this.value == this.defaultValue) { this.value = ''; } } function showText() { if(this.value == '') { this.value = this.defaultValue; } }
0 Replies
- java
- REST
- ssl
- https
How To Call A Rest Webservice With An Untrusted SSL Certificate
11/16/12 by Rodrigo Asensio in JavaTrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() { public X509Certificate[] getAcceptedIssuers() { return null; } public void checkClientTrusted(X509Certificate[] certs, String authType) {} public void checkServerTrusted(X509Certificate[] certs, String authType) {} } }; SSLContext context = SSLContext.getInstance("TLS"); context.init(null, trustAllCerts, new SecureRandom()); HttpsURLConnection.setDefaultSSLSocketFactory(context.getSocketFactory()); ClientConfig config = new DefaultClientConfig(); config.getProperties().put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES, new HTTPSProperties(new HostnameVerifier() { @Override public boolean verify(String s, SSLSession sslSession) { return true; } }, context)); Client client = Client.create(config); client.setFollowRedirects(true); WebResource resource = client.resource("https://myserver/myws"); resource.accept(MediaType.APPLICATION_JSON_TYPE); String result = resource.post(String.class);
0 Replies
- read barcode from external image URL
- Read Barcodes
- display type of recognized barcodes
- display recognized barcodes value
- Barcodes REST API
- Barcodes
Read & Recognize Barcode From External Image URL In Java Applications
11/16/12 by Sheraz Khan in Java//build URI to read barcode //type: Codabar, Code11, Code128 and Code39Extended etc. String strURI = "api.saaspose.com/v1.0/barcode/recognize?type=QR&url=upload.wikimedia.org/wikipedia/commons/c/ce/WikiQRCode.png"; // Send the request to Saaspose server InputStream responseStream = ProcessCommand(Sign(strURI), "POST"); // Read the response String strJSON = StreamToString(responseStream); //Parse and Deserializes the JSON to a object. RecognitionResponse barcodeRecognitionResponse = gson.fromJson(strJSON,RecognitionResponse.class); List<RecognizedBarCode> barcodes = barcodeRecognitionResponse.getBarcodes(); // Display the value and type of all the recognized barcodes for (RecognizedBarCode barcode : barcodes) { System.out.println("Codetext: " + barcode.BarcodeValue() + "\nType: " + barcode.getBarcodeType()); } \\Here is the RecognitionResponse class public class RecognitionResponse extends BaseResponse { private List<RecognizedBarCode> Barcodes ; public List<RecognizedBarCode> getBarcodes(){return Barcodes;} } \\Here is the RecognizedBarCode class public class RecognizedBarCode { private String BarcodeType ; private String BarcodeValue; public String getBarcodeType(){return BarcodeType;} public String BarcodeValue(){return BarcodeValue;} } \\Here is the BaseResponse class public class BaseResponse { public BaseResponse() { } private String Code; private String Status; public String getCode(){return Code;} public String getStatus(){return Status;} public void setCode(String temCode){ Code=temCode;} public void setStatus(String temStatus){ Status=temStatus;} }
0 Replies
- Apphp
- php
- element
Toggling Elements With JavaScript
11/04/12 by Chara Miteo in ActionScript<script type="text/javascript"> /* Source: www.apphp.com/index.php?snippet=javascript-toggle-elements */ function toggle(id, id2){ var toggle_one = document.getElementById(id); var toggle_two = document.getElementById(id2); if(toggle_one.style.display == "block"){ toggle_one.style.display = "none"; toggle_two.innerHTML = "Show"; }else{ toggle_one.style.display = "block"; toggle_two.innerHTML = "Hide"; } } </script> <a class="#" id="tlink">Show</a> Comments<br><br> <div id="comments" style="display:none;padding 10px;">Now you can see the comments</div>
0 Replies
- Apphp
- php
Download File With A Speed Limit In PHP
11/04/12 by Chara Miteo in PHP<?php /* Source: www.apphp.com/index.php?snippet=php-download-file-with-speed-limit */ /* set here a limit of downloading rate (e.g. 10.20 Kb/s) */ $download_rate = 10.20; $download_file = 'download-file.zip'; $target_file = 'target-file.zip'; if(file_exists($download_file)){ /* headers */ header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); header('Cache-control: private'); header('Content-Type: application/octet-stream'); header('Content-Length: '.filesize($download_file)); header('Content-Disposition: filename='.$target_file); /* flush content */ flush(); /* open file */ $fh = @fopen($download_file, 'r'); while(!feof($fh)){ /* send only current part of the file to browser */ print fread($fh, round($download_rate * 1024)); /* flush the content to the browser */ flush(); /* sleep for 1 sec */ sleep(1); } /* close file */ @fclose($fh); }else{ die('Fatal error: the '.$download_file.' file does not exist!'); } ?>
0 Replies
- Apphp
- php
- directory
List Directory Contents In PHP
11/04/12 by Chara Miteo in PHP<?php /* Source: www.apphp.com/index.php?snippet=php-list-directory-contents */ function list_directory_content($dir){ if(is_dir($dir)){ if($handle = opendir($dir)){ while(($file = readdir($handle)) !== false){ if($file != '.' && $file != '..' && $file != '.htaccess'){ echo '<a target="_blank" class="'.$dir.$file.'">'.$file.'</a><br>'."\n"; } } closedir($handle); } } } ?>
0 Replies
- Apphp
- php
- Contents
List Directory Contents In PHP
11/04/12 by Chara Miteo in PHP<?php /* Source: www.apphp.com/index.php?snippet=php-list-directory-contents */ function list_directory_content($dir){ if(is_dir($dir)){ if($handle = opendir($dir)){ while(($file = readdir($handle)) !== false){ if($file != '.' && $file != '..' && $file != '.htaccess'){ echo '<a target="_blank" class="'.$dir.$file.'">'.$file.'</a><br>'."\n"; } } closedir($handle); } } } ?>
0 Replies
- Apphp
- php
- web
- extention
Get File Extension In PHP
11/04/12 by Chara Miteo in PHP<?php /* Source: www.apphp.com/index.php?snippet=php-get-file-extension */ function get_file_extension($file_name) { /* may contain multiple dots */ $string_parts = explode('.', $file_name); $extension = $string_parts[count($string_parts) - 1]; $extension = strtolower($extension); return $extension; } ?>
0 Replies
- C
- C++
- matrix
- gaussian elimination
- upper triangulization
- back substitution
- row reduced echelon form
- gauss–jordan
- linear algebra
Matrix Operations: Gaussian Elimination, Upper Triangulization And Back-substitution Example In C
11/03/12 by Adrian Boeing in C/** Gaussian elimination / Upper triangulization / Back-substitution example by Adrian Boeing adrianboeing.blogspot.com www.adrianboeing.com */ #include <stdio.h> void PrintMatrix(double **mat, int m, int n) { for (int j=0;j<n;j++) { for (int i=0;i<m;i++) { printf("%+5.2f ",mat[j][i]); } printf("\n"); } } int main(int argc, char*argv[]) { int m,n; //m - col, n - rows int i; m=5; n=4; //allocate the matrix double **mat = new double* [n]; for (i=0;i<n;i++) mat[i] = new double [m]; //initialize matrix mat[0][0] = 1; mat[0][1] = 2; mat[0][2] = 1; mat[0][3] = 4; mat[0][4] = 13; mat[1][0] = 2; mat[1][1] = 0; mat[1][2] = 4; mat[1][3] = 3; mat[1][4] = 28; mat[2][0] = 4; mat[2][1] = 2; mat[2][2] = 2; mat[2][3] = 1; mat[2][4] = 20; mat[3][0] =-3; mat[3][1] = 1; mat[3][2] = 3; mat[3][3] = 2; mat[3][4] = 6; printf("Initial matrix\n"); PrintMatrix(mat,m,n); printf("Gaussian elimination\n"); //p is the pivot - which row we will use to eliminate for (int p=0;p<n-1;p++) { //pivot through all the rows for (int r=p+1; r < n; r++) { //for each row that isn't the pivot float multiple = mat[r][p] / mat[p][p]; //how many multiples of the pivot row do we need (to eliminate this row)? for (int c = 0; c<m; c++) { //for each element in this row mat[r][c] = mat[r][c] - mat[p][c]*multiple; //subtract the pivot row element (multiple times) } } } PrintMatrix(mat,m,n); printf("Upper triangulization\n"); //p is the pivot - which row we will normalize for (int p=0;p<n;p++) { //pivot through all the rows for (int c=p+1;c<m;c++) { //normalize the pivot row, so that the pivot element can be set to 1. mat[p][c] /= mat[p][p]; //divide all elements in the row by the pivot element } mat[p][p] = 1; //set the pivot element to 1. } PrintMatrix(mat,m,n); printf("Back-substitution\n"); for (int p=n-1;p>0;p--) { //pivot backwards through all the rows for (int r=p-1;r>=0;r--) { //for each row above the pivot float multiple = mat[r][p]; //how many multiples of the pivot row do we need (to subtract)? for (int c=p-1;c<m;c++) { mat[r][c] = mat[r][c] - mat[p][c]*multiple; //subtract the pivot row element (multiple times) } } } PrintMatrix(mat,m,n); } /* Another example: m = 6; n = 3; mat[0][0] = 2; mat[0][1] = 4; mat[0][2] =-2; mat[0][3] = 1; mat[0][4] = 0; mat[0][5] = 0; mat[1][0] = 4; mat[1][1] = 9; mat[1][2] =-3; mat[1][3] = 0; mat[1][4] = 1; mat[1][5] = 0; mat[2][0] =-2; mat[2][1] =-3; mat[2][2] = 7; mat[2][3] = 0; mat[2][4] = 0; mat[2][5] = 1; */
0 Replies
- 0
- 1
- 2
- 3
- 4
- 5
- >
- »