Skip to content

Instantly share code, notes, and snippets.

View barnes7td's full-sized avatar

Timothy Barnes barnes7td

  • CleanSlate
  • Indianapolis, IN
View GitHub Profile
@barnes7td
barnes7td / json_filter.rb
Created March 17, 2016 20:24
people_json_filter_bad_data.rb
require 'json'
require 'pp'
file_path = "./current_dossis.json"
dossis = JSON.parse(File.read(file_path))
named_dossis = dossis.reject { |d| d.fetch("name") == nil }
named_dossis = named_dossis.reject { |d| d.fetch("name") == "" }
named_dossis = named_dossis.reject { |d| d.fetch("name").downcase == "nil" }
named_dossis = named_dossis.reject { |d| d.fetch("name").to_s.include? "http" }
require 'rails_helper'
RSpec.describe IncomingController, type: :controller do
include Devise::TestHelpers
let(:user) { User.create!(email: "incoming@user.com",
name: "In Coming",
username: "in_coming",
password: "password",
password_confirmation: "password",

On your assignment:

Because you have a default_scope the other scopes that you created will all be affected by it. Therefore in order to get the right order in your other scopes and ignore the default scope you need to use reorder

default_scope { order('created_at DESC') }
scope :ordered_by_title, -> { reorder('title ASC')}
scope :ordered_by_reverse_created_at, -> { reorder('created_at ASC') }
(ns dubstep)
(defn song-decoder [song]
(clojure.string/trim (clojure.string/replace song #"(WUB)+" " "))
)
@barnes7td
barnes7td / fullcalendar.js
Last active October 1, 2015 13:20
fullcalendar
$(document).ready(function() {
$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,basicWeek,basicDay'
},
defaultDate: '2015-02-12',
editable: true,
@barnes7td
barnes7td / AtomSnippets.md
Last active September 12, 2015 21:14
Atom Snippets

How to Add These Snippets to Atom

  1. Cmd + Shift + P
  2. Select "Application: Open Your Snippets"
  3. Copy and paste the snippets into snippets.cson
  4. Save and close snippets.cson
@barnes7td
barnes7td / gist:c752ef3e636ee523b17a
Last active August 29, 2015 14:22
fb_graph2 gem pry
[6] pry(main)> user = FbGraph2::User.new('me').authenticate('CAACEdEose0cBAOgM5S1Yi4dWgi8B638bw85lZCZBjdyIJZBxbbJI7k5s9OsCcWskpSOZA5eByoPO89JZC9cwpcSnREPMiO5rEZCrLVufTWphtzkg6FvQXmpSJIUI8Ja43ZBf2HNiVGc322j5vxDS8cAey4XSQtrV7dlO5ZAugfLa05h3LcdwgWqXBWZBZAgRuEkK8WDf01DOHzelUTNqslrZB0qOv2CZA2rW2EsZD')
=> #<FbGraph2::User:0x007fcd29585428
@access_token=
"CAACEdEose0cBAOgM5S1Yi4dWgi8B638bw85lZCZBjdyIJZBxbbJI7k5s9OsCcWskpSOZA5eByoPO89JZC9cwpcSnREPMiO5rEZCrLVufTWphtzkg6FvQXmpSJIUI8Ja43ZBf2HNiVGc322j5vxDS8cAey4XSQtrV7dlO5ZAugfLa05h3LcdwgWqXBWZBZAgRuEkK8WDf01DOHzelUTNqslrZB0qOv2CZA2rW2EsZD",
@id="me",
@raw_attributes={}>
[7] pry(main)> user.fetch
=> #<FbGraph2::User:0x007fcd2a56d890
@access_token=
"CAACEdEose0cBAOgM5S1Yi4dWgi8B638bw85lZCZBjdyIJZBxbbJI7k5s9OsCcWskpSOZA5eByoPO89JZC9cwpcSnREPMiO5rEZCrLVufTWphtzkg6FvQXmpSJIUI8Ja43ZBf2HNiVGc322j5vxDS8cAey4XSQtrV7dlO5ZAugfLa05h3LcdwgWqXBWZBZAgRuEkK8WDf01DOHzelUTNqslrZB0qOv2CZA2rW2EsZD",
@barnes7td
barnes7td / same_number.rb
Last active March 12, 2019 01:34
Job Prep Same Number
# Create a method same_number? that takes a string of x's and o's and determines
# if there are the same number of x's as o's. "xooxxxxooxo" has more x's and
# therefore would return false. "xxooxxooxoxo" has the same amount of x's and o's,
# therefore would return true.
def same_number?(str)
end
@barnes7td
barnes7td / url_add_protocol.rb
Last active August 29, 2015 14:19
Add 'http://' to a url
require 'rspec'
# Got REGEX from:
# http://stackoverflow.com/questions/7908598/add-https-to-url-if-its-not-there
def add_url_protocol(url)
if url[/^https?:\/\//]
url
else
"http://#{url}"
@barnes7td
barnes7td / days_left.rb
Created March 30, 2015 16:08
Days Left in Rails (with a 7 day time frame)
# For Blocitoff items
class Item < ActiveRecord::Base
belongs_to :list
def days_to_complete
7.days
end
def due_date
created_at.to_date + days_to_complete