Skip to content

Instantly share code, notes, and snippets.

View mockdeep's full-sized avatar

Robert Fletcher mockdeep

View GitHub Profile
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 October 29, 2015 17:13
module to add ActiveRecord bulk update functionality for postgres
module BulkUpdatable
def bulk_update(objects, attribute)
return unless objects.any?
query = build_query_for(objects, attribute)
connection.execute(query)
end
private
'use strict';
var _ = require('lodash');
var request = require('../helpers').request;
module.exports = {
models: [],
loaded: false,
@mockdeep
mockdeep / puma.rb
Created April 15, 2015 01:58
Puma with worker killer
# 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 August 29, 2015 14:19
React DnD example simplified
(function () {
'use strict';
window.Card = React.createClass({
mixins: [ReactDND.DragDropMixin],
statics: {
configureDragDrop: function(register) {
register('card', {
dragSource: {
@mockdeep
mockdeep / jslist.js
Last active August 29, 2015 14:17
javascript todo list app, ugly code
(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 August 29, 2015 14:07
javascript pub/sub
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 October 7, 2019 07:19
A spec helper file for managing database cleaner configuration
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 January 4, 2016 20:49
List rspec example groups
#!/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 December 28, 2015 22:49
module to make accidentally deleting records really hard
module Trashable
module ClassMethods
def dependent_associations
reflect_on_all_associations.select do |association|
[:destroy, :delete_all].include?(association.options[:dependent])
end
end