Skip to content

Instantly share code, notes, and snippets.

@EmmaB
EmmaB / dotted_line.rb
Created October 24, 2011 15:56
Dotted line in log
def ps( msg )
if Rails.env == 'development'
puts '-' * msg.length
puts msg
end
end
// view file
= f.input :use_metadata_fields, :label => "Choose one...", :as => :select, :collection => [["Fill in detailed metadata fields","1"], ["Use a default profile","0"]], :input_html => {:id => :use_metadata_fields, :class => 'input-small'}
#default_fields // a hash sign is the haml for div id
= f.input :default_fields, :as => :select, :collection => @defaults, :method_label => :description
#metadata_fields
= f.input :price
= f.input :pub_date
= f.input :imprint
= f.input :category
{
"current_page": 1,
"per_page": 35,
"total_pages": 1,
"works": [
{
"work": {
"books": [
{
"book": {
# Frontlist Variable Page Layout Catalogue XML from Bibliocloud
<?xml version="1.0"?>
<catalogue>
<section>
<section_title>Snowbooks 2014: January to April</section_title>
<half_page_book>
<category>General non-fiction</category>
<month>January</month>
<imprint>Snowbooks</imprint>
<?xml version="1.0" encoding="ISO-8859-1"?>
<BK xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xsl:version="1.0">
<xsl:for-each select="ONIXMessage/Product">
<Book>
<xsl:variable name="form" select="ProductFormDetail"/>
<xsl:variable name="date" select="PublicationDate"/>
<xsl:variable name="isbn" select="ProductIdentifier[ProductIDType = '15']/IDValue"/>
<image href="file:///{$isbn}.jpg" />
<year><xsl:value-of select="concat(substring($date,7,2), '/',substring($date,5,2), '/',substring($date,1,4))"/></year>
<productid><xsl:value-of select="$isbn"/></productid>
@EmmaB
EmmaB / gist:de50c644f31396cdab47
Created March 19, 2015 10:41
ONIX to Word macro data
Dim strXPath1 As String 
strXPath1 = "/ONIXMessage/Product/ProductIdentifier[ProductIDType='03']/IDValue" 
ActiveDocument.ContentControls(1).XMLMapping.SetMapping strXPath1 
Dim strXPath2 As String 
strXPath2 = "/ONIXMessage/Product/BICMainSubject" 
ActiveDocument.ContentControls(2).XMLMapping.SetMapping strXPath2
 Dim strXPath3 As String
 strXPath3 = “/ONIXMessage/Product/Title[TitleType='01']/TitleText"
my_name = '{ "firstname": "Emma" ,
"lastname" : "Barnes"
}'
our_names = '[{"firstname": "Emma",
"lastname" : "Barnes"},
{"firstname": "David",
"lastname" :"Aldridge"},
{"firstname": "Rob",
"lastname" :"Jones"
}]'
# Use the Ruby JSON gem to parse data in the JSON format
json = JSON.parse(our_names)
# Get the first person's firstname. Ruby counts from 0, not 1!
json[0]["firstname"]
=> "Emma"
# Get the second person's firstname
json[1]["firstname"]
=> "David"
# Get each bit of the JSON data...
@EmmaB
EmmaB / poetry.rb
Last active September 21, 2018 13:47
Code is poetry
class Book
def initialize(name:, jacket: :draft)
@name = name
@jacket = jacket
end
def name
@name
end