Skip to content

Instantly share code, notes, and snippets.

View rahulbanerjee26's full-sized avatar

Rahul Banerjee rahulbanerjee26

View GitHub Profile
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"
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
embedGist = {
"devto": lambda gist: f"{{% embed {gist} %}}",
"medium": lambda gist: gist,
"hashnode": lambda gist: f"%[{gist}]",
"wp": lambda gist: f"[gist {gist}]",
}
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"])
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:]))
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
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
@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
from flask import Flask,request,json
app = Flask( __name__ )
@app.route('/')
def hello():
return 'Webhooks with Python'
if __name__ == ' __main__':
app.run(debug=True)
let names = ['Rahul','Rohit','Rohan']
function addNewName(name, cb){
setTimeout(function(){
names.push(name)
cb()
},5000)
}
function printNames(){
setTimeout(function(){
console.log(names)