Wednesday, December 16, 2009

Safari THead Issue

I'm not sure if this is an actual issue.

I'm using a .css file, and styling a table.

I'm using the tag thead.

I had two rows in thead.

I wanted to sort the table by column.

On sorting asc, make the border-top-style have a solid 1px #color.
On sorting desc, make the border-bottom-style solid 1px #color.

When you have two rows in thead, and sorting the first column on the second row,

Safari will give a border to the entire second row.

SOLUTION:

Remove the first row from head.

Monday, December 14, 2009

CSS change children with JQuery

I wanted to be able to change the children's css of an element with JQuery.

In a table, for instance, I wanted to change the data rows as the user's mouse and . I was using
$("#tr").mouseleave(function(){
$(this).children().css = "...";
});

This even changed rows that were header rows.

I had more than one table on the page, so accessing an id isn't efficient or practical.

I created a class in css, tableHead, and set the rows containing the th to this class.

Then in JQuery, after $(this).children().css = "";

$(".tableHead").children().css = "..";

This changed everything with the class "tableHead" to the new css.

MySQL Including Null values in a Query

I wanted to query a database for a table that references other tables.

(a -> b) ; (a -> c)

Some of the references from a -> b are null. I wanted to include the maches for a.id = 'id' anyway.

The key is to create a table in the SELECT segment of the query.

SELECT
a.id
a.name
(SELECT b.name FROM b WHERE b.id = a.bRefId) AS NullRefCol,
a.otherCol
FROM
a
WHERE
a.status = 'active'

This query will return all 'a's that have a status that is 'active' even if the reference to 'b' is null.

Tuesday, December 8, 2009

Great JQuery Websites

Collection of JQuery Tutorials

http://technosiastic.wordpress.com/2009/09/24/collection-of-top-jquery-tutorials-tips-tricks-techniques-to-improve-performance/

JQuery for Designers

http://jqueryfordesigners.com/

Wednesday, December 2, 2009

Finally, answers to how Controllers know about variables on a View

So, it's taken a while, but I've finally figured out how views variables and controllers work, with AJAX.

Ok,

For a controller method to see the value of a tag on a view, you must create a "<[percent]=HTML" tag. You can't just create a regular html tag, you must use the MVC ASP.NET helper.

It Must be in the AJAX form that you are submitting. It cannot be outside the form or the method will not see it.

They method sees the NAME you give the helper tag, NOT the id. So you can have multiple tags with the same name. This is helpful when you want to ajax a lot of functionality but need to keep the same tags but change the values, like knowing which view the user is currently on.

On Complete for AJAX happens when the form is finished submitting, NOT when it finishes loading.

Dec 7, 2009 - It, also, appears that initializing a Html.Hidden(...) field with a @value=".." will not be sent to the server. In other words, if you give @value="..." in the html attributes, the "..." will not be seen on the server. I've found that you must change the value in javascript.

Hope this helps.

Tuesday, December 1, 2009

Common IE bugs for Web Developers

Thanks Tuts+ -> nettuts

http://net.tutsplus.com/tutorials/html-css-techniques/9-most-common-ie-bugs-and-how-to-fix-them/

Friday, November 20, 2009

JQuery Stuff

$(document).ready(function(){
// your code
});

Put this in your script type=".../javascript" to execute code before the page finishes loading.

********************************

$("[element name]").addClass("[css class name]");

This adds a css class to all elements of that element type.

********************************

For great JQuery effects

http://docs.jquery.com/Effects


********************************


$("a").click(function(event){ event.preventDefault(); $(this).hide("slow"); });


Example of using an effect.

Thursday, November 19, 2009

Browser Shots, looking at your website on various browsers.

A good website for checking your website on various browsers is

www.browsershots.org.

Wednesday, November 18, 2009

C# Regular Expressions

'*' Matches 0 or more patterns.
(e.g. "*[a]" matches 0 or more 'a's)

'+' Matches 1 or more patterns.
(e.g. "+[a]" matches 1 or more 'a's)

'?' Matches 0 or 1 pattern.
(e.g. "?[a]" matches 0 or 1 'a')

'^' Ignores a pattern.
(e.g. "^a" ignores 'a's)
Also, can be used to signify the start of a string.
(e.g. "^[0-9]" will match a string starting with number)

'[]' Used for range patterns.
(e.g. "[0-9]" matches any number between 0 and 9)

'.' will match any character except '\n'.
(e.g. "a.." matches any 3 letter word starting with 'a')

'\d' matches a digit.
(e.g. "\d"matches any 1 character number)

'$' matches the end of a string.
(e.g. "$[a]" matches a string ending in a)


Monday, October 26, 2009

Apple Safari error exception 0xc000000005

I tried to open Safari and it would close and give me an error. It would not stay open for more than 30 seconds.

Running XP SP3

To fix, I had to uninstall safari and delete all history, temp, source files from my harddrive. Uninstalling did not do this. I had to do it manually.

Afterwards, Safari works.

Thursday, October 22, 2009

PHP, Print all $_Post/$_Get Variables

To print all the (Post and Get) variables do...

print_r($_GET);
print_r($_POST);

Wednesday, October 14, 2009

PHP5 and Apache 2

Put the php.ini file in ../Apache2/;


php.ini

doc_root = "C:\Apache\Apache\htdocs\"


httpd.conf

LoadModule php5_module C:/php/php5apache2.dll
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

Tuesday, September 22, 2009

C# Directory.GetFiles(string, string)

I wanted to find files in a directory with a sub string in the name "obj".

There is a list of files in the directory ...0bj_????.xsd.

The way to do this is

Directory.GetFiles(path, "obj_*.xsd");

Friday, September 11, 2009

XML and Streams with C#

I wanted to write xml to a stream and back because of the XMLDocument think.

You can go back and forth from XMLDocuments to Streams by:

MemoryStream streamName = new...();

streamName.Write( [ innerXML as byte array ], 0, [size of array]);

XMLDocument document = new ...();

document.Load(streamName);


Now you have a xmldocument.

Friday, September 4, 2009

WCF Service, C#

I wanted to create a WCF service in C#.

Communication was the problem. After creating the service, and implementing the method properly, you must either create a new project in the solution or have a console implementation in the project with the service. In order to communication with the service you must have a console.

This is on the SERVICE side.

using System.ServiceModel;
using System.ServiceModel.Description;
using [SolutionNamespace].[NamespaceList].SimpleService;

class Program
{
static void Main(string[] args)
{
Uri baseAddr = new Uri("http://localhost:8080/SimpleService.svc");
ServiceHost localHost = new ServiceHost(typeof(SimpleService), baseAddr);

try
{
localHost.AddServiceEndpoint(typeof(ISimpleService), new WSHttpBinding(), "SimpleName");

ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
smb.HttpGetEnabled = true;
localHost.Description.Behaviors.Add(smb);

localHost.Open();

Console.WriteLine("Server's up...");
Console.ReadLine();
localHost.Close();
}
catch (Exception ex)
{

}
}
}

SimpleService is the class that implements ISimpleService. ISimpleService is the ServiceContract for WCF. "SimpleName" is just a name string.



For the client, you must add a Service Reference to the WCF service. You can name it what ever, but every example I have seen has named it exactly what the service implementation is called. This was quite confusing. You can reference this service inside your console class. SimpleService is the name of the reference inside the CLIENT.
The namespace is the reference to the Service References that the service is referenced by.

This is the CLIENT side.

using [SolutionNamespace].[namespaceList].SimpleService;

class Program
{
static void Main(string[] args)
{
SimpleService client = new SimpleService();

try
{
string data = client.GetData(1);
Console.Write(">:" + data);
Console.ReadKey();
}
catch (Exception ex)
{

}
}
}

This will allow the two to communication between solutions.

Thursday, August 27, 2009

Undo framework in C#

There are two pages for a good undo framework.

http://blogs.msdn.com/kirillosenkov/archive/2009/07/02/samples-for-the-undo-framework.aspx
http://blogs.msdn.com/kirillosenkov/archive/2009/06/29/new-codeplex-project-a-simple-undo-redo-framework.aspx

Wednesday, August 26, 2009

Inserting a picture into an Excel Spreadsheet using C#

sheet1.Shapes.AddPicture(
path,
true, // this is to copy the picture into the sheet and not link the picture.
true,
##, // how far right you want the picture (in pixels)
##, // how far down you want the picture (in pixels)
##, // width of the picture
## // height of the picture
)

Saturday, August 22, 2009

MySql Server ERROR 1045

I had Error 1045 with installing MySQL server on an XP machine. I, also, have Visual Studio with Sql server installed. I had to stop that SQL server for MySQL to install correctly.

Friday, August 21, 2009

Angle Formula for a circle.

On a circle, if the absolute value of the difference of the angles is greater than 180, you may want to find an average angle that is no always in the clockwise direction. For instance...

angle a = 47
angle b = 326

To find the average angle in the counterclockwise direction

(((360 + a + b) / 2 ) % 360)

This will give you the correct angle between the two, in the CCW direction.

Thursday, August 13, 2009

Dictionary ordering C#

I just found out that Dictionary for C# has no order. So, you can add them any way you want, but you can't get them back the way you expect, because there is no "index" order to them.

Friday, July 31, 2009

C#, Microsoft.Office.Core

In order to include Microsoft.Office.Core into your C# project, you need to add a reference to

Office

It's not Microsoft.Office, just Office, which is confusing.

Creating an Image from a User Control - C#

I wanted to create an image from a "screen shot" of my user control. I wanted to be able to save a picture of the user control at any given moment, save that image to a file for later use.

It's easy!

1. Create a Bitmap object of the size of your control.
Bitmap picture = new Bitmap (800, 600);

2. Create a Graphics object from the Bitmap Object.
Graphics graphx = Graphics.FromImage(picture);

3. Draw your user control to the Graphics object.
CreateControl(graphx);

4. Save your picture to a file.
picture.Save(@"C:\ControlImage.bmp");

It's that simple!

Monday, July 20, 2009

Graphics, Form Double Buffer

I was trying to double buffer a graphic control I wrote. It would blink when redrawing. I was not double buffering because, the graph would not draw. I was using the control's CreateGraphics() method. You should use the e.CreateGraphics() on the paint event. This allows you to use the double buffer without the error of not drawing.

Monday, July 13, 2009

Checked C# overflow

Using the 'checked' keyword in C#, you can check for an overflow.

checked
{
int a = someInt * someOtherInt;
}

This will check if there is an overflow.

You cannot check a nested method or something similar.

checked
{
int a = SomeMethod(b, c);
}

This will not check for overflow.

If you nest the check block in a try-catch. You can catch the overflow error.

try
{
checked
{
int a = someInt * someOtherInt;
}
}
catch (OverflowException)
{
// do something.
}

This is how to check for an overflow.

Friday, July 10, 2009

Drawing C#

C# drawing methods only take 16 bit points.

This is very limiting when it comes to drawing large scale graphics.

C# Nullable Structs

You can make a struct type nullable by adding a ? at the end of the type.

(e.g
Point? myNullablePoint = ...
int? myNullableInt = ..
)

and so on..

Thursday, July 9, 2009

Point C#

Points are structs and not nullable.

Just thought you should know.

Tuesday, June 23, 2009

CSV File Delimiters

In a *.csv file, a comma and newline characters are main delimiters. The escape character for csv files is the double-quotes.

Thursday, June 18, 2009

List.Contains(T obj)

I don't think it is worth using this on most occasions.

First, this is BigO(n), which is the same as linearly searching the list.

Secondly, if you have a complex object, you must implement IEqualityComparer interface, which only has a GetHashCode method, which returns an int.

I don't think this is too useful.

Error 1 Inconsistent accessibility: parameter x type is less accessible than method y

I was trying to pass an interface type to a method.

public void MyMethod(IMyInterface myI)
{
// ...
}

Make the interface public

public interface IMyInterface
{
// ..
}

This should solve this problem.

Tuesday, June 16, 2009

C# 3.5 ParameterizedThreadStart

I wanted to create a Thread that would take a parameter to do concurrency in my project.

This is how I did it.
Thread is in the namespace System.Threading

{
Thread newThread = new Thread(new ParameterizedThreadStart([MethodName]);
newThread.Start([parameter]);
}

[MethodName](object [parameter])
{
// do something
}

So, the key is making the parameter object type. In the method that you created a new thread, convert the object into the datatype that it is.

Monday, June 15, 2009

Question Mark Operator C#

The question mark operator is a 'ternary' operator that allows a conditional statement to be written in one line.

if a function returns a boolean :

return someVar == anotherVar ? true : false;

is equivalent to

if(someVar == anotherVar)
{
return true;
}
else
{
return false;
]

Friday, June 12, 2009

Loading Gif with ASP.NET MVC and AJAX

I wanted a loading gif to show while the webapp was doing work. It would take a while. I, also, wanted the gif to go away once the response came back to the user.

Put the loading gif in the div that is replaced. I thought it was a good idea.

User download a file ASP.NET MVC with AJAX

I wanted the user to be able to download a file, using ASP.NET MVC with AJAX. The problem wasn't downloading, or AJAX. It was the two together.

It's really simple. What you need to do is get the path of the file to download, put the value in ViewData and make an href to that file with value "Download" to target="_blank". This will show a popup to download the file.

[lt]a href='[lt]%=path%[gt]' target="_blank" [gt] Download [lt]/a[gt]

[lt] = "<"
[gt] = ">"

Thursday, June 11, 2009

Show Loading gif on button click

I wanted to show a loading gif on a user button click, because the action would take a while. So this is the solution I found.



You make the div style.display = "none;" then on button click, you set the style.display = "";

Wednesday, June 10, 2009

Current Directory Path C#

I wanted to get the current directory in a ASP.NET MVC application on the c# side.

System.Environment.CurrentDirectory

-- gets or sets the fully qualified directory.

HOWEVER, this may not be what you are looking for as, this is sometimes

../ProgramFiles/MicroSoftVS/Common7/IDE/

Tuesday, June 9, 2009

ASP.NET MVC Dropdownlist Values on Server

I wanted to get the values directly from the dropdownlist on the server. For example, I wanted to make a drop down list, and when the user chose either one or multiple values, make a query on the server based on those values.

Well, you can't just write the "select" tag html and expect to get those values on the server. If you want to directly write the html tag, I had to make hidden fields, when the user chose a value in the dropdownlist, make the hidden field's value the value of the dropdownlist.

Well, there is a way. Use the html helper for a dropdownlist.

Before making the dropdownlist, make a dictionary of KeyValuePairs and Values.

The KeyValuePairs are the Key and Values, and the Values are just the values.

You can just make a dictionary and have just the key and values. This will work if you just need the keys on the server side.


The KeyValuePair is just if you want both the key and value on the server. If not, then just make a dictionary of string,string. Where the "new SelectList(d, 'Key', 'Value')" shows, the Key is what is sent to the server, and the value is what is shown to the user. You can change "Key" to "Value" and the value will be sent.

On the server side, you should have a List[string] Name as the variable to receive the data. It can be just "string" but you will only get the first selected key if multple are selected, where the list makes it possible to get all selected keys. If you send back a KeyValuePair as a key, then the values will look like "[key,value]".

Tuesday, June 2, 2009

ListBox in Html

List boxes in HTML are called 'select'. Each value is called 'option'. These 'select' and 'option' are tags with '<' and '>', but Blogger won't let you writing these explicitely.

A dropdownlist will be displayed unless you add ' size="###" ' as an attribute, where ### is greater than 1.




Monday, June 1, 2009

I.E. HTML Colors

I found out today that Firefox, Chrome, Opera, and Safari ( 3.0.3, 2.0.175, 9.63, 3.2.2) will accept the html shortcut for #808080 as 'grey', but I.E. 7.0.5 won't. I.E. will take 'gray'. I will resort to using the hex code from now on.

Friday, May 29, 2009

C# 3.5 Try-Catch-Finally

Will a 'Finally' block be executed if a return statement is called in a Try-Catch?

Yes, the 'Finally' block is always executed, even if a goto, or return statement is called.

Thursday, May 28, 2009

Active Armor Firewall UnInstall

I found out how to uninstall Active Armor firewall for the Asus M2N32-SLI DELUX motherboard. Under ControlPanel Add/Remove Programs on Windows XP Professional, the program to uninstall is NVIDIA Forceware Network Access Manager.  Uninstall this program and active armor will be uninstalled also.

Wednesday, May 27, 2009

Javascript Confirmation Dialog

I was trying to get verification from the user on a delete command. This may not be the correct solution.

I needed a button, when the user clicks, a pop-up form asking "Are you sure?" appears. If the user selects 'Cancel', nothing happens. If the user selects 'Ok', then the data is deleted.

I developed this solution:



I am using the submit, because I have a hidden field that is set with a value depending on what the user has chosen to do. This is the reason for doing nothing on 'ok' and something on 'cancel'.


*************************************************
11/25/2009

I think this is a more versatile solution.

//***************************************************
// Name: Form Submit
// Parameter [formId] : this is the Id of the form to
// submit.
// Parameter [verify] : 'true' if the form needs a
// confirmation before submitting, any other string
// if the form does not need confirmation.
// Parameter [message] : Message to show if the form
// needs validation.
//**************************************************
function formSubmit(formId, verify, message) {
if (verify == "true") {
if (confirm(message)) {
document.getElementById(formId).submit();
}
}
else {
document.getElementById(formId).submit();
}
}

MySQL Log

To have MySQL log queries on the database, you need to locate your mysql server folder,

usually C:/Program Files/MySQL/MySQL Server.../

In this folder, there should be a file named 'my.ini' or 'my.cnf'.

This file contains global options for the MySQL server.  You can modify this file with the 
'log="[Drive]:/[~Path]/[filename].log"' command.  Put this relatively close to the 

'[mysqld]' heading, but below it in the file.

Restart MySQL server.  You should find a [filename].log file where your path was set.

This is the log file for mysql server, it will log all queries on the databse.

If you want to log all errors, put this command close to the previous command,
'log-error="[Drive]:/[~Path]/[filename]error.log"'.  This will log all errors.

This is for my edition of MySQL Server 5.0.

Commands for Windows Command Prompt

This is a list of cool commands:

echo %windir%             - this command is for locating the Windows directory.
. - this command is for the current directory.
.. - this command is for the parent directory.

mysqld & Options

If you want to run the 'mysqld' command with its options, don't forget that you need 

'mysqladmin -u [username] -p[password] mysqld --[option]...'

You need to do the mysqladmin...username stuff or it won't work.  Yes, this seems common sense, but no one ever explains this part.  This is, also, an instruction for Windows command prompt and not mysql.

Friday, May 22, 2009

HTML input checkbox

The html input tag 'checkbox' will beck checked no matter what value it is set to the attribute 'checked'.  For instance,

checked='' ... or ... checked='checked' ... or ... checked='true' ... or ... checked='false'

will all set the checkbox to checked.

The 'checked=[value]' needs to be totally removed from the attribute list if a non-checked checkbox is desired.

Thursday, May 21, 2009

Restore MySQL Database

When restoring a database backed-up with mysqldump ...   don't use the 'mysqldump' command to restore.  

To restore the database use 'mysql'.

'mysql -u [name] -p[password] < [filename].sql'

Wednesday, May 20, 2009

MySQL Dump

I was trying to figure out how to use 'mysqldump', and there are a few KEY points that people leave out when trying to explain how to use it.

1.    DON'T be in mysql command line client when trying to use this command.  It seems common sense, but until you know, you don't.
2.   When trying to give the password -p option, make sure there is NO space between the -p and your password. (e.g mysqldump -u [name] -p[password] --all-databases > alldb.sql)
Notice how there is NO space between the 'p' and 'password'.  There was only one example that used this that I found.  Every other example showed a space.  It may work on MySQL 5.1+, but it does not work on my copy of MySQL 5.0.

Tuesday, May 19, 2009

Adding a DateTime to a MySQL database

I wanted to add a datetime in an ASP.NET MVC application talking to a MySQL database.  I needed the date in the correct format in order to add it to the database.

This is one way to do it.

The data "cell" that will hold the datetime needs to be a 'DATE' type in MySQL.  Then, the user can set the Month, Day and Year needed.  (e.g. 1/2/2009).

This is the format I used, but you can modify it as according to your application.

So, when adding the date to your database, during your query :

table.datecell = STR_TO_DATE(' " + dateVariable + " ', '%m/%d/%y')

The format %m/%d/%y is month/day/year.  This will set the value of the cell to the date and with a time.

Saturday, May 9, 2009

Replacing characters within strings with Javascript

I found out today how to replace characters within a string using Javascript.

It's not hard.

First, you take the string that has characters that need replacing.

You make a regular expression of the characters that need replacing. -> this uses the javascript RegEx("string") function.

You make a variable to hold the new string that is generated from the replacing.

You have a new string with replaced characters.

In the following example, I wanted to replace a string with the empty string, removing the unwanted characters.



temp will have the value of  "1,,3,4".

If you want to take the comma out, also, just put "2," into the regular expression function.

The regular expression function generates a regular expression that is understandable to javascript.  The first code would generate /2/ while the second code would generate /2,/.

Hope this helps.

Wednesday, May 6, 2009

Talking Point

There was just one thing I wanted to say to Ken (4100) about his "settings".

Tuesday, May 5, 2009

C++ list::iterator

So, I found out today that you can't do a "less than" comparison on list iterators.

For instance, if you want to iterate through a list with a for loop, you must do a != comparison, instead of a < comparison usually used in for loops.

for( list::iterator t = myList.begin(); t != myList.end(); t++)
{
// some code
}

This is a sample of proper code to iterate through a list using iterators.

Thursday, April 30, 2009

CHMOD, UNIX Permission

I tried to find a good example of how to give all permissions in chmod.
They are very hard to find.

If you want to give all permissions to all files in a directory type

chmod 777 * for all files without an extention
chomd 777 *.* for all files with an extention

hope this helps.

Monday, April 27, 2009

ASP.NET MVC Html.DropDownList

It took me a little while to figure out how to add custom items to an ASP.net MVC Html dropdownlist.  

It takes an IEnumerable of type SelectedList, not just any IEnumerable.  What I had to do was create a List and then make a SelectedList and put that List in the selected list for it to work.

Like this:


Thursday, April 23, 2009

ASP.NET MVC usercontrol

There are a few things I found out about ASP.Net MVC user controls.

1. The user control cannot be contained in asp:content blocks.  The code must be in "the open".
2. You can pass the ViewData as a parameter.
3. To render the user control you must:



4. You do not need the '.ascx' after the name of the view.

Friday, April 17, 2009

ASP.NET MVC HTML helpers attributes

In order to set attributes for html elements using
"Html.ActionLink(, , , )"

The attributes should be like
new { @attribute=value, ...})

an example of this would be:
new { @id=doneID, @class="invisible"})

The "doneID" is a string variable that was defined earlier in the ' ' of the page.
The @class value is just a string.



Monday, April 13, 2009

ASP.NET MVC Masterpage Image

I had a problem trying to figure out a way to display an image on a master page and have that image display on all child pages.

I could get it to show the image on all child pages in the IDE, but when I would publish, the image would not show.

My problem was fixed by creating a "class" in my Site.css file.
You can put this code anywhere in that file, but it would be good practice to group classes by logical function.

/*
SAMPLE
*/
.photo-container
{
padding:10px;
border:1px dotted #7a7a7a;
}

To display the image in the master page, this code worked for me.

Make a "div", make the "div" "class='photo-container'". style="width:auto;"> "img src="../../[Folder]/ [File].jpg" />

Type the code where you want your image to be. I hope this helps.

Saturday, April 11, 2009

In The Beginning...

This is my first blog post.

The purpose of this blog is to show and explain technical ideas and coding algorithms.

I have a "dark" them, because that is what I code in. I find it easier on the eyes.

Thanks,

Rybo