Skip to content

Instantly share code, notes, and snippets.

View himat's full-sized avatar
💭
Making

Hima himat

💭
Making
View GitHub Profile
@himat
himat / conda.md
Created September 30, 2019 01:45
[conda commands sheet] Useful conda commands #packages

Create an env from scratch

conda create --name envname

Create from an env file

conda env create -f environment.yml

List all packages installed in this conda env

conda list

List all conda envs on this system

@himat
himat / cell.js
Last active April 3, 2020 15:16
[ipynb useful first cell lines] Useful commands to put in the top cells of an ipython notebook #python #notebook
%reload_ext autoreload
%autoreload 2
import os, sys
import pathlib
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline
@himat
himat / mock_func.py
Last active July 8, 2019 19:07
[Mock any python object/function] Create a fake object/function to disable an object/function that is called later #python
# Assume our code has some function that is called later (possibly called multiple times).
# In the code below, we have a logging function, and we don't want to always use the logger.
# Instead of adding an `if disable_logging` line every time we log something with the logging function,
# we can instead just replace the logging function with a fake function that does nothing.
def mock_logger(*args, **kwargs):
pass
if disable_logging:
logger = mock_logger
@himat
himat / alfred_tips.md
Last active July 3, 2019 05:00
[Alfred useful tips] Things to use #alfred #mac

Google I'm Feeling Lucky search to select the first link on the search results page automatically

A lot of times for searches that have one main result, it will usually be the first result on the search results page, and you end up just clicking that first link. You can save time and mental capacity by using this more efficient method.
So use this if you pretty much know what you're looking for.

  • You don't even need to have your browser open to do this!
  • And this way, you don't need to remember URLs either, just need to know the description of the site!

With the I'm Feeling Lucky keyword set to l, just type in Alfred something like:

  • l wiki ontology
  • l github
  • l pytorch docs
@himat
himat / filter_pd_series.py
Created July 2, 2019 18:03
[Filter a Pandas series] Use .where(.) chaining #pandas
test = {
383: 3.000000,
663: 1.000000,
726: 1.000000,
737: 9.000000,
833: 8.166667
}
pd.Series(test).where(lambda x : x!=1).dropna()
@himat
himat / val_in_df_col.py
Last active July 2, 2019 00:40
[Check if value in df col] You have to check if `val in col.values`, not just `val in col` #pandas #dangerous
# Doing `x in df["col"]` will always look for x in the *index* of the df, not the actual column values
# Thus, you have to use `x in df["col"].values` instead
# This can be especially insidious when you're checking if a number is in a col, but that number is also in the index.
# If you don't use `.values` in this case, you will think the value is in the col when it actually isn't!
>>> df = pd.DataFrame({"a": [20, 40, 1], "b": [32, 42, 52]})
>>> df
a b
0 20 32
1 40 42