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 replaceCode(blg): | |
new_content = content | |
snippets = re.findall(start_pat + "(.*?)" + end_pat, new_content, re.S) | |
counter = 0 | |
for item in snippets: | |
if item[0] != "bash": | |
new_content = new_content.replace( | |
"\n".join([f" |
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 replaceCodeSnippetsWithGists( | |
content, gists, title, hashnode=False, devto=False, medium=False, wp=False | |
): | |
start_pat = "```(.*?)\n" | |
end_pat = "```" | |
def replaceCode(blg): | |
new_content = content | |
snippets = re.findall(start_pat + "(.*?)" + end_pat, new_content, re.S) | |
counter = 0 |
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
embedGist = { | |
"devto": lambda gist: f"{{% embed {gist} %}}", | |
"medium": lambda gist: gist, | |
"hashnode": lambda gist: f"%[{gist}]", | |
"wp": lambda gist: f"[gist {gist}]", | |
} |
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 createGists(token, snippets, public=False): | |
query_url = "https://api.github.com/gists" | |
headers = {"Authorization": f"token {token}"} | |
urls = [] | |
for fileName, code in snippets: | |
data = {"public": public, "files": {fileName: {"content": code}}} | |
# Send the request | |
response = requests.post(query_url, headers=headers, data=json.dumps(data)) | |
if response.status_code == 201: | |
urls.append(response.json()["html_url"]) |
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 getSnippetName(language, snippet): | |
mapLanguagetoFileName = { | |
"python": "__init__.py", | |
"javascript": "index.js", | |
"typescript": "index.ts", | |
} | |
lines = snippet.split("\n") | |
firstLine = lines[0] | |
if "#" in firstLine: | |
return (firstLine.strip("#").strip("\n"), "\n".join(lines[1:])) |
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
snippets = re.findall(start_pat + "(.*?)" + end_pat, content, re.S) | |
result = [] | |
for item in snippets: | |
if item[0] != "bash": | |
result.append(getSnippetName(item[0], item[1])) | |
return result |
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 getCodeSnippetsFromMarkdown(content): | |
start_pat = "```(.*?)\n" | |
end_pat = "```" | |
snippets = re.findall(start_pat + "(.*?)" + end_pat, content, re.S) | |
result = [] | |
for item in snippets: | |
if item[0] != "bash": | |
result.append(getSnippetName(item[0], item[1])) | |
return result |
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
@app.route('/githubIssue',methods=['POST']) | |
def githubIssue(): | |
data = request.json | |
print(f'Issue {data["issue"]["title"]} {data["action"]}') | |
print(f'{data["issue"]["body"]}') | |
print(f'{data["issue"]["url"]}') | |
return data |
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 flask import Flask,request,json | |
app = Flask( __name__ ) | |
@app.route('/') | |
def hello(): | |
return 'Webhooks with Python' | |
if __name__ == ' __main__': | |
app.run(debug=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
let names = ['Rahul','Rohit','Rohan'] | |
function addNewName(name, cb){ | |
setTimeout(function(){ | |
names.push(name) | |
cb() | |
},5000) | |
} | |
function printNames(){ | |
setTimeout(function(){ | |
console.log(names) |