Skip to content

Instantly share code, notes, and snippets.

@rogeriomarques
rogeriomarques / pbic_pricing_scraper.py
Created October 23, 2015 19:54 — forked from rdempsey/pbic_pricing_scraper.py
A simple Python web scraper to obtain pricing data from the Packt website
#!/usr/bin/env python
# encoding: utf-8
"""
pbic_pricing_scraper.py
Created by Robert Dempsey on 09-29-2015
Copyright (c) 2015 Robert Dempsey. All rights reserved.
Utility script to obtain the price information for my book: Python Business Intelligence Cookbook
http://pythonbicookbook.com/
"""

Workflows (States) in Django

I'm going to cover a simple, but effective, utility for managing state and transitions (aka workflow). We often need to store the state (status) of a model and it should only be in one state at a time.

Common Software Uses

  • Publishing (Draft->Approved->Published->Expired->Deleted)
@rogeriomarques
rogeriomarques / unstar.js
Last active September 18, 2015 04:19 — forked from vadviktor/unstar.js
Unstar repos on Github
$('ul.repo-list').find('button.btn').filter('[title^="Unstar"]').click()
@rogeriomarques
rogeriomarques / main.go
Last active September 14, 2015 20:12
Simple pool worker example
package main
import (
"fmt"
"math"
)
func isPrime(n float64) bool {
max := int(math.Sqrt(n))
for i := 2; i < max; i++ {
@rogeriomarques
rogeriomarques / sharetabs.rb
Last active September 6, 2015 21:13 — forked from ttscoff/sharetabs.rb
Browser tabs to Dropbox HTML list
# Share Tab Collection 1.0 | Brett Terpstra 2015 <http://brettterpstra.com>
USERID = 'XXXXX'
require 'shellwords'
require 'fileutils'
def class_exists?(class_name)
klass = Module.const_get(class_name)

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

@rogeriomarques
rogeriomarques / .psqlrc
Last active August 29, 2015 14:12 — forked from jaytaylor/.psqlrc
-- Found at:
-- http://www.if-not-true-then-false.com/2009/postgresql-psql-psqlrc-tips-and-tricks/
-- http://opensourcedbms.com/dbms/psqlrc-psql-startup-file-for-postgres/
\set QUIET ON
\pset pager always
\pset null 'NULL'
package main
import (
"database/sql"
"errors"
"fmt"
_ "github.com/bmizerany/pq"
"os"
"regexp"
"strings"
// Open Script Editor and Export this as an Application
//
// Then drop a keynote file on it in the Finder and it will properly resize
// and rotate everything so the Keynote file becomes usable as a prototype
// in the iPhone keynote app
// rotateDocument exported function
//
// Accepts a Keynote document and will rotate
// all the slides and elements in the slide 90 degrees
<script type="text/javascript">
(function () {
"use strict";
// once cached, the css file is stored on the client forever unless
// the URL below is changed. Any change will invalidate the cache
var css_href = './index_files/web-fonts.css';
// a simple event handler wrapper
function on(el, ev, callback) {
if (el.addEventListener) {
el.addEventListener(ev, callback, false);