Skip to content

Instantly share code, notes, and snippets.

View dhruvdcoder's full-sized avatar

Dhruvesh dhruvdcoder

View GitHub Profile
@dhruvdcoder
dhruvdcoder / notebook_script_template.py
Last active May 13, 2021 01:12
Template to start a notebook which will ultimately be converted into a script.
# utils.py
from typing import List, Tuple, Union, Dict, Any, Optional
def isnotebook() -> bool:
try:
shell = get_ipython().__class__.__name__ # type:ignore
if shell == "ZMQInteractiveShell":
return True # Jupyter notebook or qtconsole
elif shell == "TerminalInteractiveShell":
@dhruvdcoder
dhruvdcoder / darglint.vim
Last active September 17, 2020 15:00
Vim script to add darglint as a linter in Vim ALE
" Author: Dhruvesh Patel <[email protected]>
" Description: darglint support for optional python typechecking
"echo loaded
call ale#Set('python_darglint_executable', 'darglint')
"call ale#Set('python_mypy_ignore_invalid_syntax', 0)
call ale#Set('python_darglint_options', '')
call ale#Set('python_darglint_use_global', get(g:, 'ale_use_global_executables', 0))
call ale#Set('python_darglint_auto_pipenv', 0)
function! ale_linters#python#darglint#GetExecutable(buffer) abort
@dhruvdcoder
dhruvdcoder / glove_to_pytorch.py
Created April 12, 2019 21:17
Load glove embeddings into pytorch
# convert glove to word2vec format
from gensim.scripts.glove2word2vec import glove2word2vec
glove2word2vec(glove_input_file="emb.txt", word2vec_output_file="emb_word2vec_format.txt")
import gensim
import torch
model = gensim.models.KeyedVectors.load_word2vec_format('emb_word2vec_format.txt')
weights = torch.FloatTensor(model.vectors)
# Ref: https://stackoverflow.com/questions/37793118/load-pretrained-glove-vectors-in-python
@dhruvdcoder
dhruvdcoder / gitdiff.md
Last active October 8, 2018 10:03
Cheatsheet for git diff command
  1. Diff particular file on two branches

    git diff mybranch master -- myfile.cs
    
  2. Show names of changed files between branches

@dhruvdcoder
dhruvdcoder / vimdiff.md
Last active April 30, 2020 23:22 — forked from mattratleph/vimdiff.md
vimdiff cheat sheet

vimdiff cheat sheet

##git mergetool

In the middle file (future merged file), you can navigate between conflicts with ]c and [c.

Choose which version you want to keep with :diffget //2 or :diffget //3 (the //2 and //3 are unique identifiers for the target/master copy and the merge/branch copy file names).

:diffupdate (to remove leftover spacing issues)

:only (once you’re done reviewing all conflicts, this shows only the middle/merged file)

@dhruvdcoder
dhruvdcoder / Vim.md
Last active February 13, 2019 04:13

Spell

task command
spell on :set spell
spell off :set nospell
check spellings in syntax items as well :syntax spell toplevel
add spell file to save spelling exceptions $ mkdir -p ~/.vim/spell/
set the spell file :set spellfile=~/.vim/spell/en.utf-8.add
see spell suggestions z=
add exception to spell file zg
@dhruvdcoder
dhruvdcoder / psql-error-fix.md
Created September 20, 2018 11:47 — forked from AtulKsol/psql-error-fix.md
Solution of psql: FATAL: Peer authentication failed for user “postgres” (or any user)

psql: FATAL: Peer authentication failed for user “postgres” (or any user)

The connection failed because by default psql connects over UNIX sockets using peer authentication, that requires the current UNIX user to have the same user name as psql. So you will have to create the UNIX user postgres and then login as postgres or use sudo -u postgres psql database-name for accessing the database (and psql should not ask for a password).

If you cannot or do not want to create the UNIX user, like if you just want to connect to your database for ad hoc queries, forcing a socket connection using psql --host=localhost --dbname=database-name --username=postgres (as pointed out by @meyerson answer) will solve your immediate problem.

But if you intend to force password authentication over Unix sockets instead of the peer method, try changing the following pg_hba.conf* line:

from

@dhruvdcoder
dhruvdcoder / github_graphql_schema.json
Created September 14, 2018 07:17
Complete schema of github's graphql endpoint
This file has been truncated, but you can view the full file.
{
"data": {
"__schema": {
"queryType": {
"name": "Query"
},
"mutationType": {
"name": "Mutation"
},
"types": [
@dhruvdcoder
dhruvdcoder / repo_info.gql
Created September 13, 2018 17:28
Query to fetch information about any repository using github's graphql API
query repo_info($owner: String!, $name: String!){
repository(owner: $owner, name: $name) {
...RepoFragment
}
}
fragment RepoFragment on Repository {
name
stargazers {
totalCount
@dhruvdcoder
dhruvdcoder / tmux-cheatsheet.markdown
Last active March 3, 2021 02:01 — forked from MohamedAlaa/tmux-cheatsheet.markdown
tmux shortcuts & cheatsheet

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname