Skip to content

Instantly share code, notes, and snippets.

Avatar

Robert Fletcher mockdeep

View GitHub Profile
View nodeify.rb
require 'active_support/all'
class JsFile
attr_accessor :path, :file_contents
def initialize(path)
@path = path
@file_contents = File.read(@path)
end
@mockdeep
mockdeep / bulk_updateable.rb
Created Oct 29, 2015
module to add ActiveRecord bulk update functionality for postgres
View bulk_updateable.rb
module BulkUpdatable
def bulk_update(objects, attribute)
return unless objects.any?
query = build_query_for(objects, attribute)
connection.execute(query)
end
private
View restful_store.js
'use strict';
var _ = require('lodash');
var request = require('../helpers').request;
module.exports = {
models: [],
loaded: false,
@mockdeep
mockdeep / puma.rb
Created Apr 15, 2015
Puma with worker killer
View puma.rb
# config/puma.rb
workers Integer(ENV['WEB_CONCURRENCY'] || 1)
threads_count = Integer(ENV['MAX_THREADS'] || 2)
threads threads_count, threads_count
preload_app!
rackup DefaultRackup
port ENV['PORT'] || 3000
@mockdeep
mockdeep / Card.js.jsx
Last active Aug 29, 2015
React DnD example simplified
View Card.js.jsx
(function () {
'use strict';
window.Card = React.createClass({
mixins: [ReactDND.DragDropMixin],
statics: {
configureDragDrop: function(register) {
register('card', {
dragSource: {
@mockdeep
mockdeep / jslist.js
Last active Aug 29, 2015
javascript todo list app, ugly code
View jslist.js
(function () {
'use strict';
var itemTemplate = $('#templates .item');
var list = $('#list');
// when I load the page, I want to get the tasks from the API
$.ajax({
type: 'GET',
url: "https://listalous.herokuapp.com/lists/lobatis-list",
@mockdeep
mockdeep / pub_sub.js
Last active Aug 29, 2015
javascript pub/sub
View pub_sub.js
var events = (function(){
var topics = {};
function getQueue(topic) {
topics[topic] = topics[topic] || [];
return topics[topic];
}
return {
subscribe: function(topic, listener) {
@mockdeep
mockdeep / spec_helper.rb
Last active Oct 7, 2019
A spec helper file for managing database cleaner configuration
View spec_helper.rb
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'capybara/rspec'
RSpec.configure do |config|
config.use_transactional_fixtures = false
config.treat_symbols_as_metadata_keys_with_true_values = true
@mockdeep
mockdeep / exampes.rb
Last active Jan 4, 2016
List rspec example groups
View exampes.rb
#!/usr/bin/env ruby
ENV['RAILS_ENV'] = 'test'
require_relative '../config/environment'
class Speccer
def configuration
@configuration ||= RSpec::Core::Configuration.new
end
@mockdeep
mockdeep / trashable.rb
Last active Dec 28, 2015
module to make accidentally deleting records really hard
View trashable.rb
module Trashable
module ClassMethods
def dependent_associations
reflect_on_all_associations.select do |association|
[:destroy, :delete_all].include?(association.options[:dependent])
end
end