Skip to content

Instantly share code, notes, and snippets.

View clover-device-list.js
const configuration = {
domain: 'https://clover.com/',
merchantId: 'private',
oauthToken: 'private'
};
const devicesUrl = configuration.domain +
"v3/merchants/" + configuration.merchantId +
"/devices?access_token=" + configuration.oauthToken;
View gooten-photo-source.coffee
onPhotoSourceReq: (request, callback)->
photos = []
$.getJSON('/api/v1/moments/photos', (moments)->
if moments.length > 0
photos = _.flatten(_.map(moments, (m)->
return _.map(m.photos, (p)->
return p
)
))
@t2
t2 / ssh-git-push
Last active Jan 8, 2020
Github & Bitbucket (SSH) - Port 22 Blocked
View ssh-git-push
# vi ~/.ssh/config
Host github.com
Hostname ssh.github.com
Port 443
Host bitbucket.org
Hostname altssh.bitbucket.org
Port 443
@t2
t2 / sidekiq.config
Created Feb 11, 2015
Sidekiq on AWS ElasticBeanstalk (64bit Amazon Linux 2014.09 v1.1.0 running Ruby 2.1 (Puma))
View sidekiq.config
# Original: http://www.snip2code.com/Snippet/256399/Amazon-Elastic-Beanstalk-Sidekiq
commands:
create_post_dir:
command: "mkdir /opt/elasticbeanstalk/hooks/appdeploy/post"
ignoreErrors: true
files:
"/etc/rsyslog.d/11-sidekiq.conf":
mode: '000644'
content: |
EB_CONFIG_APP_LOGS=$(/opt/elasticbeanstalk/bin/get-config container -k app_log_dir)
@t2
t2 / birthday_liker.rb
Last active Sep 23, 2016
Like and Comment on every 'Happy Birthday' post on your Facebook feed at once.
View birthday_liker.rb
require 'date'
require 'koala'
class BirthdayLiker
FACEBOOK_TOKEN = 'your_oauth_key'
BIRTHDAY_WORDS = %w(birthday bday birfday birth born)
THANKS_OPTIONS = ['Thank you!', 'Thanks!', 'Appreciate it!']
DATE_TIME_FORMAT = '%Y-%m-%d'
def initialize(birthdate, opts={})
@t2
t2 / guild_metaprogramming_example.rb
Last active Dec 21, 2015
Simple example of using method missing to dynamically build out an object.
View guild_metaprogramming_example.rb
# Below I have a name class. It has no properties defined. I want to be able to dynamically
# build it into what I want. This allows me to not have to write code for every scenario, I can
# let the developer decide what it should include.
class Name
ALLOWED_NAME_PARTS = %w(prefix first middle last suffix)
def initialize(&block)
self.instance_eval(&block) if block_given?
end
@t2
t2 / beta_invite_rake_task.rb
Created Aug 21, 2013
Beta Invite Rake Task
View beta_invite_rake_task.rb
namespace :beta_invites do
namespace :phase_one do
desc 'Send Phase 1 Beta Invites to testers.'
task :all => :environment do
BetaInvite.all.uniq{|b| b.email}.each do |invite|
unless invite.email.blank?
email_message = BetaInviteMail.invitation(invite.email)
email_message.deliver
end
end
@t2
t2 / application.html.haml
Created Jun 1, 2013
Possible refactor using a decorator for application layout.
View application.html.haml
!!!
%html
%head
%title= title
= stylesheet_link_tag 'application', :media => 'all'
= stylesheet_link_tag '//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-combined.no-icons.min.css'
= stylesheet_link_tag '//netdna.bootstrapcdn.com/font-awesome/3.1.1/css/font-awesome.css'
= javascript_include_tag 'application'
/[if lte IE 8]
<script src="excanvas.compiled.js"></script>
@t2
t2 / Grabber.rb
Last active Dec 16, 2015
Script to pull down images from a resource I found on Reddit
View Grabber.rb
# You will need to install nokogiri and rubyzip gems
#
# gem install nokogiri
# gem install rubyzip
require 'nokogiri'
require 'open-uri'
require 'zip/zip'
IMAGES_URL = 'http://files.tinystudios.com/defaults/images/'
@t2
t2 / application.rb
Created Dec 12, 2011
Formatting Rails form elements for Twitter Bootstrap error validation
View application.rb
ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
html = %(<div class="field_with_errors">#{html_tag}</div>).html_safe
# add nokogiri gem to Gemfile
elements = Nokogiri::HTML::DocumentFragment.parse(html_tag).css "label, input"
elements.each do |e|
if e.node_name.eql? 'label'
html = %(<div class="clearfix error">#{e}</div>).html_safe
elsif e.node_name.eql? 'input'
if instance.error_message.kind_of?(Array)
html = %(<div class="clearfix error">#{html_tag}<span class="help-inline">&nbsp;#{instance.error_message.join(',')}</span></div>).html_safe