Skip to content

Instantly share code, notes, and snippets.

@davidlfox
davidlfox / Program.cs
Created October 26, 2024 03:21
how to organize generated regex partials and use them elsewhere
using System.Text.RegularExpressions;
namespace GeneratedRegexTest;
public static partial class RegexUtilities
{
// define a partial, parameterless method with GeneratedRegex attribute
// pattern to match SSN format (e.g. 123-45-6789)
[GeneratedRegex(@"\b\d{3}-\d{2}-\d{4}\b")]
public static partial Regex SsnRegex();

Keybase proof

I hereby claim:

  • I am davidlfox on github.
  • I am davidfox (https://keybase.io/davidfox) on keybase.
  • I have a public key ASCaDM08-Dro3Va2fO-TFb1EjL7Y6vrv7_6PLGf6A3KJBAo

To claim this, I am signing this object:

array(1) { ["node"]=> array(3) { [57]=> object(stdClass)#72 (3) { ["nid"]=> string(2) "57" ["vid"]=> string(2) "57" ["type"]=> string(14) "carousel_image" } [18]=> object(stdClass)#103 (3) { ["nid"]=> string(2) "18" ["vid"]=> string(2) "18" ["type"]=> string(14) "carousel_image" } [70]=> object(stdClass)#105 (3) { ["nid"]=> string(2) "70" ["vid"]=> string(2) "70" ["type"]=> string(14) "carousel_image" } } } 1
@davidlfox
davidlfox / block
Last active August 29, 2015 14:27
attempting to fetch a set of drupal content nodes, ordered by field_weight property
$query = new EntityFieldQuery();
$entities = $query->entityCondition('entity_type', 'node')
->propertyCondition('type', 'carousel_image')
->propertyCondition('status', 1)
->fieldOrderBy(‘field_weight', 'ASC')
->execute();
$nodes = node_load_multiple(array_keys($entities['node']));
@davidlfox
davidlfox / Capfile
Last active August 29, 2015 14:11
capistrano v3 restart resque workers
require 'capistrano/setup'
require 'capistrano/deploy'
require 'capistrano/rvm'
require 'capistrano/rails'
require "capistrano-resque"
Dir.glob('lib/capistrano/tasks/*.cap').each { |r| import r }
@davidlfox
davidlfox / SalaryDocument.cs
Created September 8, 2014 19:45
ES doc type with abstract classes?
[ElasticType(Name = "blsdata")]
public class SalaryDocument : IElasticSearchDocumentType<string>
{
public SalaryDocument()
{
}
/// <summary>
/// document id
@davidlfox
davidlfox / error.txt
Created July 29, 2014 12:00
rails balanced troubleshooting
undefined local variable or method `card_href' for #<PayController:0x00000105199190>
bombing on this line:
card = Balanced::Card.fetch(card_href)
@davidlfox
davidlfox / chore.rb
Last active August 29, 2015 14:03
decorate associations with draper
class Chore < ActiveRecord::Base
belongs_to :user
has_many :taken_chore
scope :available, -> { where(:available => true) }
scope :ordered, -> { available.order(created_at: :desc) }
end
@davidlfox
davidlfox / chores_controller.rb
Last active August 29, 2015 14:03
need AR query for null parent field or non-null parent field and no related child records
def search
@chores = Chore.available
if search_params[:search_text]
@chores = @chores.where('description LIKE ?', "%%%s%" % search_params[:search_text])
elsif search_params[:zipcode]
@chores = @chores.where('location LIKE ?', "%%%s%" % search_params[:zipcode])
end
@chores = @chores.order(created_at: :desc).all
@davidlfox
davidlfox / chore.rb
Created June 19, 2014 01:27
rails validation error with decimal
class Chore < ActiveRecord::Base
belongs_to :user
belongs_to :category
validates :price, :format => { :with => /\A\d{1,9}\.\d{0,2}\z/, :message => 'regex failed'}, :numericality => {:greater_than => 0}
validates :category, presence: true
validates :user, presence: true
end