Skip to content

Instantly share code, notes, and snippets.

View ismaelga's full-sized avatar
🥔

Ismael Abreu ismaelga

🥔
View GitHub Profile
In celebration of Whyday: Rubyists always want to show others the beautiful code
they have created, hence the question: Has Anybody Seen My Code?
Has Anybody Seen My Code
(sung to the tune of Has Anybody Seen My Gal)
Clean and small, works for all,
Ruby is my all in all.
Has anybody seen my code?
@ismaelga
ismaelga / LICENSE
Last active August 29, 2015 14:06 — forked from ktheory/LICENSE
Copyright 2014 Kickstarter, Inc.
Released under an MIT License.

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

# Install apt-get packages:
sudo apt-get install build-essential openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison subversion pkg-config
# Install chruby:
cd
wget https://github.com/downloads/postmodern/chruby/chruby-0.2.3.tar.gz
tar -xzvf chruby-0.2.3.tar.gz
cd chruby-0.2.3
sudo make install
@ismaelga
ismaelga / benchmark_new_set_include.rb
Last active August 29, 2015 14:13
Benchmark of Set#include? using Hash#[]
require 'benchmark/ips'
require 'set'
sizes = [10, 100, 1_000, 10_000]
accesses = %i(first last hits misses)
class NewSet < Set
def initialize(enum = nil, &block)
@hash = Hash.new(false)
super
@ismaelga
ismaelga / gist:7ce902babe356b7cae3f
Last active August 29, 2015 14:13
cargo build "no such file or directory"
~/hello_world ❯❯❯ sudo dtruss -f /usr/local/bin/cargo build
PID/THRD SYSCALL(args) = return
42307/0x231a8: thread_selfid(0x0, 0x0, 0x0) = 143784 0
42307/0x231a8: csops(0x0, 0x0, 0x7FFF58CC4248) = 0 0
42307/0x231a8: issetugid(0x0, 0x0, 0x7FFF58CC4248) = 0 0
42307/0x231a8: shared_region_check_np(0x7FFF58CC2188, 0x0, 0x7FFF58CC4248) = 0 0
42307/0x231a8: stat64("/usr/lib/dtrace/libdtrace_dyld.dylib\0", 0x7FFF58CC3318, 0x7FFF58CC4248) = 0 0
42307/0x231a8: open("/dev/dtracehelper\0", 0x2, 0x7FFF58CC4140) = 3 0
42307/0x231a8: close(0x3) = 0 0
{:ok, content} = File.read("test/example_script.lua")
defredis_script(:return_one_file, content)
@ismaelga
ismaelga / results.md
Last active August 29, 2015 14:15
Phoenix Showdown 1.7 GHz 8 GB

Phoenix

Elixir 1.0.3 Erlang/OTP 17

Running 30s test @ http://127.0.0.1:4000/showdown
  4 threads and 100 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     7.39ms    8.05ms 123.21ms   93.84%
    Req/Sec     3.76k   687.58     6.32k    79.12%
  437943 requests in 30.00s, 0.90GB read
Requests/sec:  14598.19
nickel-demo git:master ❯ RUST_BACKTRACE=1 cargo run --verbose ⏎ ✹ ✭
Fresh matches v0.1.2
Fresh nickel_macros v0.0.1 (https://github.com/nickel-org/nickel.rs.git#cd9591d2)
Fresh gcc v0.1.7
Fresh libc v0.1.2
Fresh log v0.2.3
Fresh groupable v0.1.0 (https://github.com/nickel-org/groupable-rs#efc8d769)
Fresh regex v0.1.14
Fresh pkg-config v0.2.1
Fresh gcc v0.2.1
defmacro defredis_script(name, script) do
script_sha = :crypto.hash(:sha, script)
quote bind_quoted: [script_sha: script_sha, name: name, script: script] do
def unquote(name)(client, keys \\ [], argv \\ []) do
query_args = [length(keys)] ++ keys ++ argv
case Exredis.query client, ["EVALSHA", unquote(script_sha)] ++ query_args do
<<"NOSCRIPT", _ :: binary>> ->
Exredis.query client, ["EVAL", unquote(script)] ++ query_args
reply -> reply
end