Skip to content

Instantly share code, notes, and snippets.

View marcamillion's full-sized avatar

Marc Gayle marcamillion

View GitHub Profile
@marcamillion
marcamillion / NYTPaywallWorkaround.md
Created August 29, 2021 23:02 — forked from FermiDirak/NYTPaywallWorkaround.md
Steps to get around NYT Paywall

A step by step guide wallthrough on how to access / read a NYT paywalled article

  1. Open the NYT article you want to read in incognito mode
  2. Open up your devtool console ([cmd][shift][j] on chrome/mac)
  3. Open up the devtools command prompt ([cmd][shift][P] on chrome/mac)
  4. Type in the command disable javascript into the command prompt, but don't hit enter
  5. Reload the page
  6. After the content loads but before the paywall appears, enter your disable javascript command
  7. If paywall persists, return to step 3. Otherwise, enjoy your free article.
  8. Happy reading!
@marcamillion
marcamillion / console.rb
Created March 27, 2013 15:50
Implementing HABTM counter_cache - between 2 models (Tag, Question)
## I imagine this could be done in the migration, but it was giving me problems so I moved it to the model
## and just did it on the command line
> Tag.reset_questions_count
<pre class="highlight ruby">
<p>def convert_relation(invited_gender, relation)<br>
case invited_gender<br>
when &quot;male&quot;<br>
case relation<br>
when &quot;daughter&quot;, &quot;son&quot; then &quot;dad&quot;<br>
when &quot;mom&quot;, &quot;dad&quot; then &quot;son&quot;<br>
when &quot;grandfather&quot;, &quot;grandmother&quot; then &quot;grandson&quot;<br>
when &quot;sister&quot;, &quot;brother&quot; then &quot;brother&quot;<br>
when &quot;wife&quot; then &quot;husband&quot;<br>
@marcamillion
marcamillion / finding-deleted-associated-records-by-inverse-using-where-not.rb
Last active December 23, 2015 11:30
Easily Find Polymorphically Associated Records whose destroy callbacks were not called
# The main issue here is, if you do a bunch of delete calls on a model that has associations there will be some other records that
# still exist and point to legit looking values that don't work, because even though the foreign_key exists in the table,
# the record it is pointing to does not.
# For e.g. A User and an Event
# == Schema Information
#
# Table name: users
#
class Player
def play_turn(warrior)
if warrior.feel.empty? && !taking_damage?(warrior) && warrior.health < 20
warrior.rest!
elsif warrior.feel.empty?
warrior.walk!
else
warrior.attack!
end
@health = warrior.health
class Player
def play_turn(warrior)
if @health.nil?
@health = warrior.health
end
if warrior.feel.empty? && !taking_damage?(warrior) && warrior.health < 20
warrior.rest!
elsif warrior.feel.captive?
warrior.rescue!

Contract Killer 3

Revised date: 07/11/2012

Between us [company name] and you [customer name]

Summary:

We’ll always do our best to fulfil your needs and meet your expectations, but it’s important to have things written down so that we both know what’s what, who should do what and when, and what will happen if something goes wrong. In this contract you won’t find any complicated legal terms or long passages of unreadable text. We’ve no desire to trick you into signing something that you might later regret. What we do want is what’s best for both parties, now and in the future.

@marcamillion
marcamillion / posterous_import.rb
Last active December 16, 2015 20:29 — forked from nitrogenlogic/00_posterous_import_moved.md
Added support for posts that were archived by Posterous - i.e. moved the images into subfolders belonging to dates & times that don't correspond (obviously) to the publish date of the post itself.
#!/usr/bin/env ruby
# This quick and dirty script imports posts and images exported by the
# Posterous backup feature into Octopress. Requires the escape_utils and
# nokogiri gems. Doesn't import comments.
#
# Videos and images are copied into a post-specific image directory used
# by my customized Octopress setup. Encoded videos are downloaded from
# Posterous. Images will probably need to be compressed/optimized afterward.
#
# Links to other posts in the same import will try to be converted. You will
@marcamillion
marcamillion / method_missing_override.rb
Created December 17, 2012 08:29 — forked from anonymous/gist:4316571
This allows you to do something like this: Say Advertiser is an assoc on banner, you could do something like: Advertiser.first.featured_banners And if you later add a banner type named 'Awesome' you could immediately call Advertiser.first.awesome_banner without writing new code in the model.
#Here's what I'm using. Maybe you could adapt it to your case. I have this on a Message model.
def method_missing(method_name, *args, &block)
if method_name =~ /(.*)_recipients$/
self.correspondences.where('recipient_type = ?', $1.to_s.humanize)
.collect{ |c| c.recipient }.flatten.uniq
else
super
end
end