Skip to content

Instantly share code, notes, and snippets.

Avatar

Csaba Apagyi thisismydesign

View GitHub Profile
@thisismydesign
thisismydesign / README.md
Created Dec 11, 2019
Ruby docker image and bundler version
View README.md

Ruby's docker images (e.g. ruby:2.6.3) use bundler v1 (e.g. 1.17.3), see: https://github.com/docker-library/ruby/issues/268#issuecomment-469491078

When bundling with bundler v2 locally it can lead to the the following exception:

Could not find 'bundler' (2.0.2) required by your /app/Gemfile.lock. (Gem::GemNotFoundException)

Solve this by using the correct bundle version locally:

gem install bundler -v 1.17.3
View main.dart
void main() {
// Typed variables raise type errors
var typed1 = 1;
// typed1 = '2';
int typed2;
// typed2 = '2';
// Dynamic types don't raise type errors
var a;
a = 1;
@thisismydesign
thisismydesign / ruby_is_very_easy.rb
Created Jun 28, 2019
Debugging journal #1 - This will obviously not work. Right?.. /2
View ruby_is_very_easy.rb
h.select(&:matcher)
# => {:a=>"this"}
# Sorry what?
@thisismydesign
thisismydesign / ruby_is_easy.rb
Last active Jun 28, 2019
Debugging journal #1 - This will obviously not work. Right?.. /1
View ruby_is_easy.rb
# irb / rails c / whatever
h = { a: "this", b: "that" }
h.select{ |k, v| v.match?("this") }
# => {:a=>"this"}
def matcher(string)
string.match?("this")
end
@thisismydesign
thisismydesign / association_loading.rb
Last active Jun 12, 2019
Load first records of ordered association for a collection without N+1 queries
View association_loading.rb
# https://github.com/rails/rails/issues/6769
# https://github.com/rails/rails/issues/10621
# https://stackoverflow.com/questions/19353507/eager-loading-the-first-record-of-an-association
# https://stackoverflow.com/questions/29142478/eager-load-only-first-associations-with-activerecord
# https://stackoverflow.com/questions/46415817/eager-loading-not-working-with-order-clause-in-rails
# https://stackoverflow.com/questions/52889750/eager-loading-with-scope-in-rails
# https://stackoverflow.com/questions/30056163/eager-loading-in-deep-level-nested-association
# https://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#module-ActiveRecord::Associations::ClassMethods-label-Eager+loading+of+associations
# https://stackoverflow.com/questions/29804377/rails-4-eager-load-limit-subquery
# https://stackoverflow.com/questions/6477614/how-do-you-do-eager-loading-with-limits
@thisismydesign
thisismydesign / test.js
Last active Feb 10, 2019
Mocking per test case with Jest /1
View test.js
jest.mock("MyOtherComponent", () => {
return require
.requireActual("TestUtils")
.mockOriginalFunctionality("MyOtherComponent");
});
describe("<Component />", () => {
it("works", () => {
// MyOtherComponent works as usual
}):
@thisismydesign
thisismydesign / TestUtils.js
Created Feb 10, 2019
Mocking per test case with Jest /2
View TestUtils.js
export const mockOriginalFunctionality = name => {
const actualModule = require.requireActual(name);
return {
...Object.getOwnPropertyNames(actualModule)
.map(functionName => {
return {
[functionName]: jest.fn().mockImplementation(() => {
return actualModule[functionName]();
})
@thisismydesign
thisismydesign / test.js
Created Feb 10, 2019
Mocking per test case with Jest /1
View test.js
describe("<Component />", () => {
it("works", () => {
// ...
}):
describe("when something silly happens", () => {
beforeEach(() => {
jest.mock("MyOtherComponent", () => {
// ...
})
@thisismydesign
thisismydesign / the_worst_is.js
Created Feb 1, 2019
JavaScript is not a language
View the_worst_is.js
// https://codeburst.io/javascript-null-vs-undefined-20f955215a2
// With default parameters, `null` does not use default parameters
let logDefault = (str = 'default') => {
console.log(str);
}
logHi();
// => hi
logHi(undefined);
// => hi
@thisismydesign
thisismydesign / test.rb
Last active Jan 26, 2019
Ruby: When and how to use factories for seeding? /3
View test.rb
# db/seeds/test.rb
build_stubbed(:user)
def seed_user_pagination_data
FactoryBot.create_list(:user, 10)
end
# user_spec.rb
it "returns user" do
# ...
You can’t perform that action at this time.