Skip to content

Instantly share code, notes, and snippets.

View sobstel's full-sized avatar

Przemek Sobstel sobstel

View GitHub Profile
@sobstel
sobstel / createSequentialNavigator.js
Created April 29, 2020 16:43
React Navigation (v4) sequential navigator
// @flow
import React, { Component } from 'react';
import _ from 'lodash';
import createStackNavigator from './createStackNavigator';
type Props = {
navigation: *,
};
const DEFAULT_CONFIG = {
@sobstel
sobstel / typescript-cheatsheet.ts
Last active October 11, 2019 10:41
TypeScript cheatsheet
// same arg type and return type
withUID<T>(obj: T)
// "extends" helps providing some constraints
// eg <T extends object>
withUID({a: 1}) // valid
withUID("wrong way") // NOT valid
// default value type (string)
A<T=string> { name: T }
@sobstel
sobstel / router.rb
Last active November 13, 2019 12:59
Simple Ruby router
class Router
Route = Struct.new(:pattern, :block)
class RouteSet
def on(pattern, &block)
Router.routes.push Route.new(pattern, block)
end
end
@routes = []
@sobstel
sobstel / no_simulator.txt
Last active July 12, 2019 12:36
React Native "Could not find iPhone simulator"
❯ react-native run-ios --simulator="iPhone 7"
Found Xcode workspace Nabobil.xcworkspace
Could not find iPhone 7 simulator
Error: Could not find iPhone 7 simulator
at resolve (...)
sed -i '' 's/startsWith/includes/g' node_modules/react-native/local-cli/runIOS/findMatchingSimulator.js
@sobstel
sobstel / better_conversation.md
Last active December 15, 2018 18:14
10 ways to have a better conversation (by Celeste Headlee)

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 October 10, 2018 07:37
React Native iOS third-party double-conversion build error fix
# 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 ../../../../
@sobstel
sobstel / mvp-cheatsheet.md
Last active August 22, 2018 07:05
MVP cheatsheet

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 July 11, 2022 17:00
Bulk upsert (Rails/PostgreSQL)
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
@sobstel
sobstel / effective_ruby.md
Last active November 10, 2023 20:20
Effective Ruby

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 March 29, 2018 18:36
Rails manual association preloading
# 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)