diff --git a/.envrc b/.envrc new file mode 100644 index 0000000000000000000000000000000000000000..f270360c1d013308d438ccba2d26c5cfcd7f619f --- /dev/null +++ b/.envrc @@ -0,0 +1,2 @@ +source_up +layout pipenv diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..3e66e1d5821e755498f864e372ae1dbe23c29414 --- /dev/null +++ b/.gitignore @@ -0,0 +1,49 @@ +~* +*~ +*.sw[op] +*.py[cod] +.DS_Store +__pycache__/ +.vagrant/ +vendor/ +Thumbs.db +*.retry +.svn/ +.sass-cache/ +*.log +*.out +*.so +node_modules/ +.npm/ +nbproject/ +*.ipynb +.idea/ +*.egg-info/ +*.[ao] +.classpath +.cache/ +bower_components/ +*.class +*.[ewj]ar +secring.* +.*.kate-swp +.swp.* +.directory +.Trash-* +build/ +_build/ +dist/ +.tox/ +*.pdf +*.exe +*.dll +*.gz +*.tgz +*.tar +*.rar +*.zip +*.pid +*.lock +*.env +.bundle/ +!Pipfile.lock diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000000000000000000000000000000000000..bf2f790c5e2671a0ece0fb0cdcf4f9fa1550099e --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,28 @@ +--- +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v2.0.0 + hooks: + - id: check-added-large-files + - id: check-executables-have-shebangs + - id: check-merge-conflict + - id: check-yaml + - id: detect-private-key + - id: flake8 + args: + - '--max-line-length=79' +- repo: https://github.com/ambv/black + rev: 18.9b0 + hooks: + - id: black + language_version: python3.6 + args: + - | + --line-length=79 +- repo: https://github.com/pre-commit/mirrors-pylint.git + rev: v2.1.1 + hooks: + - id: pylint + args: + - | + --disable=invalid-name,import-error,missing-docstring diff --git a/Pipfile b/Pipfile new file mode 100644 index 0000000000000000000000000000000000000000..5a940d9b83c6eb1bb5bc2d4652e4ea9702f722df --- /dev/null +++ b/Pipfile @@ -0,0 +1,14 @@ +[[source]] +url = "https://pypi.org/simple" +verify_ssl = true +name = "pypi" + +[packages] +requests = "*" +parse = "*" + +[dev-packages] +pre-commit = "*" + +[requires] +python_version = "3.6" diff --git a/Pipfile.lock b/Pipfile.lock new file mode 100644 index 0000000000000000000000000000000000000000..b5732ceec1e812cb8c55811a121d817f9df81886 --- /dev/null +++ b/Pipfile.lock @@ -0,0 +1,138 @@ +{ + "_meta": { + "hash": { + "sha256": "98ebdd3e85cb2f22dd8d72ef5c193c6f12db85a2f7148433b5f04a12d5ed0517" + }, + "pipfile-spec": 6, + "requires": { + "python_version": "3.6" + }, + "sources": [ + { + "name": "pypi", + "url": "https://pypi.org/simple", + "verify_ssl": true + } + ] + }, + "default": { + "certifi": { + "hashes": [ + "sha256:339dc09518b07e2fa7eda5450740925974815557727d6bd35d319c1524a04a4c", + "sha256:6d58c986d22b038c8c0df30d639f23a3e6d172a05c3583e766f4c0b785c0986a" + ], + "version": "==2018.10.15" + }, + "chardet": { + "hashes": [ + "sha256:84ab92ed1c4d4f16916e05906b6b75a6c0fb5db821cc65e70cbd64a3e2a5eaae", + "sha256:fc323ffcaeaed0e0a02bf4d117757b98aed530d9ed4531e3e15460124c106691" + ], + "version": "==3.0.4" + }, + "idna": { + "hashes": [ + "sha256:156a6814fb5ac1fc6850fb002e0852d56c0c8d2531923a51032d1b70760e186e", + "sha256:684a38a6f903c1d71d6d5fac066b58d7768af4de2b832e426ec79c30daa94a16" + ], + "version": "==2.7" + }, + "parse": { + "hashes": [ + "sha256:9dd6048ea212cd032a342f9f6aa2b7bc222f7407c7e37bdc2777fecd36897437" + ], + "index": "pypi", + "version": "==1.9.0" + }, + "requests": { + "hashes": [ + "sha256:99dcfdaaeb17caf6e526f32b6a7b780461512ab3f1d992187801694cba42770c", + "sha256:a84b8c9ab6239b578f22d1c21d51b696dcfe004032bb80ea832398d6909d7279" + ], + "index": "pypi", + "version": "==2.20.0" + }, + "urllib3": { + "hashes": [ + "sha256:41c3db2fc01e5b907288010dec72f9d0a74e37d6994e6eb56849f59fea2265ae", + "sha256:8819bba37a02d143296a4d032373c4dd4aca11f6d4c9973335ca75f9c8475f59" + ], + "version": "==1.24" + } + }, + "develop": { + "aspy.yaml": { + "hashes": [ + "sha256:04d26279513618f1024e1aba46471db870b3b33aef204c2d09bcf93bea9ba13f", + "sha256:0a77e23fafe7b242068ffc0252cee130d3e509040908fc678d9d1060e7494baa" + ], + "version": "==1.1.1" + }, + "cached-property": { + "hashes": [ + "sha256:3a026f1a54135677e7da5ce819b0c690f156f37976f3e30c5430740725203d7f", + "sha256:9217a59f14a5682da7c4b8829deadbfc194ac22e9908ccf7c8820234e80a1504" + ], + "version": "==1.5.1" + }, + "cfgv": { + "hashes": [ + "sha256:73f48a752bd7aab103c4b882d6596c6360b7aa63b34073dd2c35c7b4b8f93010", + "sha256:d1791caa9ff5c0c7bce80e7ecc1921752a2eb7c2463a08ed9b6c96b85a2f75aa" + ], + "version": "==1.1.0" + }, + "identify": { + "hashes": [ + "sha256:5e956558a9a1e3b3891d7c6609fc9709657a11878af288ace484d1a46a93922b", + "sha256:623086059219cc7b86c77a3891f3700cb175d4ce02b8fb8802b047301d71e783" + ], + "version": "==1.1.7" + }, + "nodeenv": { + "hashes": [ + "sha256:aa040ab5189bae17d272175609010be6c5b589ec4b8dbd832cc50c9e9cb7496f" + ], + "version": "==1.3.2" + }, + "pre-commit": { + "hashes": [ + "sha256:98ec318db1f255e3d5089ae416959ef3c775215a3509620027d446eeabbba740", + "sha256:b68f9219c56b50ebafb57f378c5325f9876d06fb29e9cd05daf5cbd6676ce8f2" + ], + "index": "pypi", + "version": "==1.11.2" + }, + "pyyaml": { + "hashes": [ + "sha256:254bf6fda2b7c651837acb2c718e213df29d531eebf00edb54743d10bcb694eb", + "sha256:3108529b78577327d15eec243f0ff348a0640b0c3478d67ad7f5648f93bac3e2", + "sha256:3c17fb92c8ba2f525e4b5f7941d850e7a48c3a59b32d331e2502a3cdc6648e76", + "sha256:8d6d96001aa7f0a6a4a95e8143225b5d06e41b1131044913fecb8f85a125714b", + "sha256:c8a88edd93ee29ede719080b2be6cb2333dfee1dccba213b422a9c8e97f2967b" + ], + "version": "==4.2b4" + }, + "six": { + "hashes": [ + "sha256:70e8a77beed4562e7f14fe23a786b54f6296e34344c23bc42f07b15018ff98e9", + "sha256:832dc0e10feb1aa2c68dcc57dbb658f1c7e65b9b61af69048abc87a2db00a0eb" + ], + "version": "==1.11.0" + }, + "toml": { + "hashes": [ + "sha256:229f81c57791a41d65e399fc06bf0848bab550a9dfd5ed66df18ce5f05e73d5c", + "sha256:235682dd292d5899d361a811df37e04a8828a5b1da3115886b73cf81ebc9100e" + ], + "version": "==0.10.0" + }, + "virtualenv": { + "hashes": [ + "sha256:2ce32cd126117ce2c539f0134eb89de91a8413a29baac49cbab3eb50e2026669", + "sha256:ca07b4c0b54e14a91af9f34d0919790b016923d157afda5efdde55c96718f752" + ], + "version": "==16.0.0" + } + } +} diff --git a/README.md b/README.md new file mode 100644 index 0000000000000000000000000000000000000000..c02ee24425dce82ea7c0b91dfc116f6291102372 --- /dev/null +++ b/README.md @@ -0,0 +1,34 @@ +# HiringSolved challenge + +My solution to the HiringSolved challenge. If anyone from HiringSolved is +reading this, my actual site is at <https://www.shore.co.il/blog>. + +1. __Math challenge__: + + I did it in my head. + +1. __Haystack challenge__: + + I googled the question and copied the answer from +<https://puzzling.stackexchange.com/a/59513>. + +1. __Breadcrumbe challenge__: + + For this I wrote some Python. The code is in `breadcrumbs.py` and to run it +you need Python 3.6 and pipenv (I also use direnv for convience). To use it run +`pipenv run ./breadcrumbs.py`. + +1. __Monster challenge__: + + From reading the cookies from the previous challenge, I searched the DOM for +`true` and found `true-blue`, took the color hex from there and added to the +URL. + +1. __Post challenge__: + + Not much of a challenge. I fiddled a bit with `curl` and posted using the +following command: + +``` +curl -XPOST 'https://challenge.hiringsolved.com/REDACTED?hirable=true&name=Nimrod+Adar&email=nimrod@shore.co.il&website=https://github.com/adarnimrod/hs-challenge' +``` diff --git a/breadcrumbs.py b/breadcrumbs.py new file mode 100755 index 0000000000000000000000000000000000000000..a96eadb9f81088f94c0a5f21acc2070e90e67487 --- /dev/null +++ b/breadcrumbs.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python3 +from sys import stderr +from requests import get +from parse import ( # pylint: disable=redefined-builtin,no-name-in-module + compile, +) + +BASE_URL = "https://challenge.hiringsolved.com/breadcrumbs/" +INITIAL_CRUMB = 19196 +NEXT_PARSER = compile("the next breadcrumb is {:d}", case_sensitive=True) +SUBTRACT_PARSER = compile( + "Yes. Subtract {:d} and keep going.", case_sensitive=True +) +ADD_PARSER = compile("Yes. Add {:d} and keep going.", case_sensitive=True) + + +if __name__ == "__main__": + crumb = INITIAL_CRUMB + previous = "" + while True: + r = get(BASE_URL + str(crumb)) + print(r.cookies.get("info")) + print(r.text, file=stderr) + if r.text == previous: + print("Stuck on the same message.", file=stderr) + exit(1) + previous = r.text + if NEXT_PARSER.search(r.text): + crumb = NEXT_PARSER.search(r.text)[0] + elif ADD_PARSER.search(r.text): + crumb = crumb + ADD_PARSER.search(r.text)[0] + elif SUBTRACT_PARSER.search(r.text): + crumb = crumb - SUBTRACT_PARSER.search(r.text)[0] + else: + print("Don't know what to do.", file=stderr) + exit(1)