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
/** | |
* Union two objects and exclude false values when merging same keys | |
* @param left | |
* @param right | |
* @returns New combined object | |
*/ | |
export function unionWithExclusion(left: object, right: object): object { | |
return [left, right].reduce((prev: any, current) => { | |
if(current) { | |
Object.entries(current).map(([key, 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
dataToFile(content, fileName, contentType) { | |
const a = document.createElement("a"); | |
const file = new Blob([content], {type: contentType}); | |
a.href = URL.createObjectURL(file); | |
a.download = fileName; | |
a.click(); | |
} | |
dataToFile(JSON.stringify(data), 'results.json', 'application/json'); |
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, user-scalable=yes, initial-scale=1, maximum-scale=1"> | |
<title>Document</title> | |
</head> | |
<body> | |
<div class="display-cover"> |
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 React from 'react'; | |
import { | |
StyleSheet, | |
StatusBar, | |
PermissionsAndroid, | |
} from 'react-native'; | |
import { | |
Header, | |
Colors, |
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
users = User.query.filter_by(id=id).first() | |
users = [] | |
for user in users: | |
dictret = dict(receipt.__dict__) | |
dictret.pop('_sa_instance_state', None) | |
users.append(dictret) |
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
# Returns list of methods of class: PersonClass | |
method_list = [func for func in dir(PersonClass) if callable(getattr(PersonClass, func)) and not func.startswith("__")] | |
# Execute methods | |
for method in method_list: | |
execute = getattr(class_name, method) | |
execute() |
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
def chunks(lst, n): | |
for i in range(0, len(lst), n): | |
yield lst[i:i + n] | |
lst = [1,3,5,6,7,9,5,4,2,3,5,6,7,4,3] | |
res = list(chunks(lst, 3)) | |
print(res) # [[1, 3, 5], [6, 7, 9], [5, 4, 2], [3, 5, 6], [7, 4, 3]] |
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 org.json.simple.JSONObject; | |
import org.json.simple.parser.JSONParser; | |
import org.json.simple.parser.ParseException; | |
public static JSONObject readJSON(String file) throws IOException, ParseException { | |
JSONParser parser = new JSONParser(); | |
FileReader config = new FileReader(file); | |
Object obj = parser.parse(config); | |
return (JSONObject) obj; |
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
# Note Microsoft Excel must be installed | |
from openpyxl import Workbook, load_workbook | |
from win32com.client import Dispatch | |
path = os.path.dirname(os.path.abspath(__file__)) | |
o = Dispatch("Excel.Application") | |
o.Visible = False | |
o.DisplayAlerts = False |
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
/* Common Regular Expressions */ | |
// Match domain (com,net,ru) | |
let url = "https://www.youtube.com/watch?v=vEPOU_fKmR8"; | |
url.match(/^https?\:\/\/([^\/?#]+)(?:[\/?#]|$)/i); | |
let site = matches && matches[1]; |