Skip to content

Instantly share code, notes, and snippets.

@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 / 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: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 / 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: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 / 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 / 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;
<!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 / onnavigatedfrom.cs
Created October 10, 2011 08:11
OnNavigatedFrom
protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
{
}
@jlebrech
jlebrech / gist:1012752
Created June 7, 2011 17:54
failed installing imagemagick on brew
checking for IceConnectionNumber in -lICE... yes
-------------------------------------------------------------
checking for X11...
checking for shmctl... yes
checking for XShmAttach in -lXext... yes
checking for XShapeCombineMask in -lXext... yes
checking for XtSetEventDispatcher in -lXt... yes
-------------------------------------------------------------
checking for ZLIB...
checking zconf.h usability... yes