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 / 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 / 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 / ghost-sitemap.rb
Last active August 29, 2015 13:56
Walking a sticko-themed blog to create sitemap links
require 'nokogiri'
require 'open-uri'
home = 'http://your-blog.com'
sitemap_file = File.open('sitemap.xml', 'wb')
sitemap_file.puts('<?xml version="1.0" encoding="UTF-8"?>
<urlset
xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Collapsible Tree Example</title>
<style>
.node circle {
gibbon = Gibbon::API.new
view = ActionView::Base.new('app/views/', {instance_variable_for_templates: 5324}, ActionController::Base.new)
campaign = gibbon.campaigns.create(
type: "regular",
options: {
list_id: 'xxxy',
from_email: '[email protected]',
from_name: 'Your From',
subject: "the subject",
@maricris-sn
maricris-sn / do-ghost-upgrade
Last active August 29, 2015 14:05
Upgrading Ghost
# Login to your server as root
# Stop ghost service to prevent database corruption
service ghost stop
# Do some manual backups
cd /var/www
CURRENT_GHOST_TAR=/var/www/ghost-$(date +"%Y-%m-%d").tar
tar cvf $CURRENT_GHOST_TAR /var/www/ghost
@maricris-sn
maricris-sn / read-split-name
Created October 28, 2014 10:07
Read a spreadsheet's fullname column; and split into first and last names
# Assumes gem install 'roo' has been done
require 'roo'
# Spreadsheet filename I want to read
file_path = ENV["CONTACT_PATH"]
puts "Importing data from " + file_path
# Opening the file using roo
spreadsheet = case File.extname(file_path)
Remove osxfuse if installed via homebrew:
> brew uninstall osxfuse
Install osxfuse binary and choose to install the MacFUSE compatibility layer:
http://sourceforge.net/projects/osxfuse/files/latest/download?source=files
Reboot (optional but recommended by osxfuse)
Install ntfs-3g via homebrew:
> brew update && brew install ntfs-3g
@maricris-sn
maricris-sn / bench_rails_memory_usage.rb
Last active August 29, 2015 14:27 — forked from brianhempel/bench_rails_memory_usage.rb
A script to test the memory usage of your Rails application over time. It will run 30 requests against the specified action and report the final RSS. Choose the URL to hit on line 45 and then run with `ruby bench_rails_memory_usage.rb`.
require "net/http"
def start_server
# Remove the X to enable the parameters for tuning.
# These are the default values as of Ruby 2.2.0.
@child = spawn(<<-EOC.split.join(" "))
XRUBY_GC_HEAP_FREE_SLOTS=4096
XRUBY_GC_HEAP_INIT_SLOTS=10000
XRUBY_GC_HEAP_GROWTH_FACTOR=1.8
XRUBY_GC_HEAP_GROWTH_MAX_SLOTS=0
@maricris-sn
maricris-sn / ftp-upload.rb
Last active September 18, 2015 04:30 — forked from taf2/ftp-upload.rb
uploading a file in ruby is hard. ftp is hard.
# fireway configured with: http://major.io/2007/07/01/active-ftp-connections-through-iptables/
require 'net/ftp'
require 'stringio'
# allows us to upload files by content instead of writing to disk first
class Net::FTP
def puttextcontent(content, remotefile, &block)
f = StringIO.new(content)
begin