Skip to content

Instantly share code, notes, and snippets.

View alassek's full-sized avatar

Adam Lassek alassek

View GitHub Profile
@alassek
alassek / ModernButton.cs
Created February 24, 2009 22:37
ASP.Net Button control that renders with Button tag instead of input
[ParseChildren(false)]
public class ModernButton : WebControl
{
//Fields
private static readonly object EventClick;
private static readonly object EventCommand;
//Events
public event EventHandler Click;
public event CommandEventHandler Command;
public static class Extensions
{
public static bool IsNumeric(this String value)
{
return Regex.IsMatch(value, @"^\d+$");
}
public static string Numeric(this string value)
{
return Regex.Replace(value, "\\D", String.Empty);
String.prototype.padLeft = function(length, s) {
var pad = [];
var padding = length - this.length;
if (padding > 0) {
for (i = 0; i < padding; i++) pad.push(s);
return pad.join('') + this;
}
return this + '';
}
//case-insensitive selector for ASP.Net ID's
//usage: $(':aspnetid(id)')
jQuery.extend(
jQuery.expr[":"],
{
aspnetid: function(a, i, m) {
return (new RegExp(m[3] + '$', 'i')).test(jQuery(a).attr('id'));
}
}
private bool ValidEmailAddress(string emailAddress)
{
string qtext = "[^\\x0d\\x22\\x5c\\x80-\\xff]"; // <any CHAR excepting <">, "\" & CR, and including linear-white-space>
string dtext = "[^\\x0d\\x5b-\\x5d\\x80-\\xff]"; // <any CHAR excluding "[", "]", "\" & CR, & including linear-white-space>
string atom = "[^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-\\x3c\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+"; // *<any CHAR except specials, SPACE and CTLs>
string quoted_pair = "\\x5c[\\x00-\\x7f]"; // "\" CHAR
string quoted_string = string.Format("\\x22({0}|{1})*\\x22", qtext, quoted_pair); // <"> *(qtext/quoted-pair) <">
string word = string.Format("({0}|{1})", atom, quoted_string); //atom / quoted-string
string domain_literal = string.Format("\\x5b({0}|{1})*\\x5d", dtext, quoted_pair); // "[" *(dtext / quoted-pair) "]"
export:
foreach ($n in (1..15)) { cmd.exe /c "mysqldump -u root --password={password here} s88franchise$n > s88franchise$n.sql" }
import:
foreach ($n in (1..15)) { cmd.exe /c "mysql -u root --password={password here} s88franchise$n < s88franchise$n.sql" }
import (bash):
// http://blog.stevenlevithan.com/archives/faster-trim-javascript
function trim12 (str) {
var str = str.replace(/^\s\s*/, ''),
ws = /\s/,
i = str.length;
while (ws.test(str.charAt(--i)));
return str.slice(0, i + 1);
}
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
Response.AddHeader("Refresh", Convert.ToString((Session.Timeout * 60) - 10));
}
</script>
/Users/adam/.rvm/gems/ruby-1.8.7-p299@rails3/gems/activerecord-3.0.3/lib/active_record/connection_adapters/mysql_adapter.rb:22:in `mysql_connection': !!! Missing the mysql2 gem. Add it to your Gemfile: gem 'mysql2' (RuntimeError)
from /Users/adam/.rvm/gems/ruby-1.8.7-p299@rails3/gems/activerecord-3.0.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:228:in `send'
from /Users/adam/.rvm/gems/ruby-1.8.7-p299@rails3/gems/activerecord-3.0.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:228:in `new_connection'
from /Users/adam/.rvm/gems/ruby-1.8.7-p299@rails3/gems/activerecord-3.0.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:236:in `checkout_new_connection'
from /Users/adam/.rvm/gems/ruby-1.8.7-p299@rails3/gems/activerecord-3.0.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:190:in `checkout'
from /Users/adam/.rvm/gems/ruby-1.8.7-p299@rails3/gems/activerecord-3.0.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:
@alassek
alassek / bash_tricks.sh
Created November 22, 2010 22:58
Shell commands for complicated operations
# batch-rename files by extension less -> scss
for f in *less ; do mv $f `basename $f less`scss; done