Skip to content

Instantly share code, notes, and snippets.

View strukturedkaos's full-sized avatar

Don Pottinger strukturedkaos

View GitHub Profile
@strukturedkaos
strukturedkaos / MainActivity.java
Created February 1, 2012 17:50
Android Authentication Example
package com.sexifit.android;
import java.io.IOException;
import java.io.StringReader;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
@strukturedkaos
strukturedkaos / gist:3801641
Created September 28, 2012 19:17 — forked from jkassemi/gist:3797001
Select2.js capybara
def select2_select(text, options)
page.find("#s2id_#{options[:from]} a").click
page.all("ul.select2-results li").each do |e|
if e.text == text
e.click
return
end
end
end
@strukturedkaos
strukturedkaos / seeds.rb
Created October 9, 2012 13:16
Seeding from CSV File Example
require 'csv'
seed_data_path = "db/seed/"
puts "Importing shifts..."
CSV.foreach(Rails.root.join(seed_data_path + "shifts.csv"), headers: true) do |row|
%w(Monday Tuesday Wednesday Thursday Friday Saturday Sunday).each do |day|
Shift.find_or_create_by_day_and_start_time_and_end_time(day, Time.parse(row[0]), Time.parse(row[1]))
end
end
@strukturedkaos
strukturedkaos / select2_helper.rb
Created October 29, 2012 00:20 — forked from sbeam/gist:3849340
capybara helper for select2-ajax elements
# select2_ajax helper to make capybara work with ajax-enabled Select2 elements
# assumes 'placeholder' option is used in Select2 (if it is using ajax, it should be)
#
# usage:
#
# it "should have a select2 field for searching by team name" do
# @team = Factory :team
# select2_ajax @team.name, :from => "Select a Team", :minlength => 4
# click_button "Join"
# page.should have_content "You are now on '#{@team.name}'."
@strukturedkaos
strukturedkaos / html_email.html.haml
Last active December 15, 2015 05:39
Railscast Example of HTML Email with CSS
!!!
%html
%head
%meta{:content => "text/html; charset=utf-8", "http-equiv" => "Content-Type"}/
%title RailsCasts Weekly
:css
body, td { color:#000000; font-size:14px; font-family:Verdana,Helvetica,Arial; }
.divider { background-color:#555555; height:2px; }
.episode h2 { margin-top:0; margin-bottom:8px; font-size:18px; }
.episode p { margin:8px 0; }
class PdfMerger
def merge(pdf_paths, destination)
first_pdf_path = pdf_paths.delete_at(0)
Prawn::Document.generate(destination, :template => first_pdf_path) do |pdf|
pdf_paths.each do |pdf_path|
pdf.go_to_page(pdf.page_count)
## This gist is intended to provide a code example for the
# 'Making Signed Requests' section of the 'Authentication Overview' document.
# (http://developer.netflix.com/docs/Security).
#
# We are going to make a catalog request. The hardest part of
# it is figuring out how to generate the oauth_signature.
require 'cgi'
require 'base64'
require 'openssl'
# encoding: binary
require 'active_model/validator'
class EmailValidator < ActiveModel::EachValidator
EmailAddress = begin
qtext = '[^\\x0d\\x22\\x5c\\x80-\\xff]'
dtext = '[^\\x0d\\x5b-\\x5d\\x80-\\xff]'
atom = '[^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-' +
'\\x3c\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+'
@strukturedkaos
strukturedkaos / index-1.html
Created June 18, 2014 04:33
Beginning of angular task list app index template
<!DOCTYPE html>
<!--[if lt IE 7]> <html lang="en" ng-app="taskListApp" class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html lang="en" ng-app="taskListApp" class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html lang="en" ng-app="taskListApp" class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html lang="en" ng-app="taskListApp" class="no-js"> <!--<![endif]-->
@strukturedkaos
strukturedkaos / dependencies-1.html
Created June 18, 2014 04:35
Dependencies for Angular Task List
<link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.css">
<link href="css/app.css" media="all" rel="stylesheet">
<link href="bower_components/animate.css/animate.min.css" media="all" rel="stylesheet" type="text/css" />
<link href="css/animations.css" media="all" rel="stylesheet">
<link href="bower_components/font-awesome/css/font-awesome.min.css" media=all rel=stylesheet />
<script src="bower_components/modernizr/modernizr.js"></script>