Skip to content

Instantly share code, notes, and snippets.

View grammaticof's full-sized avatar

Francesco Grammatico grammaticof

View GitHub Profile
@grammaticof
grammaticof / gist:1994198
Created March 7, 2012 16:28 — forked from kled/gist:1994059
jQuery: HTML start page
<!DOCTYPE html>
<html>
<head>
<title>index</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
});
@grammaticof
grammaticof / snippet.js
Created March 14, 2012 16:58 — forked from necolas/snippet.js
jQuery: async load services
/*
* Updated to use the function-based method described in http://www.phpied.com/social-button-bffs/
* Better handling of scripts without supplied ids.
*
* N.B. Be sure to include Google Analytics's _gaq and Facebook's fbAsyncInit prior to this function.
*/
(function(doc, script) {
var js,
fjs = doc.getElementsByTagName(script)[0],
@grammaticof
grammaticof / gist:2043815 Capistrano: task to load production data into development database
desc "Load production data into development database"
task :import_remote_db do
filename = "dump.#{Time.now.strftime '%Y-%m-%d_%H:%M:%S'}.sql"
dbuser = "yourusername"
dbhost = "yourhostname"
dbpassword = "yourpassword"
application_db = "yourdatabasename"
local_db_host = "localhost"
local_db_user = "local_user_name"
@grammaticof
grammaticof / snippet.js
Created July 9, 2012 15:03 — forked from necolas/snippet.js
Optimised async loading of cross-domain scripts
/*
* Updated to use the function-based method described in http://www.phpied.com/social-button-bffs/
* Better handling of scripts without supplied ids.
*
* N.B. Be sure to include Google Analytics's _gaq and Facebook's fbAsyncInit prior to this function.
*/
(function(doc, script) {
var js,
fjs = doc.getElementsByTagName(script)[0],
@grammaticof
grammaticof / 1.html
Created August 24, 2012 15:42 — forked from mxriverlynn/1.html
backbone.js: how to get the model of the clicked html element
<script id="item-template" type="text/x-jquery-tmpl">
<li><a href="#">${name}</a></li>
</script>
@grammaticof
grammaticof / youtube-helper.js
Created August 28, 2012 16:59 — forked from kvnn/youtube-helper.js
Require.js Module for the YouTube Iframe API
define(["require", "exports"], function (require, exports) {
exports.YouTubeHelper = function (settings) {
// MEMBERS & DEFAULTS #################################################################################################################################################
var documentRef;
var originURL = ""; // for cross site checks
var targetContainer;
var target;
var parentContainer; // used for adding popups back into the original spot
<?php
if ( $app['debug'] ) {
$logger = new Doctrine\DBAL\Logging\DebugStack();
$app['db.config']->setSQLLogger($logger);
$app->error(function(\Exception $e, $code) use ($app, $logger) {
if ( $e instanceof PDOException and count($logger->queries) ) {
// We want to log the query as an ERROR for PDO exceptions!
$query = array_pop($logger->queries);
$app['monolog']->err($query['sql'], array(
@grammaticof
grammaticof / gist:4147767
Created November 26, 2012 11:33 — forked from samqiu/railscasts.rb
download railscast video
#!/usr/bin/ruby
require 'rss'
p 'Downloading rss index'
rss_string = open('http://feeds.feedburner.com/railscasts').read
rss = RSS::Parser.parse(rss_string, false)
videos_urls = rss.items.map { |it| it.enclosure.url }.reverse
videos_filenames = videos_urls.map {|url| url.split('/').last }
# db/migrate/20111218135715_globalize_models.rb
class GlobalizeModels < ActiveRecord::Migration
def up
NewsItem.create_translation_table!(
{:title => :string, :body => :text},
{:migrate_data => true}
)
end

If you want to use curl or net-http/open-uri to access https resources, you will often (always?) get an error, because they don't have the large number of root certificates installed that web browsers have.

You can manually install the root certs, but first you have to get them from somewhere. This article gives a nice description of how to do that. The source of the cert files it points to is hosted by the curl project, who kindly provide it in the .pem format.

problem: Sadly, ironically, and comically, it's not possible to access that file via https! Luckily, the awesome curl project does provide us with the script that they use to produce the file, so we can do it securely ourselves. Here's how.

  1. git clone https://github.com/bagder/curl.git
  2. cd curl/lib
  3. edit mk-ca-bundle.pl and change: