Skip to content

Instantly share code, notes, and snippets.

🏠
Working from home

Mark Przepiora markprzepiora

🏠
Working from home
Block or report user

Report or block markprzepiora

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@markprzepiora
markprzepiora / gist:61e7e6a3c06e9b573390
Created Sep 20, 2014
ActiveRecord 4.2 relationship + callback regression
View gist:61e7e6a3c06e9b573390
# 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 / _undeprecate.sh
Last active Dec 21, 2015
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"...)
View _undeprecate.sh
find spec -name '*.rb' | xargs sed -i '' -E 's/([^.]|^)stub([^_]|$)/\1double\2/g'
@markprzepiora
markprzepiora / springer-free-maths-books.md
Created Dec 29, 2015 — forked from bishboria/springer-free-maths-books.md
Springer have made a bunch of books available for free, here are the direct links
View download-springer-books.sh
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
View copy_bower_components.sh
#!/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
View application.controller.js
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);
View application.controller.js
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);
View controllers.application.js
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"));
},
View with_progress.rb
# 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( ▏ ▎ ▍ ▌ ▋ ▊ ▉ )
View reset_test_dbs.sh
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
You can’t perform that action at this time.