Skip to content

Instantly share code, notes, and snippets.

View maricris-sn's full-sized avatar
😺

Maricris Nonato maricris-sn

😺
View GitHub Profile
@maricris-sn
maricris-sn / database_cleaner.rb
Created November 12, 2020 13:26 — forked from jsteiner/database_cleaner.rb
Database Cleaner
RSpec.configure do |config|
config.before(:suite) do
DatabaseCleaner.clean_with(:truncation)
end
config.before(:each) do
DatabaseCleaner.strategy = :transaction
end
config.before(:each, js: true) do
@maricris-sn
maricris-sn / dates_to_time.rb
Created February 28, 2019 07:03
Dates To Time
def dates_to_time(date_string, created_at)
if date_string[/[0-9]+/].blank?
# there aren't any numbers in it
return 0
else
# there's at least one number to derive date from
if date_string[/\'(\d){2}/].present?
# uses Month '14 for example
matched_year = date_string[/\'(\d){2}/]
# extrapolate the decade from when this record was created
@maricris-sn
maricris-sn / 0_reuse_code.js
Created May 20, 2016 14:31
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@maricris-sn
maricris-sn / social_utils.rb
Created October 21, 2013 12:11
This is a library that pulls in shares from Facebook, Twitter, Google Plus, Pinterest, LinkedIn and StumbleUpon. If you need a more elaborate breakdown for Facebook related data, please look at: http://stackoverflow.com/questions/6137414/how-to-fetch-facebook-likes-share-comments-count-from-an-article/7707702#7707702 Inspired by https://gist.git…
require 'open-uri'
module SocialUtils
def self.get_facebook_shares(url)
f = open("http://graph.facebook.com/?id=#{url}")
response = f.read()
shares = JSON.parse(response)['shares']
return shares.nil? ? 0 : JSON.parse(response)['shares']
end
@maricris-sn
maricris-sn / gist:7051895
Last active December 25, 2015 22:39 — forked from jonathanmoore/gist:2640302
Modified original gist to correct Pinterest call to get shares (pins).

Share Counts

I have always struggled with getting all the various share buttons from Facebook, Twitter, Google Plus, Pinterest, etc to align correctly and to not look like a tacky explosion of buttons. Seeing a number of sites rolling their own share buttons with counts, for example The Next Web I decided to look into the various APIs on how to simply return the share count.

If you want to roll up all of these into a single jQuery plugin check out Sharrre

Many of these API calls and methods are undocumented, so anticipate that they will change in the future. Also, if you are planning on rolling these out across a site I would recommend creating a simple endpoint that periodically caches results from all of the APIs so that you are not overloading the services will requests.

Twitter

@maricris-sn
maricris-sn / streamzoo.rb
Created September 7, 2013 03:21
Fetch Streamzoo photos as thumbnails and display in your site
$ rails g model StreamzooPhotos url:string
##lib/tasks/streamzoo.rake
require 'hpricot'
require 'open-uri'
namespace :streamzoo do
desc "refresh thumbnails"
task :update_thumbs => :environment do
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')
def smiley(str)
str = str.sub(':)', "<img src='/images/emoticons/1.gif' alt='smile'/>")
str = str.sub(':(', "<img src='/images/emoticons/2.gif' alt='sad'/>")
str = str.sub(';)', "<img src='/images/emoticons/3.gif' alt='wink'/>")
str = str.sub(':D', "<img src='/images/emoticons/4.gif' alt='grin'/>")
str = str.sub(':P', "<img src='/images/emoticons/5.gif' alt='tongue'/>")
end
## Think Geek Code (controller) [ruby]
def thinkGeek
require 'rss'
rss = RSS::Parser.parse(open('http://www.thinkgeek.com/xml/app/wishlist/id/').read, false)
@output = "" + rss.channel.description + ""
@output += ""