Skip to content

Instantly share code, notes, and snippets.

@artemf
artemf / README.md
Last active September 4, 2018 10:39
Refactoring the infamous `CommentsController#create` from Lobste.rs

Refactoring the infamous CommentsController#create from Lobste.rs

This refacatoring was inspired by this comment on Lobste.rs code on Reddit. Someone noted that the code is a mess, especially CommentsController#create method. I glanced over suggested solutions and haven't found anything simple and effective.

I have grown to love simple code. Simple code is easy to test, easy to understand, easy to maintain, easy to add features to. Some authors provided even more complicated alternatives to the original mess, sometimes thier solutions where 2-3 times larger (in LOC) than the original spread across files! Tell me about code simplicity!

Benefits (Advantages)

  • Uses simple Rails code style for controllers. No service objects, no nothing. Simple before_action hooks and private helper methods that encapsulate pieces of logic that can be safely extracted from the main controller method. The logic is pre

Keybase proof

I hereby claim:

  • I am artemf on github.
  • I am artemf (https://keybase.io/artemf) on keybase.
  • I have a public key whose fingerprint is 6916 1AB7 C216 C173 A1D8 4B96 284A 5D56 56AB 29C1

To claim this, I am signing this object:

@artemf
artemf / gist:e5c2025c66098be06c92
Created March 27, 2015 02:41
CURL request to Fastly docs without VPN
artemf$ curl -vs --compressed https://docs.fastly.com/guides/caching/ -o /dev/null
* Adding handle: conn: 0x7fe600804400
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 0 (0x7fe600804400) send_pipe: 1, recv_pipe: 0
* About to connect() to docs.fastly.com port 443 (#0)
* Trying 103.245.222.249...
* Connected to docs.fastly.com (103.245.222.249) port 443 (#0)
* TLS 1.2 connection using TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256
@artemf
artemf / gist:9e97c0074d29359959b2
Created March 27, 2015 02:35
CURL request to css with headers via VPN
artemf$ curl -vs --compressed http://glavdigest.ru/assets/application-dbf66ede5cbd79b735916ac1a6c740c4.css -o /dev/null
* Adding handle: conn: 0x7ff683000000
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 0 (0x7ff683000000) send_pipe: 1, recv_pipe: 0
* About to connect() to glavdigest.ru port 80 (#0)
* Trying 103.245.222.249...
* Connected to glavdigest.ru (103.245.222.249) port 80 (#0)
> GET /assets/application-dbf66ede5cbd79b735916ac1a6c740c4.css HTTP/1.1
@artemf
artemf / gist:f2bc1896f82db56fdabd
Last active August 29, 2015 14:17
CURL request to css with headers
artemf$ curl -vs --compressed http://glavdigest.ru/assets/application-dbf66ede5cbd79b735916ac1a6c740c4.css -o /dev/null
* Adding handle: conn: 0x7fd3e2004400
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 0 (0x7fd3e2004400) send_pipe: 1, recv_pipe: 0
* About to connect() to glavdigest.ru port 80 (#0)
* Trying 103.245.222.249...
* Connected to glavdigest.ru (103.245.222.249) port 80 (#0)
> GET /assets/application-dbf66ede5cbd79b735916ac1a6c740c4.css HTTP/1.1
curl "http://ivvi-itss.herokuapp.com/sentence_audio_timing.json" -d '{"iso_language":"eng","audio_file":"https://s3.amazonaws.com/iVVi-Audio/uploads/story/source_mp3_filename/41/iVVi_Charlie_01-09-13.wav","sentence_list":[{"sentence_sequence":1,"sentence_text":"Charlemagne – A Really Big Dog.","sentence_char_count":26},{"sentence_sequence":2,"sentence_text":"Charlemagne (we call him Charlie) came home as a small puppy only 8 weeks old.","sentence_char_count":64},{"sentence_sequence":3,"sentence_text":"When he was really young he had what looked like an old man’s beard.","sentence_char_count":55},{"sentence_sequence":4,"sentence_text":"Charlie liked to eat EVERYTHING in sight.","sentence_char_count":35},{"sentence_sequence":5,"sentence_text":"He not only ate his food, but he also ate wood, dirt, flowers - and even worms!","sentence_char_count":63},{"sentence_sequence":6,"sentence_text":"Soon he was growing faster.","sentence_char_count":23},{"sentence_sequence":7,"sentence_text":"And faster.","sentence_char_co
@artemf
artemf / tox_only_test_blackbox.txt
Created February 5, 2014 19:41
[wal-e] Tox only tests/test_blackbox.py
$ tox -e py27 -- tests/test_blackbox.py
GLOB sdist-make: /Users/artemf/Projects/wal-e/setup.py
py27 inst-nodeps: /Users/artemf/Projects/wal-e/.tox/dist/wal-e-0.7a3.zip
py27 runtests: commands[0] | python setup.py develop
running develop
running egg_info
writing requirements to wal_e.egg-info/requires.txt
writing wal_e.egg-info/PKG-INFO
writing top-level names to wal_e.egg-info/top_level.txt
writing dependency_links to wal_e.egg-info/dependency_links.txt
@artemf
artemf / tox_second_run.txt
Created February 5, 2014 19:39
[wal-e] Tox second run
$ tox -e py27
GLOB sdist-make: /Users/artemf/Projects/wal-e/setup.py
py27 inst-nodeps: /Users/artemf/Projects/wal-e/.tox/dist/wal-e-0.7a3.zip
py27 runtests: commands[0] | python setup.py develop
running develop
running egg_info
writing requirements to wal_e.egg-info/requires.txt
writing wal_e.egg-info/PKG-INFO
writing top-level names to wal_e.egg-info/top_level.txt
writing dependency_links to wal_e.egg-info/dependency_links.txt
@artemf
artemf / tox_first_run.txt
Created February 5, 2014 19:39
[wal-e] Tox first run
$ tox -e py27
GLOB sdist-make: /Users/artemf/Projects/wal-e/setup.py
py27 create: /Users/artemf/Projects/wal-e/.tox/py27
py27 installdeps: pytest, pytest-capturelog, pytest-cov, pytest-flakes, pytest-pep8, pytest-xdist
py27 inst: /Users/artemf/Projects/wal-e/.tox/dist/wal-e-0.7a3.zip
py27 runtests: commands[0] | python setup.py develop
running develop
running egg_info
writing requirements to wal_e.egg-info/requires.txt
writing wal_e.egg-info/PKG-INFO