Skip to content

Instantly share code, notes, and snippets.

<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>
<!--[if IE]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<style>
article, aside, figure, footer, header, hgroup,
@jlebrech
jlebrech / transparentize.cs
Created October 19, 2011 09:28
Set copy the left pixel and make any instances of that color transparent
ExtendedImage _img = sender as ExtendedImage;
byte transpCorner = _img.Pixels[0 * _img.PixelWidth + 0]; // top left pixel
byte[] newPixels = _img.Pixels;
for (int xp = 0; xp < _img.PixelWidth; xp++)
{
for (int yp = 0; yp < _img.PixelHeight; yp++)
{
int r = 0, g = 0, b = 0, alpha = 0;
@jlebrech
jlebrech / flickr.cs
Created December 20, 2011 09:42
flickr
XDocument doc = XDocument.Load(s);
flicks.Clear();
XNamespace serv = "http://search.yahoo.com/mrss/";
foreach (XElement value in doc.Element("rss").Element("channel").Elements("item"))
{
flick _item = new flick();
@jlebrech
jlebrech / gist:1505361
Created December 21, 2011 09:25
rails wizard
Bundler could not find compatible versions for gem "rails":
In Gemfile:
rails_admin depends on
rails (~> 3.1)
rails (3.1.0.rc5)
@jlebrech
jlebrech / ChaptersController.rb
Created January 10, 2012 17:18
what is wrong with my before filter
class ChaptersController < ApplicationController
before_filter :check_ownership_of_chapters_book
def check_ownership_of_chapters_book
#abort(params.to_yaml)
=begin
---
utf8: ✓
authenticity_token: NwsHY5ex9ynzXfDSXiQ8EBps6Yhzxf0iPPbJPWLkTtg=
@jlebrech
jlebrech / gist:1595667
Created January 11, 2012 17:14
routes
book_chapters GET /books/:book_id/chapters(.:format) {:action=>"index", :controller=>"chapters"}
POST /books/:book_id/chapters(.:format) {:action=>"create", :controller=>"chapters"}
new_book_chapter GET /books/:book_id/chapters/new(.:format) {:action=>"new", :controller=>"chapters"}
edit_chapter GET /chapters/:id/edit(.:format) {:action=>"edit", :controller=>"chapters"}
chapter GET /chapters/:id(.:format) {:action=>"show", :controller=>"chapters"}
PUT /chapters/:id(.:format) {:action=>"update", :controller=>"chapters"}
DELETE /chapters/:id(.:format) {:action=>"destroy", :controller=>"chapters"}
books GET /books(.:format) {:action=>"index", :controller=>"books"}
POST /books(.:format)
@jlebrech
jlebrech / gist:1663976
Created January 23, 2012 16:03
create_epubs.rake
task :create_epubs => :environment do
include Rails.application.routes.url_helpers # brings ActionDispatch::Routing::UrlFor
include ActionView::Helpers::TagHelper
av = ActionView::Base.new(Rails.root.join('app', 'views'))
puts av.render("books/", :books => Book.all).to_string
end
@jlebrech
jlebrech / gist:1669500
Created January 24, 2012 10:25
raketask.rake
task :create_epubs => [:environment] do
av = ActionView::Base.new(Rails.root.join('app', 'views'))
av.view_paths = ActionController::Base.view_paths
av.extend ApplicationHelper #or any other helpers your template may need
@book = Book.first
puts @book.to_yaml # this can read from the model
body = av.render(:template => "books/epub-show", :locals => @book) # this isn't passing @book to the view correctly, i get undefined method for nil:nilClass
end
@jlebrech
jlebrech / imgkit.rb
Created February 3, 2012 15:44
imgkit wrong output dimensions
require 'imgkit'
kit = IMGKit.new('http://google.com', :quality => 94, :width => 320, :height => 240)
img = kit.to_img(:jpeg)
file = kit.to_file('file.jpg')
#the output file has the dimensions of 710x240
#clearly not right.
/Users/jlebrech/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler/rubygems_integration.rb:219:in `block in replace_bin_path': can't find executable rake (Gem::Exception)
from /Users/jlebrech/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/bin/rake:19:in `<main>'