Skip to content

Instantly share code, notes, and snippets.

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

Mark Przepiora markprzepiora

🏠
Working from home
View GitHub Profile
@markprzepiora
markprzepiora / _undeprecate.sh
Last active December 21, 2015 00:59
One-liner for switching over to using "double" instead of "stub" to create test double, the latter of which is deprecated in RSpec 3. This should not touch actual stubbing (e.g. something.stub(awesome: true)), or stubbing of constants for example (e.g., stub_const "MyArray"...)
find spec -name '*.rb' | xargs sed -i '' -E 's/([^.]|^)stub([^_]|$)/\1double\2/g'
@markprzepiora
markprzepiora / copy_bower_components.sh
Last active January 4, 2016 10:09
copy_bower_components
#!/usr/bin/env bash
set -e
# copy_bower_components - A very simple bash script for copying your Bower
# components over to your rails vendor/assets folder.
#
# Copyright (c) 2013 Mark Przepiora
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
@markprzepiora
markprzepiora / gist:61e7e6a3c06e9b573390
Created September 20, 2014 17:46
ActiveRecord 4.2 relationship + callback regression
# Models
class Post < ActiveRecord::Base
after_save :do_something_to_tags
has_many :post_tags, inverse_of: :post
has_many :tags, through: :post_tags
def do_something_to_tags
puts "The following line in Rails 4.2 incorrectly joins on post_id = NULL"
@markprzepiora
markprzepiora / springer-free-maths-books.md
Created December 29, 2015 16:11 — forked from bishboria/springer-free-maths-books.md
Springer have made a bunch of books available for free, here are the direct links
if [ ! -f Serge\ Lang\ -\ SL2\(R\)\ \(978-1-4612-5142-2\).pdf ]; then
echo "downloading 978-1-4612-5142-2"
curl -L http://link.springer.com/content/pdf/10.1007/978-1-4612-5142-2.pdf > Serge\ Lang\ -\ SL2\(R\)\ \(978-1-4612-5142-2\).pdf.tmp
mv Serge\ Lang\ -\ SL2\(R\)\ \(978-1-4612-5142-2\).pdf{.tmp,}
fi
if [ ! -f David\ Cox\ John\ Little\ Donal\ OShea\ -\ Ideals,\ Varieties,\ and\ Algorithms\ \(978-1-4757-2693-0\).pdf ]; then
echo "downloading 978-1-4757-2693-0"
curl -L http://link.springer.com/content/pdf/10.1007/978-1-4757-2693-0.pdf > David\ Cox\ John\ Little\ Donal\ OShea\ -\ Ideals,\ Varieties,\ and\ Algorithms\ \(978-1-4757-2693-0\).pdf.tmp
mv David\ Cox\ John\ Little\ Donal\ OShea\ -\ Ideals,\ Varieties,\ and\ Algorithms\ \(978-1-4757-2693-0\).pdf{.tmp,}
fi
import Ember from 'ember';
export default Ember.Controller.extend({
model: null,
actions: {
// This is fired when the user selects a new time zone
// from the dropdown.
changeTimeZone(tz) {
this.set('model.timeZone', tz);
import Ember from 'ember';
export default Ember.Controller.extend({
model: null,
actions: {
// This is fired when the user selects a new time zone
// from the dropdown.
changeTimeZone(tz) {
this.set('model.timeZone', tz);
@markprzepiora
markprzepiora / controllers.application.js
Last active October 18, 2016 17:40
Clicked outside
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
actions: {
clickOutside(event) {
const $target = Ember.$(event.target);
const clickedOutside = typeof $target.data('outside') !== 'undefined';
alert("Clicked outside: " + (clickedOutside ? "yes" : "no"));
},
# Example:
#
# Content.find_each.with_progress{ |c| do_something(c) }
#
# Will do_something to each content and print out a nice progress bar as it goes
class Enumerator
def with_progress
return to_enum(__callee__) unless block_given?
bar_chars = %w( ▏ ▎ ▍ ▌ ▋ ▊ ▉ )
psql --dbname=postgres --no-psqlrc -c "DROP DATABASE IF EXISTS app_test;"
psql --dbname=postgres --no-psqlrc -c "CREATE DATABASE app_test;"
psql --dbname=app_test --no-psqlrc -c < db/structure.sql
for n in $(seq 2 $parallel_tests_count); do
(
psql --dbname=postgres --no-psqlrc -c "DROP DATABASE IF EXISTS app_test$n;"
psql --dbname=postgres --no-psqlrc -c "CREATE DATABASE app_test$n WITH TEMPLATE app_test;"
) &
done