Skip to content

Instantly share code, notes, and snippets.

@potatosalad
potatosalad / designer.html
Last active August 29, 2015 14:10
designer
<link rel="import" href="../topeka-elements/category-icons.html">
<link rel="import" href="../core-icon/core-icon.html">
<polymer-element name="my-element">
<template>
<style>
:host {
position: absolute;
width: 100%;
@potatosalad
potatosalad / jws-payload-example.ex
Created September 22, 2015 15:53
Example of extracting the payload from a JWS signature
jwk_map = %{ "kty" => "oct", "k" => :base64url.encode("secret")}
jws_map = %{ "alg" => "HS256" }
jwt_map = %{ "test" => true }
signature = JOSE.JWT.sign(jwk_map, jws_map, jwt_map)
signature_compacted = JOSE.JWS.compact(signature)
{_, signature_map} = JOSE.JWS.expand(signature_compacted)
payload = JOSE.JWT.from(:base64url.decode(Map.get(signature_map, "payload")))
# one-liner version:
@potatosalad
potatosalad / cdcatalog.xml
Created November 9, 2010 18:40
XML to SQL example
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="cdcatalog.xsl"?>
<!-- Edited by XMLSpy® -->
<catalog>
<cd>
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<country>USA</country>
<company>Columbia</company>
<price>10.90</price>
@potatosalad
potatosalad / kraken-example.rb
Created March 26, 2011 18:13
Example of Kraken's EAV at work
# products:
# - _id
# - name
# - kraken_id
# - parent_id
class Product
include Mongoid::Document
include Mongoid::Kraken
field :name, :type => String
end
resources :categories
## equivalent to:
get '/categories(.:format)' => 'categories#index', :as => :categories
post '/categories(.:format)' => 'categories#create'
get '/categories/new(.:format)' => 'categories#new', :as => :new_category
get '/categories/:id/edit(.:format)' => 'categories#edit', :as => :edit_category
get '/categories/:id(.:format)' => 'categories#show', :as => :category
put '/categories/:id(.:format)' => 'categories#update'
resources :categories, :constraints => { :id => /.+?/ }
## equivalent to:
get '/categories(.:format)' => 'categories#index', :as => :categories
post '/categories(.:format)' => 'categories#create'
get '/categories/new(.:format)' => 'categories#new', :as => :new_category
get '/categories/*id/edit(.:format)' => 'categories#edit', :as => :edit_category
get '/categories/*id(.:format)' => 'categories#show', :as => :category
put '/categories/*id(.:format)' => 'categories#update'
@potatosalad
potatosalad / bottles.rb
Created September 20, 2011 17:48
Paste this into a rails console and type "99.bottles.of_beer.on_the_wall.sing!"
# paste into a rails console
# usage: 99.bottles.of_beer.on_the_wall.sing!
# alternate: 24.bottles.of_water.on_my_desk.sing!
class Bottle < ::ActiveSupport::BasicObject
attr_accessor :value, :type, :where
def initialize(value, type = nil, where = nil) #:nodoc:
@value, @type, @where = value, type, where
end
<!-- jQuery library for embedding gists in blog posts, etc. -->
<div id="1352696" class="gist"></div>
<!-- or -->
<div id="gist-1352696" class="gist"></div>
<script src="http://gist.pagodabox.com/jquery.gist.js"></script>
<!DOCTYPE html>
<html>
<head>
<script class="jsbin" src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
<!--[if IE]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<script src="https://raw.github.com/brandonaaron/jquery-mousewheel/master/jquery.mousewheel.js"></script>
require 'digest/md5'
def bson_id
[
'%08x' % Time.now.utc.to_i, # 4 bytes
Digest::MD5.hexdigest(`hostname`.strip)[0..5], # 3 bytes
'%04x' % $$, # 2 bytes
'%06x' % rand(0..('f' * 6).to_i(16)) # 3 bytes
] # 12 bytes total
end