This file contains hidden or 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
hello |
This file contains hidden or 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
Q - HOW TO GET THE DATETIME PYTHON OBJ FROM A DATE STRING WITHOUT KNOWING THE STRING DATETIME FORMAT. | |
A- we use "delorean" (pip install delorean) package to make that string in to python datetime | |
object. How to use it -- | |
pip install delorean | |
Go to python shell and try this | |
>>> datetime_str = "2017-07-17" | |
>>> from delorean import parse | |
>>> parse(datetime_str.strip()).datetime.month | |
7 | |
>>> parse(datetime_str.strip()).datetime.day |
This file contains hidden or 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 {Pipe, PipeTransform} from '@angular/core'; | |
/* | |
* Changes the case of the first letter of a world by avoiding the prepositions. | |
*/ | |
@Pipe({name: 'titlecase'}) | |
export class TitleCase implements PipeTransform { | |
transform(input:string):string { | |
let words = input.split(" "); |
This file contains hidden or 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 os | |
import zipfile | |
import re | |
def extract_nested_zip(zippedFile, toFolder): | |
""" Extract a zip file including any nested zip files | |
Delete the zip file(s) after extraction | |
""" | |
if not os.path.exists(zippedFile): | |
return |
This file contains hidden or 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 py7zlib | |
import os | |
import re | |
class SevenZFile(object): | |
@classmethod | |
def is_7zfile(cls, filepath): | |
''' | |
Class method: determine if file path points to a valid 7z archive. |
This file contains hidden or 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
''' | |
Tested with: | |
Mongo 3.0.12 | |
pymongo 3.3.0 | |
Elasticsearch 2.1.2 | |
Kibana 4.3.3 | |
elasticsearch python 2.1.0 | |
''' |
This file contains hidden or 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 functools import reduce | |
def deep_get(dictionary, keys_list, default=None): | |
keys = ".".join(keys_list) | |
return reduce(lambda d, key: d.get(key, default) if isinstance(d, dict) else default, keys.split("."), | |
dictionary) | |
def setInDict(dataDict, mapList, value): | |
if mapList[:-1]: | |
if deep_get(dataDict, mapList[:-1]): | |
deep_get(dataDict, mapList[:-1])[mapList[-1]] = value |
This file contains hidden or 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
class Caching: | |
def __init__(self, size=5): | |
self.store = {} | |
self.size = 5 | |
def update_recently_used(self, key): | |
value = self.store.pop(key) | |
self.store[key] = value | |
def get(self, key): |
This file contains hidden or 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
""" | |
N level are there in multi story parking | |
X number slots are there on each level | |
to park a vehicle take reg number and color | |
Question which your program need to answer | |
1.Give me all slots for given a color | |
2.Give me slot number for a give red number | |
""" |