Skip to content

Instantly share code, notes, and snippets.

View donfanning's full-sized avatar
🗃️
Holding up libraries and robbing them blind for the future.

Don Fanning donfanning

🗃️
Holding up libraries and robbing them blind for the future.
View GitHub Profile
# Date formats
Time::DATE_FORMATS.merge!(
:friendly_date => lambda {|d| "#{d.month}/#{d.mday}" }, # 4/25 (no leading zeroes)
:friendly_time => lambda {|t|
date = (t.at_midnight == Time.now.at_midnight) ? '' : "#{t.month}/#{t.mday}@" # 4/25@4PM on other days
"#{date}#{t.strftime('%I').to_i}#{t.strftime('%p')}" # 4PM on same day
},
:year => "%Y", # 2008
:month_year => "%b %Y", # Apr 2008
:ampm_time => "%I:%M %p", # 04:15 PM
@donfanning
donfanning / cc.php
Created August 15, 2018 14:19 — forked from cam-gists/cc.php
PHP: Credit Card Validation Class
<?php
class CardValidation {
public $valid = false;
public $valid_cc;
public $valid_cc_type_pair;
public $valid_ccv_type_pair;
public $error;
public function validate($cc, $type = false, $ccv = false) {
@donfanning
donfanning / crawled_url_spec.rb
Created August 15, 2018 13:55 — forked from devton/crawled_url_spec.rb
CrawledUrlSpec
require 'rails_helper'
RSpec.describe CrawledUrl, :type => :model do
describe ".persist_from" do
let(:url) { 'http://www.foo.bar.com/foo-bar#lorem?ipsum=dolor' }
let(:attributes) { ::Crawler::UrlParser.parse url }
subject { CrawledUrl.persist_from url }
context "when url already persisted" do
@donfanning
donfanning / async-phantom.js
Created August 15, 2018 13:29 — forked from penk/async-phantom.js
Parallel crawler example using PhantomJS and Aysnc.js
// usage: phantomjs async-phantom.js
var async = require('async'),
links = [
"http://google.com",
"http://yahoo.com",
"http://duckduckgo.com",
"http://bing.com",
];