Skip to content

Instantly share code, notes, and snippets.

@emarthinsen
emarthinsen / scrape.rb
Created November 1, 2012 20:00
URL Scraper
def scrape_url(url)
url_found = false
twitter_name = nil
begin
agent = Mechanize.new do |a|
a.follow_meta_refresh = true
end
agent.get(normalize_url(url)) do |page
@emarthinsen
emarthinsen / subscription_factory.rb
Created December 6, 2012 04:01
Traits in Associations
(rdb:1) p FactoryGirl.build(:user, :pro, :active)
ArgumentError Exception: Factory not registered: [:subscription, :pro]
(rdb:1) p FactoryGirl.build(:subscription, :pro)
#<Subscription id: nil, user_id: nil, plan: "pro", renew_on: "2012-12-13", charge_on: "2012-12-13", failures: 0, created_at: nil, updated_at: nil>
@emarthinsen
emarthinsen / dashboard_observer.rb
Created January 3, 2013 05:42
Trying to get some custom AR callbacks to trigger corresponding handlers in an observer
class DashboardObserver < ActiveRecord::Observer
observe :user
def after_activate(user)
DashboardService.update_metrics
end
end
curl -X GET 'http://elasticsearch.local/listings/_search?pretty' -d '
{
"from": 0,
"size": 20000,
"query": {
"bool": {
"must": [
{"term": {"state":{"term":"active"}}},
{"term": {"account_type":{"term":"free"}}},
@emarthinsen
emarthinsen / controller.rb
Last active August 29, 2015 14:04
Trouble adding request headers in controller spec
class ApiController < ApplicationController
def index
# request.headers always equals {}
if request.headers['Authorization'] == 'HELLO'
render text: 'SUCCESS', status: :ok
else
render text: 'FAILURE', status: :unauthorized
end
@emarthinsen
emarthinsen / Error Message
Created October 18, 2014 02:56
Vector of function pointers
ex6.54.cpp:12:11: error: unexpected type name 'func': expected expression
vector<*func> funcPtrs;
^
1 error generated.
@emarthinsen
emarthinsen / script.cocoascript
Created February 1, 2016 22:28
Long-lived Plugin
var interval = null;
var onStart = function(context) {
[coscript setShouldKeepAround:true];
interval = [coscript scheduleWithInterval:1.0 jsFunction:function() {
log("In interval");
}];
};
'use strict';
module.exports = (event, context, callback) => {
console.log("Send the response: " + event.params.querystring.challenge);
callback(null, { challenge: event.params.querystring.challenge });
};
@emarthinsen
emarthinsen / .htaccess
Created June 9, 2018 19:34
.htaccess if directive to force basic auth on staging
<If "(%{HTTP_HOST} =~ /staging/) && ! (%{REQUEST_URI} =~ /privacy-policy$/)">
AuthType Basic
AuthName "Staging Area"
AuthUserFile /var/app/current/public/.htpasswd
Require valid-user
</If>
@emarthinsen
emarthinsen / .htaccess
Created June 9, 2018 21:00
Another .htaccess attempt
AuthType Basic
AuthName "Staging Area"
AuthUserFile /var/app/current/public/.htpasswd
Require valid-user
SetEnvIfNoCase HOST staging REQUIRE_AUTH
SetEnvIfNoCase Request_URI ^/privacy-policy$ !REQUIRE_AUTH
Order Allow,Deny
Allow from All
Deny from env=REQUIRE_AUTH