Skip to content

Instantly share code, notes, and snippets.

View paolochiodi's full-sized avatar

Paolo Chiodi paolochiodi

View GitHub Profile
(function(){
var newStylesheet = null;
window.addCssClass = function (selector, content){
// ensure presence of head element
if(typeof selector === 'string'){
console.log('creating');
class ActiveRecord::Base
alias_method 'paperclip_valid?', 'valid?'
def valid?
ret = paperclip_valid?
unless self.class.attachment_definitions.nil?
self.class.attachment_definitions.each_key do |attachment|
%w(_file_name _content_type _file_size).each do |suffix|
#!/bin/sh
# adapted from http://stackoverflow.com/questions/489277/script-to-convert-mysql-dump-sql-file-into-format-that-can-be-imported-into-sqlit
if [ "x$1" == "x" ]; then
echo "Usage: $0 <dumpname>"
exit
fi
cat $1 |
grep -v ' KEY "' |
grep -v ' UNIQUE KEY "' |
grep -v ' PRIMARY KEY ' |
@paolochiodi
paolochiodi / carousel.js
Created April 18, 2011 07:39
A simple example of javascript
@paolochiodi
paolochiodi / config.ru
Created March 12, 2012 13:56
Example of a rack app with sprockets
require 'bundler'
Bundler.require
project_root = File.expand_path(File.dirname(__FILE__))
assets = Sprockets::Environment.new(project_root) do |env|
env.logger = Logger.new(STDOUT)
end
compass_gem_root = Gem.loaded_specs['compass'].full_gem_path
IMAGES = [
"https://s3.amazonaws.com/cdn.blomming.com/items/000/700/192/original/b3a1bc5faa4d6becfe7aa66afaea73f8.png",
"https://s3.amazonaws.com/cdn.blomming.com/items/000/700/471/original/52a56d6ce31b8e92572cd667963fa8ba.jpg",
"https://s3.amazonaws.com/cdn.blomming.com/items/000/522/509/original/fa7c3bb313a96178cca219c1957d1a06.jpg",
"https://s3.amazonaws.com/cdn.blomming.com/items/000/197/874/original/f11b7994af669663301ca5786f6a4d68.jpg",
"https://s3.amazonaws.com/cdn.blomming.com/items/000/307/331/original/b3dbbd6ceaa4e5570dda4c9fc5302c1d.jpg",
"https://s3.amazonaws.com/cdn.blomming.com/items/000/690/960/original/419b0c8960b73611d5ee4f5a1da3bb54.jpg",
"https://s3.amazonaws.com/cdn.blomming.com/items/000/691/008/original/4dc8316656dd7c53c84f65b526d85d03.jpg",
"https://s3.amazonaws.com/cdn.blomming.com/items/000/691/012/original/208c30f7afdce678b647e0b38027c409.jpg",
var Cover = require('../../lib/resizers/resizer_stream');
var Transform = require('stream').Transform;
describe("ResizerStream", function() {
it("should be a Transform stream", function() {
var resizer = new Cover({ height: 100, width: 200 });
expect(resizer).to.be.an.instanceof(Transform);
});
require 'net/http'
require 'json'
auth_uri = URI('https://api.blomming.com/v1/oauth/token')
json_uri = URI('https://api.blomming.com/v1/categories/158/items')
params = {
:grant_type => 'client_credentials',
:client_id => '<CLIENT_ID>',
:client_secret => '<CLIENT_SECRET>'
@paolochiodi
paolochiodi / leak.js
Created December 24, 2013 06:51
Test resizer for memory leaks
var fs = require('fs');
var resizers = require('../index');
var execute = function(next) {
var Cover = resizers.cover;
var Contain = resizers.contain;
var Crop = resizers.crop;
var inputImage = fs.createReadStream(__dirname + '/test.jpg');
@paolochiodi
paolochiodi / README.md
Last active September 11, 2015 15:39
Example to create importable test suites with lab

This is a possible approach to create a set of tests (child.js) that can be imported into another project (parent.js) and run through it. This kind of approach also allows to pass parameters and options to the initial set of tests (in this case si).

Another possible approach is to just return lab from the child test and have it re-exported by parent (in this case parameteres would need to be added to tests).

Tests are run with lab parent.js.

This has been explored for use in seneca-store-test. Using this approach we can refactore seneca-store-test to directly use experiments and tests (or describe/it in BDD parlance) while still depende on store implementation to provide a correctly configured seneca instance. The added benefits imho are: