Skip to content

Instantly share code, notes, and snippets.

import sys
from tweepy import OAuthHandler
from tweepy import API
from tweepy import Stream
from tweepy.streaming import StreamListener
# Replace the "None"s by your own credentials
ACCESS_TOKEN = None
ACCESS_TOKEN_SECRET = None
@adamoudad
adamoudad / slackbot.py
Created May 21, 2020 17:44
Bot posting a message to a slack channel using a web hook.
#!/bin/python3
#-*- encoding: utf-8 -*-
import slackweb
HOOK_URL='https://hooks.slack.com/services/SOME_GIBBERISH_CODE.'
slack = slackweb.Slack(url=HOOK_URL)
slack.notify(text="Hello world!")
@adamoudad
adamoudad / date_formatting.py
Created August 4, 2020 10:04
Several syntax for formatting dates in python
from datetime import datetime
(datetime.today().strftime("%Y年%m月%d日"))
"{:%Y年%m月%d日}".format(datetime.today())
"{0:%Y}{1}{0:%m}{2}{0:%d}{3}".format(datetime.today(), "年", "月", "日")
f"{datetime.today():%Y年%m月%d日}"
from torchvision import datasets, transforms
from torch.utils.data import DataLoader
from torch.optim import Adam
from torch import nn
transform=transforms.Compose([
transforms.ToTensor(),
transforms.Normalize((0.1307,), (0.3081,))
])
dataset = datasets.MNIST('./mnist_data', train=True, download=True,
import torch
from torch import nn
import torch.nn.functional as F
class Perceptron(nn.Module):
def __init__(self):
super().__init__()
self.dropout2 = nn.Dropout(0.5)
self.fc1 = nn.Linear(28 * 28, 128) # 9216
self.fc2 = nn.Linear(128, 10)
from tqdm import tqdm
lst = [1, 3, 5, 7, 11]
for element in tqdm(lst):
sleep(0.1)
from tqdm import trange
iterations = 20
for i in trange(iterations, desc="Proving P=NP", unit="carrots"):
sleep(0.1)
def get_divisors(n):
divisors = []
for m in range(1, n+1):
if n % m == 0:
divisors.append(m)
return divisors
from tqdm import trange
iterations = 10
pbar = trange(iterations, unit="carrots")
for i in pbar:
sleep(0.5)
if i % 2:
pbar.set_description(f"Testing odd number {i}")
else:
pbar.set_description(f"Testing even number {i}")
from tqdm import trange
iterations = 10
with trange(iterations, unit="carrots") as pbar:
for i in pbar:
sleep(0.5)
if i % 2:
pbar.set_description(f"Testing odd number {i}")
else:
pbar.set_description(f"Testing even number {i}")