Skip to content

Instantly share code, notes, and snippets.

View stevepm's full-sized avatar
🏠
Working from home

Steve stevepm

🏠
Working from home
View GitHub Profile
@stevepm
stevepm / app.rb
Created April 14, 2014 19:20
Application File
require 'sinatra/base'
require 'rack-flash'
class App < Sinatra::Application
enable :sessions
use Rack::Flash
helpers do
def h(text)
class Dogs
POOR = (0..5).to_a.sample
AVERAGE = (6..10).to_a.sample
EXCELLENT = (11..15).to_a.sample
def initialize
joe = {
:name => {:first => "Joe", :last=> "Smith"},
:owner_quality => EXCELLENT
}
@stevepm
stevepm / http_response.rb
Last active August 29, 2015 14:01
HttpResponse
require 'fileutils'
class HttpResponse
def initialize(text)
@text = text
@headers = @text.split("\n\n").first
@body = @text.split("\n\n")[1]
end
def headers
# in spec/support/omniauth_macros.rb
module OmniauthMacros
def mock_auth_hash
# The mock_auth configuration allows you to set per-provider (or default)
# authentication hashes to return during integration testing.
OmniAuth.config.mock_auth[:twitter] = {
'provider' => 'twitter',
'uid' => '123545',
'user_info' => {
'name' => 'mockuser',
{
from: 0,
size: 150,
query: {
filtered: {
query: {
bool: {
should: [
function_score: {
query: {
@stevepm
stevepm / elasticsearch.rb
Last active August 29, 2015 14:02
Elastic search query
settings index: {number_of_shards: 1} do
mappings dynamic: 'false' do
indexes :name, analyzer: 'standard', index_options: 'offsets'
indexes :description, analyzer: 'standard', index_options: 'offsets'
indexes :total_downloads, type: 'long'
end
end
def search(query)
__elasticsearch__.search(
@stevepm
stevepm / commenting_spec.rb
Created June 5, 2014 16:14
bootstrap-wsywig5
require 'spec_helper'
feature 'User Profile' do
scenario 'a user can view their comments', js: true do
mock_gem
mock_gem('rails')
log_in
within '#most_downloaded' do
click_link 'faraday'
end
@stevepm
stevepm / anagram.js
Last active August 29, 2015 14:02
anagram
function anagram(word) {
this.word = word;
this.originalWord = wordObject(word);
this.matches = function (wordArray) {
if (typeof wordArray === 'string'){
wordArray = Array.prototype.slice.call(arguments);
}
var wordMatches = [];
for (var i = 0; i < wordArray.length; i++) {
var wordMatcher = wordArray[i];
@stevepm
stevepm / gist:b71f6a2f42ce4a2ad080
Last active August 29, 2015 14:10
Bluemix Rails instructions

#Bluemix Instructions

  • Install cloudfoundry cli
  • rails new MY_APP_NAME -T
  • Add rails_12factor gem to gemfile for logging purposes
  • touch manifest.yml to create the manifest file in your root directory, this will store your Bluemix App config
  • Log in to Bluemix
  • Click Create an app
  • Choose Ruby on Rails runtime towards the bottom
  • Choose your app name and route and then click create
@stevepm
stevepm / designer.html
Created December 10, 2014 22:46
designer
<link rel="import" href="../topeka-elements/category-images.html">
<link rel="import" href="../core-icon/core-icon.html">
<link rel="import" href="../core-icons/core-icons.html">
<link rel="import" href="../core-icons/av-icons.html">
<link rel="import" href="../paper-fab/paper-fab.html">
<polymer-element name="my-element">
<template>
<style>