Skip to content

Instantly share code, notes, and snippets.

yum install autoconf automake bzip2 bzip2-devel cmake freetype-devel gcc gcc-c++ git libtool make mercurial pkgconfig zlib-devel -y
cd /usr/src/
mkdir ffmpeg_sources
# nasm
cd /usr/src/ffmpeg_sources
curl -O -L https://www.nasm.us/pub/nasm/releasebuilds/2.14.02/nasm-2.14.02.tar.bz2
tar xjvf nasm-2.14.02.tar.bz2
cd nasm-2.14.02
./autogen.sh

Keybase proof

I hereby claim:

  • I am chrisfinne on github.
  • I am chrisfinne (https://keybase.io/chrisfinne) on keybase.
  • I have a public key ASCMyEvQ2uNEGLxSgPppGzfESWEIPG9DW1LvcNuyowZ-jQo

To claim this, I am signing this object:

@chrisfinne
chrisfinne / persisted_custom_pk_bug.rb
Created March 15, 2014 10:30
ActiveRecord Bug: AR .persisted? throws SystemStackError for an unsaved model with a custom primary_key that didn't save due to validation error
# AR .persisted? throws SystemStackError for an unsaved model with a
# custom primary_key that didn't save due to validation error
gem 'activerecord', '4.1.0.rc1' # in HEAD too
require 'active_record'
require 'minitest/autorun'
require 'logger'
# Ensure backward compatibility with Minitest 4
Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test)
@chrisfinne
chrisfinne / string_extension.rb
Last active January 4, 2016 13:28
validate us canada phone number
class String
def is_us_phone?
!!(self.gsub(/\D/,'') =~/\A1?\d{10}\z/)
end
def to_us_phone
return nil unless is_us_phone?
s = self.gsub /\D/,''
s[0,1]=='1' ? s[0,11] : '1'+s[0,10]
@chrisfinne
chrisfinne / gist:5694324
Created June 2, 2013 18:08
ruby class vs. instance method
>> class Foo
>>
?> def self.bar
>> "i'm a class method"
>> end
>>
?> def bar
>> "i'm an instance method"
>> end
>>
@chrisfinne
chrisfinne / gist:1835150
Created February 15, 2012 11:20
Ruby TMail detect HTML in plain text or escaped HTML
class TMail::Mail
def bad_html?
if multipart?
return true if parts.detect{|p| p.content_type.include?('text/plain') && p.to_s =~ /<(html|head)/im }
return true if parts.detect{|p| p.to_s =~ /&lt;\/(p|a|span|div|style|head|html)&gt;/im }
else
return true if body =~ /&lt;\/(p|a|span|div|style|head|html)&gt;/im
return true if content_type.include?('text/plain') && body =~ /<(html|head)/im
end
false
@chrisfinne
chrisfinne / gist:1446662
Created December 8, 2011 10:30
Is a US number SMSable?
class String
# http://en.wikipedia.org/wiki/North_American_Numbering_Plan
@@bad_phones = 0.upto(9).collect{|t| t.to_s*10} + ['231231234']
def is_smsable?
return false unless self.is_phone?
return false if self.gsub(/[0123456789\-\.\+\(\) ]/,'').present? # non-phone number chars are present
return false if self =~ /\A\s*\+\s*[^1\s]/ # International number
us_ten = self.gsub(/\D/,'').gsub(/\A1/,'')
return false if us_ten.size != 10
@chrisfinne
chrisfinne / gist:1099504
Created July 22, 2011 13:58
Ruby/Rails - Initialize BigDecimal with commas in the String
class BigDecimal
class << self
def new_with_commas(*args)
if args.first.is_a?(String) && args.first=~/,/
args.first.gsub!(',','')
end
new_without_commas(*args)
end
alias_method_chain :new, :commas
end
class Foo < SimpleRecord::Base
has_dates :started_at
end
f1=Foo.create :started_at=>Time.now
sleep(1)
Foo.connection.get_attributes(Foo.table_name, f1.id)[:attributes]['started_at'][0]
=> "2010-04-14T22:24:56"
f2=Foo.create :started_at=>DateTime.now
sleep(1)
def test_ascii_http_post
first_name = "joe" + ("X" * 1000) # pad the field to help get the URL over the 2000 length limit so AWS uses a POST
last_name = "blow" + ("X" * 1000) # pad the field to help get the URL over the 2000 length limit so AWS uses a POST
mm = MyModel.create :first_name=>first_name, :last_name=>last_name
mm.save
sleep 1
assert mm.first_name == first_name
assert mm.last_name == last_name
mm2 = MyModel.find(mm.id)
assert mm2.first_name == first_name