Skip to content

Instantly share code, notes, and snippets.

View erdostom's full-sized avatar

Tamas Erdos erdostom

View GitHub Profile
@erdostom
erdostom / git_patch.md
Last active February 9, 2023 13:57
Export a commit and apply it to a different directory

Make sure the destination repo has the origin repo added as a remote

  1. Export the patch (from the highest up directory) git format-patch --relative -1 <SHA> --stdout > ~/file.patch
  2. Import the patch (from repo root): git am -3 --directory=<DIR> ~/file.patch

The Padlock Problem

Alice wants to propose to Bob by sending him an emerald ring (screw diamonds). The problem is that Alice lives in New York and Bob lives in Moscow. All correspondence between them is subject to inspection and confiscation by Russian customs officials, unless it is secured via a lock. How can Alice send Bob the emerald ring without risk of confiscation?

She could try to send a padlocked package and then the key in separate package, but of course the the customs officials could intercept the key. She could also use a combination lock, but then how would she send the code in a secure way?

There is a solution that doesn't require external systems: Alice sends the locked package to Bob. Bob then adds his own lock to the package and sends it back to Alice. Alice removes the lock she placed with her key and sends the package (now secured only with Bob's lock) to him. Bob removes his lock and opens the package! Everyone lives happily ever after (except the customs officials).

@erdostom
erdostom / human_factors.mdown
Created March 31, 2020 14:39
Rules of Thumb For UX

Rules of Thumb For UX

These rules are more than 20 years old, but as valid as ever. Some things change. The way humans think, doesn't.

  • Know thy user, and YOU are not thy user.
  • Things that look the same should act the same.
  • Everyone makes mistakes, so every mistake should be fixable.
  • The information for the decision needs to be there when the decision is needed.
  • Error messages should actually mean something to the user, and tell the user how to fix the problem.
  • Every action should have a reaction.
@erdostom
erdostom / prime_factors.rb
Created December 7, 2019 07:41
print prime factors
def get_factors(number)
(2...number).each do |n|
if number % n == 0
return [get_factors(n), get_factors(number / n)]
end
end
return number
end
def print_factors(number)
@erdostom
erdostom / Dockerfile
Last active November 25, 2022 14:53
Good starter Dockerfile + docker-compose.yml for Rails 6.
FROM ruby:2.6.5-alpine
RUN apk add --update --no-cache bash build-base nodejs sqlite-dev tzdata postgresql-dev yarn
RUN gem install bundler:2.1.4
WORKDIR /usr/src/app
COPY package.json yarn.lock ./
RUN yarn install --check-files
@erdostom
erdostom / consoleSave.js
Created February 7, 2017 16:08
save an object to json from chrome console
(function(console){
console.save = function(data, filename){
if(!data) {
console.error('Console.save: No data')
return;
}
if(!filename) filename = 'console.json'
@erdostom
erdostom / raills_helper.rb
Created March 17, 2016 21:51
database cleaner for js: true
RSpec.configure do |config|
# If you're not using ActiveRecord, or you'd prefer not to run
# each of your examples within a transaction, remove the following
# line or assign false instead of true.
config.use_transactional_fixtures = false
# Clean up and initialize database before
# running test exmaples
config.before(:suite) do
# Truncate database to clean up garbage from
@erdostom
erdostom / application.rb
Created October 26, 2015 18:48
Force IE away from compatibility mode
# config/application.rb
config.action_dispatch.default_headers.merge!('X-UA-Compatible' => 'IE=edge')

Keybase proof

I hereby claim:

  • I am erdostom on github.
  • I am erdostom (https://keybase.io/erdostom) on keybase.
  • I have a public key whose fingerprint is 41EE 8B48 D8C3 7189 7FAB 5418 5944 38F1 AA77 42EA

To claim this, I am signing this object:

They gave out dark glasses that you could watch it with. Dark glasses! Twenty miles away, you couldn't see a damn thing through dark glasses. So I figured the only thing that could really hurt your eyes (bright light can never hurt your eyes) is ultraviolet light. I got behind a truck windshield, because the ultraviolet can't go through glass, so that would be safe, and so I could see the damn thing.

Time comes, and this tremendous flash out there is so bright that I duck, and I see this purple splotch on the floor of the truck. I said, "That's not it. That's an after-image." So I look back up, and I see this white light changing into yellow and then into orange. Clouds form and disappear again-- from the compression and expansion of the shock wave.

Finally, a big ball of orange, the center that was so bright, becomes a ball of orange that starts to rise and billow a little bit and get a little black around the edges, and then you see it's a big ball of smoke with flashes on the inside, with the heat of