Skip to content

Instantly share code, notes, and snippets.

View bear454's full-sized avatar

James Mason bear454

View GitHub Profile
@bear454
bear454 / dot-net-guid.rb
Created February 25, 2014 21:18
.net is *evil*: example.
# Convert a string in the expected format, into 16 bytes, emulating .Net's
# Guid constructor.
# "00000000-0000-0000-0000-000000000000" =>
# [CLSCompliantAttribute(false)]
# public Guid(
# uint a,
# ushort b,
# ushort c,
# byte d,
# byte e,
@bear454
bear454 / original.rb
Created May 27, 2014 17:02
conference date string refactor
def conference_date_string(conf)
startstr = "Unknown - "
endstr = "Unknown"
# When the conference in the same motn
if conf.start_date.month == conf.end_date.month and conf.start_date.year == conf.end_date.year
startstr = conf.start_date.strftime("%B %d - ")
endstr = conf.end_date.strftime("%d, %Y")
elsif conf.start_date.month != conf.end_date.month && conf.start_date.year == conf.end_date.year
startstr = conf.start_date.strftime("%B %d - ")
endstr = conf.end_date.strftime("%B %d, %Y")
@bear454
bear454 / designer.html
Last active August 29, 2015 14:14
designer
<link rel="import" href="../polymer/polymer.html">
<polymer-element name="linuxtycooon-app">
<template>
<style>
:host {
position: absolute;
width: 100%;
height: 100%;
@bear454
bear454 / designer.html
Last active August 29, 2015 14:14
designer
<link rel="import" href="../core-scaffold/core-scaffold.html">
<link rel="import" href="../core-header-panel/core-header-panel.html">
<link rel="import" href="../core-menu/core-menu.html">
<link rel="import" href="../core-item/core-item.html">
<link rel="import" href="../core-icon-button/core-icon-button.html">
<link rel="import" href="../core-toolbar/core-toolbar.html">
<link rel="import" href="../core-menu/core-submenu.html">
<polymer-element name="my-element">
class Person < ActiveRecord::Base
has_many :orders
has_many :lines, :through => :products
has_many :products, :through => :lines
end
class Order < ActiveRecord::Base
has_many :lines
has_many :products, :through => :lines
end
def class Cart < ActiveRecord::Base
#...
def installation_instructions_pdf(pdf = nil)
pdf ||= Prawn::Document.new
eval(IO.read("app/views/cards/installation.pdf.prawn"))
pdf
end
#...
@bear454
bear454 / some_random_view.html.erb
Created August 27, 2009 19:17
Bare example of link_to_remote: clicking the "Update" link in the view will change the text in the update_me span to 'Updated text.'
<span id="update_me">Some text that needs to be updated.</span>
<%=link_to_remote "Update", :url => "/update/something", :update => 'update_me' %>
#!/usr/bin/ruby
require 'rubygems'
require 'sinatra'
require 'haml'
require 'gdata'
PROJECT_PATH = "/your/project/path"
DOMAIN = 'your_google_apps_domain_or_blank_for_any_google_account.com'
@bear454
bear454 / active_record_steps.rb
Created September 22, 2009 00:05
Some generic rspec steps I use for unit testing ActiveRecord models with cucumber.
# clear a table
Given /^I have no (\S+)$/ do |table|
ActiveRecord::Base.connection.execute "DELETE FROM `#{table.tableize}`"
end
# create a new instance, as an @underscore_named_var, and @it.
Given /^I have a new (\S+)$/ do |model|
eval "@#{model.underscore} = #{model.classify}.new"
eval "@it = #{model.classify}.new"
end
class Core < ActiveResource::Base
self.site = case Rails.env
when 'production'
"http://core.yamatoengines.com"
else
"http://localhost:3005"
end
end