Skip to content

Instantly share code, notes, and snippets.

@zhannes
zhannes / fb_recrawl.rb
Created March 17, 2015 21:26
quick script takes a file of URLs and tells FB to recrawl them. When og:image etc have changed, this will refresh FB's cache of the page.
# pass input file as param
return unless ARGV.size > 0
list = ARGV[0]
File.readlines(list).each do |line|
puts `curl --data "id=#{line}&scrape=true" https://graph.facebook.com`
end
@zhannes
zhannes / dfd-foo.js
Last active August 29, 2015 14:16
callback vs dfd
// old way, plan to pass a func
function doAsyncStuff(callback){
// do stuff, then call the function that was passed
setTimeout(callback,2000);
}
// calling it
doAsyncStuff(function(){
console.log('internet website')
>>> d = {'a': 'foo', 'b': 'bar'}
>>> d
{'a': 'foo', 'b': 'bar'}
# get name of matching prop
>>> matches = [item for item in d if d[item] =='bar']
>>> matches
['b']
# or, get the value of the match
@zhannes
zhannes / gist:7452354
Created November 13, 2013 16:51
iframe form
function iFramePost(form){
if(!form) return;
if(!form.jquery) form = $(form);
var f = document.createElement('iframe');
var target = 'iframe_target_' + (new Date).getTime();
form.attr('target',target);
f.name = target;
var id = 'iframe_post_' + (new Date).getTime();
f.id = id;
form.attr('data-iframe-post-id',id);
collection = Backbone.Collection.extend(
initialize: ->
@term = ""
@page = ""
url: ->
"url-to-data?" + @term
)
# when user clicks a sort header, set props on collection
@zhannes
zhannes / main.js
Created July 22, 2013 00:26
small jsonp
(function(doc, script){
var API_KEY = ''; // use yours
// tks -- http://css-tricks.com/thinking-async/
var js,
fjs = doc.getElementsByTagName(script)[0],
add = function(url, id) {
if (doc.getElementById(id)) {return;}
js = doc.createElement(script);
js.src = url;
doctype html
/[if lt IE 7]
| <html class="ie ie6 lt-ie9 lt-ie8 lt-ie7">
/[if IE 7]
| <html class="ie ie7 lt-ie9 lt-ie8">
/[if IE 8]
| <html class="ie ie8 lt-ie9">
/[if IE 9]
| <html class="ie ie9">
| <!--[if (gte IE 9)|!(IE)]<!-->
(function($){
$(function(){
// code in here
})
})(window.jQuery)
@zhannes
zhannes / Gemfile
Last active December 17, 2015 05:49
This is here now: https://github.com/zhannes/mm_starter. Middleman with slim, stylus, coffee script, assets (concat, minify, fingerprint)
# If you have OpenSSL installed, we recommend updating
# the following line to use "https"
source 'http://rubygems.org'
gem "middleman", :github => "middleman/middleman"
gem 'middleman-sprockets', :github => "middleman/middleman-sprockets"
gem "stylus"
gem "slim"
gem "gist"
@zhannes
zhannes / template-helper.js
Created April 13, 2013 21:46
Fetch a javascript template (html file) and then pass it data.
define(['jquery', 'handlebars'],function($,Handlebars){
/* use:
var tmpl = App.helpers.tmpl,
getCompiledTemplate = tmpl('foo', {});
getCompiledTemplate.then(function(content){
$('#something').html(content);
});