class Post < ActiveRecord::Base
STATUS = %w(draft published)
def draft?
status == 'draft'
end
def published?
status == 'published'| <script type="text/javascript"> | |
| $(function(){ | |
| $('input#submit').click(function(){ | |
| var file = $('input[type="file"]').val(); | |
| var exts = ['doc','docx','rtf','odt']; | |
| // first check if file field has any value | |
| if ( file ) { | |
| // split file name at dot | |
| var get_ext = file.split('.'); | |
| // reverse name to check extension |
| import re | |
| def fff(url): | |
| query = re.search('\?(.*)', url) | |
| return query and query.group() or '/' | |
| def fff2(url): | |
| query = re.search('(https?://)?\w/(.*)', url) | |
| return "/%s" % (query and query.group(2) or "", ) |
| #!/usr/bin/env python | |
| # coding: utf8 | |
| from __future__ import print_function | |
| import requests | |
| URL = 'https://graph.facebook.com/?ids=%s'; | |
| def get_url_data(url): |
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.
| from scrapy.item import DictItem, Field | |
| def create_item_class(class_name, field_list): | |
| fields = {field_name: Field() for field_name in field_list} | |
| return type(class_name, (DictItem,), {'fields': fields}) |
| # app/models/model_name.rb | |
| class ModelName < ActiveRecord::Base | |
| include Tokenable | |
| end | |
| # app/models/concerns/tokenable.rb | |
| module Tokenable | |
| extend ActiveSupport::Concern | |
| included do |
| require 'json' | |
| raise Exception, 'you must provide a json file' unless ARGV[0] | |
| buffer = File.open(ARGV[0]).read | |
| buffer.gsub!("\n", '') | |
| buffer.gsub!("\t", '') | |
| json = JSON.parse(buffer) | |
| puts json.first.collect {|k,v| k}.join(',') |
| require 'json' | |
| require 'csv' | |
| raise Exception, 'you must provide a json file' unless ARGV[0] | |
| buffer = File.open(ARGV[0]).read | |
| buffer.gsub!("\n", '') | |
| buffer.gsub!("\t", '') | |
| json = JSON.parse!(buffer) |