Skip to content

Instantly share code, notes, and snippets.

View danesparza's full-sized avatar
:octocat:
The best way to predict the future is to invent it - Alan Kay

Dan Esparza danesparza

:octocat:
The best way to predict the future is to invent it - Alan Kay
View GitHub Profile
@danesparza
danesparza / gist:973917
Created May 16, 2011 03:58
HTML 5 local storage - Javascript
// First, make sure our browser supports HTML 5 local storage
if (typeof(localStorage) == 'undefined' )
{
alert('Your browser does not support HTML5 localStorage. Try upgrading.');
}
else
{
try
{
// saves to the database using key/value
@danesparza
danesparza / gist:973919
Created May 16, 2011 03:59
Using SQL tinyint columns in C#
DataSet ds = GetDataSetFromStoredProc("stored_proc_name", new SqlParameter("@parameter_name", value_id));
var retItems = from dstable in ds.Tables[0].AsEnumerable()
select new ClassThing()
{
PrimaryKeyId = dstable.Field<int>("some_column_name")
};
@danesparza
danesparza / gist:973923
Created May 16, 2011 04:02
Gravatar in C# - creating the hash
using System.Security.Cryptography;
/// Hashes an email with MD5. Suitable for use with Gravatar profile
/// image urls
public static string HashEmailForGravatar(string email)
{
// Create a new instance of the MD5CryptoServiceProvider object.
MD5 md5Hasher = MD5.Create();
// Convert the input string to a byte array and compute the hash.
@danesparza
danesparza / gist:975068
Created May 16, 2011 18:59
Gravatar url examples
Format:
http://www.gravatar.com/avatar/{md5 hash}
Example:
http://www.gravatar.com/avatar/73543542128f5a067ffc34305eefe48a
@danesparza
danesparza / gist:975071
Created May 16, 2011 19:00
Gravatar images - using the hash
// Compute the hash
string hash = HashEmailForGravatar(email);
// Assemble the url and return
return string.Format("http://www.gravatar.com/avatar/{0}", hash);
@danesparza
danesparza / gist:975079
Created May 16, 2011 19:03
ASP.NET MVC2 custom validation helper - C#
/// <summary>
/// If the given model field has validation errors, this will emit the given CSS class name
/// </summary>
/// <typeparam name="TModel"></typeparam>
/// <typeparam name="TProperty"></typeparam>
/// <param name="htmlHelper"></param>
/// <param name="expression"></param>
/// <param name="cssClassToEmit"></param>
/// <returns></returns>
public static MvcHtmlString ValidationCSSClassFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression, string cssClassToEmit)
@danesparza
danesparza / gist:975081
Created May 16, 2011 19:04
ASP.NET MVC2 custom validation helper - View code
<div id="email_tip" class="tip <%: Html.ValidationCSSClassFor(m=>m.Email, "error") %>" style="display: none;float: left;">
<%: Html.ValidationMessageFor(m=>m.Email) %>
</div>
var shoppingLists = from user in Users
join listUsers in ShoppingListUsers
on user.UserId equals listUsers.UserId
join lists in ShoppingLists
on listUsers.ShoppingListId equals lists.ShoppingListId
where user.UserId == userToFind.UserId
select lists;
return shoppingLists;
@danesparza
danesparza / gist:975088
Created May 16, 2011 19:07
Delete data from multiple tables at once - SQL
begin transaction;
declare @deletedIds table ( id int );
delete t1
/* Notice this next line is using the 'deleted' pseudo table: */
output deleted.id into @deletedIds;
from table1 t1
join table2 t2
on t2.id = t1.id
@danesparza
danesparza / gist:975091
Created May 16, 2011 19:09
jQuery UI transfer effect - javascript
// Use transfer effect
$("#txtProduct").effect("transfer", { to: $("#test") }, 1000);