Skip to content

Instantly share code, notes, and snippets.

@maininformer
Last active August 9, 2019 23:00
Show Gist options
  • Save maininformer/b73491be20327f7a1beea60ba8324030 to your computer and use it in GitHub Desktop.
Save maininformer/b73491be20327f7a1beea60ba8324030 to your computer and use it in GitHub Desktop.

Python Mock

Mock the method what not, where it is imported and not where it exists. If the test runs a method in a file called foo. and inside foo, you want to patch bar, then the patch should be foo.bar, even if bar is imported from baz originally.

Also gotchas: http://alexmarandon.com/articles/python_mock_gotchas/

If you are stacking up decorator patches, the order is down to up, the lowest one goes to the first agument.

GPG

Search someone by email: gpg --keyserver hkp://keyserver.ubuntu.com --search-key 'email@email.com'

Redash

For the AIM AWS:

  • Make sure it is at least t2.small, nano will starve
  • If you ssh, you need to run docker-compose run --rm server bin/run ./manage.py database create_tables docker-compose run --rm server create_db for the postgres errors. IT WILL ADD EXTRA TABLES TO YOUR PROD DATABASE
  • If you already added a datasource and then restarted the docker-compose and now you cannot get in because of Postgres password error, simply add the third party postgres URI to the end of the env file, so it overwrites the test one. ( I think this happens, because redash will try to auth with the existing postgres first)

Sublime

VIM biding key repeats on Mac: https://gist.github.com/kconragan/2510186 Python: IndentationError: unexpected indent: probably mixed spaces and tabs

VIM

block commenting:

Put your cursor on the first # character, press CtrlV (or CtrlQ for gVim), and go down until the last commented line and press x, that will delete all the # characters vertically.

For commenting a block of text is almost the same:

  1. First, go to the first line you want to comment, press CtrlV. This will put the editor in the VISUAL BLOCK mode.
  2. Then using the arrow key and select until the last line
  3. Now press ShiftI, which will put the editor in INSERT mode and then press #. This will add a hash to the first line.
  4. Then press Esc (give it a second), and it will insert a # character on all other selected lines.

Shell/BaSH

here_document is good, it can deliver you from the pain of echo swallowing quotes and many more. use it, and also for piping do like:

cat <<EOF | base64
"this will be base64"
EOF

if pressing the Enter key does not new line:

try stty sane

The Ulitmate Guide to node google directory api sdk with a service account (as of June 22 2018)

  • Basically follow this but with the following caveats.
  • For a service account change the authenticator to a JWT like this
  • You cant NOT update a service account to have domain wide delegation AFTER it is created. The button is there, but it will tell you you don't have permissions, and then it will appear and disappear. So you need to enable it upon creation.
  • You need to include the subject field in the JWT authenticator, not shown in the link above. Like this; Code is here
  • The original GCP link says users = response.users that is incorrect, it should be users = response.data.users

GCP and Google Apis

To authenticate without checking in the client_secret.json you can stringify and parse the JSON.

Angular 1

Inspecting the scope: choose an element and

angular.element($0).scope()

Modals

you can only call close() on a $modalInstance, when you pass it to a controller.

Kubernetes

see the specs

kubectl get <Resource> <ResourceName> -o yaml

Google Apps Script

triggers

simple triggers don't need installing. If a trigger needs permission it will get wiped and needs installing. The scope of the triggers is limited to the trigger code and will not look at all the script to see if permission is required. Unlike normal scripts, where if a function has a permission requiring method but is not even called and another non-permission requiring method is called, then the non-permission requiring will ask for authorization.

Postgres

WARNING: terminal is not fully functional

Most probably due to the pager, add -P pager=off to the psql commands, or use \pset

Restart in unix: sudo /etc/init.d/postgresql restart

psql: FATAL: no pg_hba.conf entry for host "xxx.xx.xx.xx", user "xxxx", database "xxxx", SSL on

FATAL: no pg_hba.conf entry for host "xxx.xx.xx.xx", user "xxxx", database "xxxx", SSL off

As a super user ask postgres to show where the hba file is:

sudo su postgres -c psql
postgres=> SHOW hba_file;

Go there and edit and add your host:

host all(this is user) all(this is database) xxx.xx.xx.xx/32 trust

The restart postgres:

sudo /etc/init.d/postgresql restart

Easy peasy dump and restore postgres:

pg_dump -Fc postgres://user:pass@host:port/database > pg.dump
pg_restore -C -d postgres://user:pass@host:port/database pg.dump

with a file.sql.gzip

gunzip file.sql.gzip
cat file.sql | psql postgres://user:password@host:port/database

List enums

select unnest(enum_range(null, null::name_of_enum_type));

Multiple update rows each with a different condition

if

SELECT email FROM users WHERE _id IN (1,2)

will return nothing. Then run:

WITH updated AS
  (SELECT u._id as _id, c.email as email
   FROM users AS u
   JOIN (
         VALUES ('1', 'something@email.com'),
                ('2','somethingElse@email.com')) AS c (_id, email) ON c._id = u._id
   )
UPDATE users AS u
SET email = updated.email
FROM updated
WHERE updated._id = u._id ;

List materialized views

SELECT oid::regclass::text
FROM   pg_class
WHERE  relkind = 'm';

Get matrialized views script

SELECT pg_get_viewdef('viewName');

ES8 highlighting in vim

Add these to sources_non_forked of vimrc

Don't use https://github.com/isRuslan/vim-es6 it breaks on backticks and sucks, use this instead: https://github.com/pangloss/vim-javascript.git

https://github.com/othree/yajs.vim.git

https://github.com/othree/es.next.syntax.vim.git

you also NEED https://github.com/mxw/vim-jsx.git

and use it with peaksea; mango doesn't work

Word jumps for Zsh

run cat. Press alt forward and back. you will get patterns X and Y. add to zshrc: bindkey "X" forward-word

source

links

The ecr link that is hard to find for some reason https://docs.aws.amazon.com/AmazonECR/latest/userguide/Registries.html#registry_auth

Declarative vs Imperative

Ultimately I think, if the instruction does not directly relate to the desired output, as something being done on the input, it is going to be more of an imperative, e.g. using a list, a variable to mutate during a loop etc.

gcloud

to get the GOOGLE_APPLICATION_CREDENTIALS: gcloud auth application-default login

mysqlclient python

To install: brew install mysql-connector-c then: vi $(which mysql_config) and then make the changes mentioned here Finally: export LDFLAGS="-L/usr/local/opt/openssl/lib" and then pip install mysqlclient

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment