Skip to content

Instantly share code, notes, and snippets.

View alassek's full-sized avatar

Adam Lassek alassek

View GitHub Profile
@alassek
alassek / application_controller.rb
Created May 5, 2014 22:00
SSL Auth for Services
class ApplicationController < ActionController::Base
before_filter :require_authentication
private
def require_authentication
unless current_certificate.verify(public_key)
head :forbidden
end
end
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);
}
/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
activesupport (3.0.3) lib/active_support/dependencies.rb:304:in `depend_on'
activesupport (3.0.3) lib/active_support/dependencies.rb:216:in `require_dependency'
actionpack (3.0.3) lib/abstract_controller/helpers.rb:148:in `modules_for_helpers'
actionpack (3.0.3) lib/abstract_controller/helpers.rb:144:in `map!'
actionpack (3.0.3) lib/abstract_controller/helpers.rb:144:in `modules_for_helpers'
actionpack (3.0.3) lib/action_controller/metal/helpers.rb:101:in `modules_for_helpers'
actionpack (3.0.3) lib/abstract_controller/helpers.rb:97:in `helper'
actionpack (3.0.3) lib/abstract_controller/helpers.rb:161:in `default_helper_module!'
actionpack (3.0.3) lib/abstract_controller/helpers.rb:24:in `inherited'
actionpack (3.0.3) lib/abstract_controller/helpers.rb:24:in `class_eval'