Skip to main content

Posts

Showing posts from March, 2020

setup git account on mac with ssh - push to remote denied with other login

http://burnedpixel.com/blog/setting-up-git-and-github-on-your-mac/#generatenewkey

SSH uses public-key cryptography to authenticate the remote computer and allow it to authenticate the user, if necessary. There are several ways to use SSH; one is to use automatically generated public-private key pairs to simply encrypt a network connection, and then use password authentication to log on.” An SSH key basically lets your computer uniquely identify itself when it connects to servers. If Github is aware of the key your computer is using, you won’t have to enter your Github username/password every time you connect. Check for pre-existing SSH keys on your computer Let’s see if your computer has one or more keys already installed:
12# Point the terminal to the directory that would contain SSH keys for your user account.$ cd ~/.ssh If you get the response “No such file or directory”, skip to Generate a new SSH Key. Otherwise, you’ll need to backup and remove your existing SSH keys. Backup and …

ERROR:root:code for hash md5 was not found.

brew install openssl brew link openssl --force brew uninstall python brew install python --with-brewed-openssl> fsevents@1.2.12 install /Users/junwang/Documents/my-apps/my-app-ts/node_modules/fsevents > node-gyp rebuild ERROR:root:code for hash md5 was not found. Traceback (most recent call last): File "/usr/local/Cellar/python@2/2.7.15_3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py", line 147, in <module> globals()[__func_name] = __get_hash(__func_name) File "/usr/local/Cellar/python@2/2.7.15_3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py", line 97, in __get_builtin_constructor raise ValueError('unsupported hash type ' + name) ValueError: unsupported hash type md5 ERROR:root:code for hash sha1 was not found. Traceback (most recent call last): File "/usr/local/Cellar/python@2/2.7.15_3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py", line 147, in <module> …

change git username

change the current working directory to the local repository where you want to configure the name that is associated with your Git commits. Set a Git username: $ git config user.name "Mona Lisa" Confirm that you have set the Git username correctly: $ git config user.name > Mona Lisa

styled component with MUI

yarn add @material-ui/core<linkrel="stylesheet"href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap"/> <linkrel="stylesheet"href="https://fonts.googleapis.com/icon?family=Material+Icons"/> yarn add @material-ui/iconsyarn add styled-components const StyledButton =styled(Button)` background-color: #6772e5; color: #fff; box-shadow: 0 4px 6px rgba(50, 50, 93, 0.11), 0 1px 3px rgba(0, 0, 0, 0.08); padding: 7px 14px; &:hover { background-color: #5469d4; } `;

Best practices for using Git - amend -m --no-edit

The only thing that I'd add is that you should clean up your git commits in your feature branch before creating a PR. This is easily done with git commit --amend and squashing.Adding the -m option allows you to pass in a new message from the command line without being prompted to open an editor. git commit--amend -m "an updated commit message"# Edit hello.pyand main.py git add hello.py git commit # Realize you forgot toadd the changes from main.py git add main.py git commit --amend --no-edithttps://deepsource.io/blog/git-best-practices/feat: add beta sequence ^--^ ^---------------^ | | | +-> Summary in present tense. | +-------> Type: chore, docs, feat, fix, refactor, style, or test.

jest / mocha / chai for GraphQL api - apollo-server-testing

use Jest:
"test": "jest" use mocha:

package.json
"test": "mocha --require @babel/register ./test/*.test.js"




const { createTestClient } =require("apollo-server-testing"); const { testServer, baseContext } =require("./test-utils/test-server"); const { query, mutate } =createTestClient(testServer); test("something", async () => { // set / reset / merge the context as needed before calling query or mutatetestServer.mergeContext({ req: { headers: { Authorization:`Bearer ${token}` } }, }); constres=awaitquery({ query, variables }); expect(res)... });

check permission for admin on navbar instead of withSession(App) - on every component

AdminNavbarLinks.js:
if (profile && profile.admin !== true && window.location.href.indexOf('/admin') !== -1) { router.push('/login') }

constwithSession = Component=>props=> ( <Queryquery={GET_ME}> {({ data, loading, refetch }) => ( <Component {...props} loading={loading} session={data} refetch={refetch} /> )} </Query> )
exportdefaultwithSession

About GraphQL - Downside

Web caching complexity

File uploading. Since GraphQL doesn’t understand files, a file uploading feature is not included in its specification. You won’t have to deal with this limitation in case of REST, as there you can POST or PUT whatever content you want to.
To allow file uploads in your GraphQL web app, there are several options: using Base64 encoding. But it will make the request larger and expensive to encode/decode.making a separate API endpoint just for this purpose.using a library like Apollo for implementing the GraphQL multipart request specification.uploadFileToS3:combineResolvers( // isAuthenticated, async (parent, args, { models }) => { const { file } = awaitargs const { createReadStream, filename, mimetype, encoding } = awaitfile conststream = createReadStream() constresult = awaituploadFileToS3(filename, stream) returnresult } ),