Skip to content

Instantly share code, notes, and snippets.

View tieleman's full-sized avatar

Sjoerd Tieleman tieleman

View GitHub Profile
@tieleman
tieleman / retina_finder.rb
Created June 8, 2012 16:38
A hacky retina file finder/reporter. Use it for all your weird retina weirdness stuff.
class RetinaFinder
PATH_TO_NORMAL = "app/assets/images/"
PATH_TO_RETINA = "app/assets/images/2x/"
IMAGE_FORMATS = %w(png jpg gif)
MULTIPLIER = 4 # 2 for regular retina, 4 for retina + 2x zoom, etc.
def run
build_file_lists
match_files
report_missing_or_orphaned
@tieleman
tieleman / sequelize.js
Last active December 14, 2015 15:28
Script to demonstrate an issue in Sequelize. https://github.com/sequelize/sequelize/issues/481
var Sequelize = require('sequelize');
// Set up database connection
var sql = new Sequelize('database', 'root', '', {
dialect: 'mysql'
});
// Global counter
var counter = 0;
@tieleman
tieleman / viewports.txt
Last active December 14, 2015 22:39
Reported media query viewport sizes (max-width) when using width=device-width. You can use this list to construct media queries targetting specific platforms.
*Device* *Portrait* *Landscape* *Device type* *Remarks*
Nexus 7 600 961 Tablet
iPad 2 768 768 Tablet iOS always reports the same, regardless of orientation.
Surface RT 1366 1024 Tablet
Galaxy Tab 2 1280 800 Tablet
Galaxy Nexus 360 598 Phone
iPhone 5 320 320 Phone iOS always reports the same, regardless of orientation.
Galaxy S3 mini 320 534 Phone Stock android browser reports 533, not 534 (Chrome).
@tieleman
tieleman / viewport.html
Created March 14, 2013 09:43
Quick 'n dirty script to report viewport sizes. See #5159984 for a list of devices.
<!DOCTYPE html>
<html>
<head>
<title>viewport test</title>
<meta name="viewport" id="viewport" content="width=device-width">
<meta charset="utf-8">
</head>
<body>
<span id="width"></span> x <span id="height"></span>
@tieleman
tieleman / deploy.rb
Created April 19, 2013 12:30
Snippet to deploy Rails 4. Don't use the Capistrano asset tasks.
after "deploy:restart", "deploy:cleanup"
namespace :deploy do
task :restart, :roles => :web do
run "touch #{release_path}/tmp/restart.txt"
end
task :finalize_update, :roles => :web do
run "RAILS_ENV=#{rails_env}"
@tieleman
tieleman / detect.js
Created April 25, 2013 07:39
Two quick 'n dirty JavaScript snippets to determine whether Flash/Silverlight are installed. Wrapped in try/catch blocks to prevent IE8 from throwing errors. Uses the "navigator.plugins" object in modern browsers and ActiveXObject for old IE.
var hasFlash = false;
var hasSilverlight = false;
try {
hasFlash = !!((typeof navigator.plugins != "undefined" && typeof navigator.plugins["Shockwave Flash"] == "object") || (window.ActiveXObject && (new ActiveXObject("ShockwaveFlash.ShockwaveFlash")) !== false));
} catch(err) {
hasFlash = false;
}
try {
@tieleman
tieleman / blur_worker.js
Last active January 11, 2017 23:10
A web worker to blur image data from a canvas. Pass it a message with a data object supplying ImageData, a radius and quality (number of passes). Returns a message with the resulting blurred ImageData.
/*
* BoxBlurFilter
* Visit http://createjs.com/ for documentation, updates and examples.
*
* Adapted by Hiro to function as a standalone web worker. Pass it a
* message with a data object supplying ImageData, a radius and quality
* (number of passes). Returns a message with the resulting
* blurred ImageData.
*
*
@tieleman
tieleman / server.js
Created February 5, 2014 09:53
Tiny Node.js web server that echoes any data you POST/PUT/send to it. Useful for debugging purposes.
var http = require('http');
http.createServer(function (req, res) {
var postedData = '';
req.on('data', function(data) { postedData += data.toString(); });
req.on('end', function() {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end(postedData);
console.log(postedData);
});
}).listen(8080, '127.0.0.1');
@tieleman
tieleman / spawner.rb
Last active August 29, 2015 13:57
Spawn example
pid1 = spawn "some_command"
pid2 = spawn "some_other_command"
pid1.on_exit do |status|
puts "Process #1 exited with status code #{status}, aborting."
exit
end
pid2.on_exit do |status|
puts "Process #2 exited with status code #{status}, aborting."
@tieleman
tieleman / spawner.js
Created March 11, 2014 10:33
Spawn example JS
var child_process = require('child_process');
job1 = child_process.spawn('sleep', ['5'])
job2 = child_process.spawn('sleep', ['10'])
job1.on('exit', function(code, signal) {
console.log("Job 1 exited with code " + code + " and signal " + signal);
job2.kill(); // Send SIGTERM to other job
})