The quake hit at 7:54 p.m. west of Illapel, about 177 miles north of the capital, Santiago, and was felt in São Paulo, Brazil, more than 2,100 miles away. This caused what's known as an 'Earthquake Swarm' pictured below.
Translate
Thursday, September 17, 2015
Terremotos Chile 8.4
Chile — A strong 8.3-magnitude earthquake struck off Chile’s coast on Wednesday, shaking buildings in cities around the country and forcing the authorities to evacuate residents along the 2,690-mile coast after tsunami warnings were issued. At least eight deaths were reported.
The quake hit at 7:54 p.m. west of Illapel, about 177 miles north of the capital, Santiago, and was felt in São Paulo, Brazil, more than 2,100 miles away. This caused what's known as an 'Earthquake Swarm' pictured below.
The quake hit at 7:54 p.m. west of Illapel, about 177 miles north of the capital, Santiago, and was felt in São Paulo, Brazil, more than 2,100 miles away. This caused what's known as an 'Earthquake Swarm' pictured below.
Labels:
Chile,
terremotos
Monday, July 6, 2015
Base64 Encoder
private void button1_Click(object sender, EventArgs e)
{
this.openFileDialog1.InitialDirectory = GetDownloadsPath();
if (this.openFileDialog1.ShowDialog() == DialogResult.OK)
{
try
{
textBox2.Text = "";
Cursor.Current = Cursors.AppStarting;
toolStripStatusLabel1.Text = "Working ...";
string path = openFileDialog1.FileName;
string fileExt = Path.GetExtension(path).ToLower().Replace(".", String.Empty);
textBox1.Text = path;
textBox1.Refresh();
_image = Image.FromFile(this.textBox1.Text);
var imgHeight = _image.Height;
var imgWidth = _image.Width;
pictureBox1.Height = imgHeight;
pictureBox1.Width = imgWidth;
pictureBox1.Image = _image;
pictureBox1.SizeMode = PictureBoxSizeMode.AutoSize;
pictureBox1.Refresh();
using (MemoryStream ms = new MemoryStream())
{
_image.Save(ms, _image.RawFormat);
byte[] buffer = ms.ToArray();
StringBuilder sb = new StringBuilder();
sb.Append(String.Format("data:image/{0};base64,", fileExt));
sb.Append(Convert.ToBase64String(buffer));
this.textBox2.Text = sb.ToString();
}
}
catch (IOException ioEx)
{
MessageBox.Show("Error: Could not read image file from disk. Orignal error: " + ioEx.Message, "Error");
}
catch (Exception ex)
{
MessageBox.Show("Error: " + ex.Message, "Error");
}
finally
{
Cursor.Current = Cursors.Default;
toolStripStatusLabel1.Text = "Ready";
}
}
}
{
this.openFileDialog1.InitialDirectory = GetDownloadsPath();
if (this.openFileDialog1.ShowDialog() == DialogResult.OK)
{
try
{
textBox2.Text = "";
Cursor.Current = Cursors.AppStarting;
toolStripStatusLabel1.Text = "Working ...";
string path = openFileDialog1.FileName;
string fileExt = Path.GetExtension(path).ToLower().Replace(".", String.Empty);
textBox1.Text = path;
textBox1.Refresh();
_image = Image.FromFile(this.textBox1.Text);
var imgHeight = _image.Height;
var imgWidth = _image.Width;
pictureBox1.Height = imgHeight;
pictureBox1.Width = imgWidth;
pictureBox1.Image = _image;
pictureBox1.SizeMode = PictureBoxSizeMode.AutoSize;
pictureBox1.Refresh();
using (MemoryStream ms = new MemoryStream())
{
_image.Save(ms, _image.RawFormat);
byte[] buffer = ms.ToArray();
StringBuilder sb = new StringBuilder();
sb.Append(String.Format("data:image/{0};base64,", fileExt));
sb.Append(Convert.ToBase64String(buffer));
this.textBox2.Text = sb.ToString();
}
}
catch (IOException ioEx)
{
MessageBox.Show("Error: Could not read image file from disk. Orignal error: " + ioEx.Message, "Error");
}
catch (Exception ex)
{
MessageBox.Show("Error: " + ex.Message, "Error");
}
finally
{
Cursor.Current = Cursors.Default;
toolStripStatusLabel1.Text = "Ready";
}
}
}
Wednesday, March 25, 2015
Utillities
public static DataTable ToDataTable(List items)
{
var dt = new DataTable(typeof (T).Name);
PropertyInfo[] props = typeof (T).GetProperties(BindingFlags.Public | BindingFlags.Instance);
foreach (var prop in props)
{
dt.Columns.Add(prop.Name, BaseType(prop.PropertyType));
}
foreach (var item in items)
{
try
{
var values = new object[props.Length];
for (var i = 0; i < props.Length; i++)
{
values[i] = props[i].GetValue(item, null);
}
dt.Rows.Add(values);
}
catch (Exception)
{
}
}
return dt;
}
public static Type BaseType(Type oType)
{
if (oType != null && oType.IsValueType && oType.IsGenericType &&
oType.GetGenericTypeDefinition() == typeof (Nullable<>))
{
return Nullable.GetUnderlyingType(oType);
}
else
{
return oType;
}
}
{
var dt = new DataTable(typeof (T).Name);
PropertyInfo[] props = typeof (T).GetProperties(BindingFlags.Public | BindingFlags.Instance);
foreach (var prop in props)
{
dt.Columns.Add(prop.Name, BaseType(prop.PropertyType));
}
foreach (var item in items)
{
try
{
var values = new object[props.Length];
for (var i = 0; i < props.Length; i++)
{
values[i] = props[i].GetValue(item, null);
}
dt.Rows.Add(values);
}
catch (Exception)
{
}
}
return dt;
}
public static Type BaseType(Type oType)
{
if (oType != null && oType.IsValueType && oType.IsGenericType &&
oType.GetGenericTypeDefinition() == typeof (Nullable<>))
{
return Nullable.GetUnderlyingType(oType);
}
else
{
return oType;
}
}
Labels:
c-sharp
Monday, March 23, 2015
Custom jQuery validation plugin client side validation rules
When using jQuery Validation plugin setting up a new
validator for a Html form is easy. Adding custom rules for validation is just
as easy. Creating a custom rule on the client side could be more efficient than
doing server side validation after the form is submitted.
Take for instance this javascript that creates a
Validation object for a Html5 input element of type number:
// your Validation object
Var myValidator;
// Place custom validation rule here
// setting up the rules and message for the input element
myValidator = $( "#form1" ).validate({
rules: {
input1: {
// selector of your input textbox
digits:
true,
minlength: 9,
maxlength: 9,
messages:
{
digits: "Value has to be a number",
minlength: $.validator.format("Value {0} is to low"),
maxlength: $.validator.format("Value {0} is too high")
}
}
},
showErrors:
function(errorMap, errorList){
//
place you validation error summary rendering code here
});
}
});
Now if you had a javascript function bound to the input
element's keyup, input events your call to validate the value of the input
element could be similar to the following javascript:
$( "#input1" ).bind( "keyup input",
function(e) {
myValidator.element( "#input1" );
}
});
Now the custom rule part. Take for instance you wanted to
prevent a value to be submitted that was already on display in a different
element on the form. Instead of performing server side validation or making a
separate ajax call, add a custom validation method to the jQuery Validation
plugin. (The syntax is available at
http://jqueryvalidation.org/jQuery.validator.addMethod/).
// Place custom validation rule here
// addMethod ( method-name-string, function(value,
element){
// validation code
//}, validation-message-string );
// e.g.
$.validator.addMethod( "notequalto", function(
value, element ) {
var currentVal
= $( "#txtBoxCurrentValue" ).text();
if ( value ===
currentVal ) {
return
false;
} else {
return
true;
}
}, "That value is already set" );
Now update you rules section for input1 in your validator
object to be:
rules: {
input1: {
// selector of your textbox
digits:
true,
minlength: 9,
maxlength: 9,
notequalto:
true, // no quotes around the new method name, must validate to true
messages: {
digits: "Value has to be a number",
minlength: $.validator.format("Value {0} is to low"),
maxlength: $.validator.format("Value {0} is too high")
}
Labels:
jQuery,
validation.plugin
MSBuild TransformXMl Task when converting from VS 2010 to VS 2012
Sometimes within a VS project Xml files are used to hold
configuration settings for different build types, e.g., Debug vs. Release, etc.
A build warning will be displayed such as:
The "TransformXml task could not be loaded from the
assembly C:\Program Files
(x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.Task.dll.
This warning means that you migrated your VS 2010 project
into a VS 2012 solution successfully, but, forgot to change the references for
VS 2010 MSBuild assemblies to VS 2012 ( which is v11.0 ).
To Fix:
- Unload the project in the VS 2012 IDE, and edit the
project file.
- Change all Microsoft.Web.Publishing.Task.dll version v10.0 references to v11.0
- Change the $(MSBuildExtensionsPath) variable name to
$(MSBuildExtensionsPath32)
- Save your edits and reload the project
Wednesday, March 4, 2015
Custom jQuery validation plugin client side validation rules
When using jQuery Validation plugin setting up a new validator for a Html form is easy. Adding custom rules for validation is just as easy. Creating a custom rule on the client side could be more efficient than doing server side validation after the form is submitted.
Take for instance this javascript that creates a Validation object for a Html5 input element of type number:
// your Validation object
Var myValidator;
// Place custom validation rule here
// setting up the rules and message for the input element
myValidator = $( "#form1" ).validate({
rules: {
input1: { // selector of your input textbox
digits: true,
minlength: 9,
maxlength: 9,
messages: {
digits: "Value has to be a number",
minlength: $.validator.format("Value {0} is to low"),
maxlength: $.validator.format("Value {0} is too high")
}
}
},
showErrors: function(errorMap, errorList){
// place you validation error summary rendering code here
});
}
});
Now if you had a javascript function bound to the input element's keyup, input events your call to validate the value of the input element could be similar to the following javascript:
$( "#input1" ).bind( "keyup input", function(e) {
myValidator.element( "#input1" );
}
});
Now the custom rule part. Take for instance you wanted to prevent a value to be submitted that was already on display in a different element on the form. Instead of performing server side validation or making a separate ajax call, add a custom validation method to the jQuery Validation plugin. (The syntax is available at http://jqueryvalidation.org/jQuery.validator.addMethod/).
// Place custom validation rule here
// addMethod ( method-name-string, function(value, element){
// validation code
//}, validation-message-string );
// e.g.
$.validator.addMethod( "notequalto", function( value, element ) {
var currentVal = $( "#txtBoxCurrentValue" ).text();
if ( value === currentVal ) {
return false;
} else {
return true;
}
}, "That value is already set" );
Now update you rules section for input1 in your validator object to be:
rules: {
input1: { // selector of your textbox
digits: true,
minlength: 9,
maxlength: 9,
notequalto: true, // no quotes around the new method name, must validate to true
messages: {
digits: "Value has to be a number",
minlength: $.validator.format("Value {0} is to low"),
maxlength: $.validator.format("Value {0} is too high")
}
Now you have a custom validation rule for comparing a value against another Html element on the same form. Happy validating!
Take for instance this javascript that creates a Validation object for a Html5 input element of type number:
// your Validation object
Var myValidator;
// Place custom validation rule here
// setting up the rules and message for the input element
myValidator = $( "#form1" ).validate({
rules: {
input1: { // selector of your input textbox
digits: true,
minlength: 9,
maxlength: 9,
messages: {
digits: "Value has to be a number",
minlength: $.validator.format("Value {0} is to low"),
maxlength: $.validator.format("Value {0} is too high")
}
}
},
showErrors: function(errorMap, errorList){
// place you validation error summary rendering code here
});
}
});
Now if you had a javascript function bound to the input element's keyup, input events your call to validate the value of the input element could be similar to the following javascript:
$( "#input1" ).bind( "keyup input", function(e) {
myValidator.element( "#input1" );
}
});
Now the custom rule part. Take for instance you wanted to prevent a value to be submitted that was already on display in a different element on the form. Instead of performing server side validation or making a separate ajax call, add a custom validation method to the jQuery Validation plugin. (The syntax is available at http://jqueryvalidation.org/jQuery.validator.addMethod/).
// Place custom validation rule here
// addMethod ( method-name-string, function(value, element){
// validation code
//}, validation-message-string );
// e.g.
$.validator.addMethod( "notequalto", function( value, element ) {
var currentVal = $( "#txtBoxCurrentValue" ).text();
if ( value === currentVal ) {
return false;
} else {
return true;
}
}, "That value is already set" );
Now update you rules section for input1 in your validator object to be:
rules: {
input1: { // selector of your textbox
digits: true,
minlength: 9,
maxlength: 9,
notequalto: true, // no quotes around the new method name, must validate to true
messages: {
digits: "Value has to be a number",
minlength: $.validator.format("Value {0} is to low"),
maxlength: $.validator.format("Value {0} is too high")
}
Now you have a custom validation rule for comparing a value against another Html element on the same form. Happy validating!
Labels:
javascript,
jQuery,
mvc

