Try-Catch-Custom-Error
title: "Try Catch with Custom Error"
author: "Rj"
date: 2019-04-20
description: "List Test"
type: technical_note
draft: false
class NegativeMarksError(Exception):
pass
def check_marks(mark):
try:
if(mark < 0):
raise NegativeMarksError
if(mark > 50):
print('pass')
else:
print('fail')
except ValueError:
print('ValueError: Some value error')
except TypeError:
print('TypeError: Cannot …
Read More
Try-Catch-Raise-Error
title: "Try Catch with Raise Error"
author: "Rj"
date: 2019-04-20
description: "List Test"
type: technical_note
draft: false
def check_marks(mark):
try:
if(mark < 0):
raise ValueError
if(mark > 50):
print('pass')
else:
print('fail')
except ValueError:
print('ValueError: Some value error')
except TypeError:
print('TypeError: Cannot convert into int')
Read More
Ttl-Cache
title: "TTL Cache"
author: "Rj"
date: 2019-04-20
description: "-"
type: technical_note
draft: false
from cachetools import TTLCache
cache = TTLCache(maxsize=10, ttl=10)
cache['city'] = 'Toronto'
# Run the cell below after 10 seconds
# more
# https://stackoverflow.com/questions/31771286/python-in-memory-cache-with-time-to-live
Score: 5
Read More
Ttl-Cache-1
title: "TTL Cache Check"
author: "Rj"
date: 2019-04-20
description: "-"
type: technical_note
draft: false
from cachetools import TTLCache
import time
cache = TTLCache(maxsize=10, ttl=10)
cache['city'] = 'Toronto'
if('city' in cache):
print(cache['city'])
else:
print('Cache not found')
Read More
Unicode-Dammit
title: "Unicode Dammit"
author: "Rj"
date: 2019-04-20
description: "-"
type: technical_note
draft: false
from bs4 import UnicodeDammit
print("inside main method")
dammit = UnicodeDammit(b"Sacr\xc3\xa9 bleu!")
<class 'bs4.dammit.UnicodeDammit'>
print(dammit.unicode_markup)
print(type(dammit.unicode_markup))
Read More
User-Input
title: "User input"
author: "Rj"
date: 2019-04-20
description: "-"
type: technical_note
draft: false
city = input("Enter your city : ")
Enter your city : Toronto
Score: 0
Read More
Various-Algorithms
title: "Various Algorithms"
author: "Rj"
date: 2019-04-20
description: "-"
type: technical_note
draft: false
Source:
https://www.kaggle.com/drfrank/estonia-disaster-visualization-machine-learning
import numpy as np
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import train_test_split, GridSearchCV, cross_val_score
from sklearn.metrics import confusion_matrix, accuracy_score, classification_report
X = np.array(
[
[1, 1], [1, 2], [2 …
Read More
Various-Algorithms-Titanic
title: "Various Algorithms Titanic"
author: "Rj"
date: 2019-04-20
description: "-"
type: technical_note
draft: false
Source:
https://www.kaggle.com/drfrank/estonia-disaster-visualization-machine-learning
https://stackoverflow.com/questions/55240330/how-to-read-csv-file-from-github-using-pandas
https://gist.github.com/michhar/2dfd2de0d4f8727f873422c5d959fff5
https://www.kaggle.com/rajacsp/titanic-basic-analysis
import pandas as pd
url = 'https://gist.githubusercontent.com/michhar/2dfd2de0d4f8727f873422c5d959fff5/raw …
Read More
Versions
title: "Versions"
author: "Rj"
date: 2019-04-20
description: "List Test"
type: technical_note
draft: false
# scipy
import scipy
print('scipy: %s' % scipy.__version__)
# numpy
import numpy
print('numpy: %s' % numpy.__version__)
# matplotlib
import matplotlib
print('matplotlib: %s' % matplotlib.__version__)
Read More
Webanalyzer Simple
title: "Web Analyzer Simple"
author: "Rj"
date: 2019-04-20
description: "-"
type: technical_note
draft: false
w = webanalyzer.WebAnalyzer()
w.headers = {
"User-Agent": "custom ua",
"header-key": "header-value"
}
w.allow_redirect = True
w.aggression = 0
r = w.start("http://www.fatezero.org")
print(r)
[{'name': 'Script', 'origin': 'whatweb'}, {'name': 'HTML5', 'origin': 'whatweb'}, {'name': 'Fastly …
Read More