Skip to content

Instantly share code, notes, and snippets.

☀️
hasta mañana...

Przemek Sobstel sobstel

View GitHub Profile
@sobstel
sobstel / better_conversation.md
Last active Dec 15, 2018
10 ways to have a better conversation (by Celeste Headlee)
View better_conversation.md

10 ways to have a better conversation (by Celeste Headlee)

  1. Don't multitask (be present, be in that moment)
  2. Don't pontificate
  3. Use open-ended questions
  4. Go with the flow
  5. If you don't know, say that you don't know
  6. Don't equate your experience with theirs (it's never the same, all experiences are individual)
  7. Try not to repeat yourself
  8. Stay out of the weeds (people don't care about details)
@sobstel
sobstel / react-native-ios-third-party-build-fix.sh
Created Oct 10, 2018
React Native iOS third-party double-conversion build error fix
View react-native-ios-third-party-build-fix.sh
# error: Build input file cannot be found: '/Users/sobstel/Projects/nabobil/nabobil-mobile/node_modules/react-native/third-party/double-conversion-1.1.6/src/diy-fp.cc'
cd node_modules/react-native/scripts && ./ios-install-third-party.sh && cd ../../../
cd node_modules/react-native/third-party/glog-0.3.5/ && ../../scripts/ios-configure-glog.sh && cd ../../../../
View mvp-cheatsheet.md

MVP cheatsheet

The goal

To prove there is product market fit while taking on the least amount of risk possible.

Steps

1. Define the problem your product solves and what makes your product unique

@sobstel
sobstel / bulk_upsert.rb
Last active Nov 5, 2018
Bulk upsert (Rails/PostgreSQL)
View bulk_upsert.rb
class Data < ApplicationRecord
class << self
def bulk_upsert(values)
transaction do
values.uniq { |v| v[:key] }.each_slice(1000) do |values_slice|
connection.exec_query <<-SQL.squish
INSERT INTO #{table_name}(#{upsert_columns.join(', ')})
VALUES #{upsert_values_statement(values_slice)}
ON CONFLICT(key)
DO UPDATE SET
View effective_ruby.md

Effective Ruby

#1 (Almost) Everything is true

  • Every value is true except false and nil.
  • The number zero is true in Ruby.
  • Use the nil? method to differentiate between false and nil.

#2 All objects could be nil

@sobstel
sobstel / manual_preloading.rb
Created Mar 29, 2018
Rails manual association preloading
View manual_preloading.rb
# taken from https://mrbrdo.wordpress.com/2013/09/25/manually-preloading-associations-in-rails-using-custom-scopessql/
# collection association e.g. has_many
owners = People.all
association_name = :photos
owners.each do |owner|
records = Array(whatever_you_want)
@sobstel
sobstel / loadable.js
Created Mar 4, 2018
Loader/loading Higher-Order Component
View loadable.js
// Sample usage: (taken from https://github.com/sobstel/golazon)
//
// class Competition extends Component {
// (...)
// }
//
// const fetchData = ({ id }) => {
// return competitionService.competition(id).then(competition => ({ competition }));
// };
//
View fetch_with_timeout.js
const API_URL = '...';
const TIMEOUT = 10; // seconds
export default (path) => {
/* global fetch */
const req = fetch(API_URL + path);
const timeout = new Promise((resolve, reject) => {
return setTimeout(() => reject(new Error('request timeout')), TIMEOUT * 1000);
});
@sobstel
sobstel / README
Last active Jan 6, 2018
Climb the stairs (brain friendly, not so cpu friendly)
View README
There's a staircase with N steps, and you can climb 1 or 2 steps at a time.
Given N, write a function that returns the number of unique ways you can
climb the staircase. The order of the steps matters.
For example, if N is 4, then there are 5 unique ways:
1, 1, 1, 1
2, 1, 1
1, 2, 1
@sobstel
sobstel / warden.rb
Last active Feb 20, 2018
Warden Rails cookie
View warden.rb
Warden::Manager.after_authentication do |user, auth, _opts|
cookies = ActionDispatch::Request.new(auth.env).cookie_jar
cookies.encrypted[REMEMBER_ME_COOKIE_NAME] = { value: user.id, expires: 1.week.from_now }
end
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.