Skip to content

Instantly share code, notes, and snippets.

View yhay81's full-sized avatar

Yusuke Hayashi yhay81

View GitHub Profile
@yhay81
yhay81 / memo-bot.py
Last active February 17, 2018 08:45
Discord bot which remember and call your memo anywhere.
import sqlite3
import discord
client = discord.Client()
@client.event
async def on_ready():
print('Logged in as')
print(client.user.name)
@yhay81
yhay81 / pin-bot.py
Last active April 12, 2022 11:32
Discord bot who can pin messages with just adding reaction 📌
import discord
client = discord.Client()
@client.event
async def on_ready():
print('Logged in as')
print(client.user.name)
@yhay81
yhay81 / goldbach-comet.py
Last active May 4, 2019 00:50
Goldbach's comet follows x^(0.8) ?
from matplotlib import pyplot as plt
import numpy as np
import pandas as pd
from sympy import sieve
def prime_doubles(upper):
result = [0] * (2 * upper + 1)
sieve.extend(upper)
max_prime_index, _ = sieve.search(upper)
for i in range(1, max_prime_index+1):

5 Steps to know about JavaScript Closure

This is what I think is easy way to understand what closure of JavaScript is.

Step 1. Declaration variables

When we use variables in programming, at first we declare it and then use it. So, what happens when I declare the variable which name is already declared?

let count = 0;
const doOnlyOnce = function (){
if(count==0){
console.log("You do this for first time.");
}else{
console.log("You already have done this.");
}
count++;
};
@yhay81
yhay81 / utils.py
Created March 20, 2018 21:22
Python speed test
from functools import wraps
from time import time
def timing(f):
@wraps(f)
def wrapper(*args, **kwds):
s = time()
f(*args, **kwds)
return time() - s
@yhay81
yhay81 / CorgiBot.js
Last active March 24, 2018 11:22
Slack bot who react some words and return a giphy.
var SLACK_ACCESS_TOKEN = PropertiesService.getScriptProperties().getProperty('SLACK_ACCESS_TOKEN');
var GIPHY_API_KEY = PropertiesService.getScriptProperties().getProperty('GIPHY_API_KEY');
// var SPREAD_SHEET_ID = PropertiesService.getScriptProperties().getProperty('SPREAD_SHEAT_ID');
var POST_MESSAGE_ENDPOINT = 'https://slack.com/api/chat.postMessage';
var TEXTS = [
'Do you like dogs?:dog:',
'You said the word!:grinning:',
'I hope you like this...:poodle:',
'Dogs are cute!:dog2: Dogs are cute!:dog2:',
class NaturalNumber:
def __init__(self, p=None):
self.predecessor = p
def __eq__(self, x):
if self.predecessor is None and x.predecessor is None:
return True
elif (self.predecessor is None and x.predecessor is not None) \
or (self.predecessor is not None and x.predecessor is None):
return False
@yhay81
yhay81 / file0.txt
Last active December 6, 2018 14:19
Google Apps Script 用 Slack API ライブラリ作った ref: https://qiita.com/yhay81/items/edf74af8efe3d3d1a1b5
var token = 'xoxb-34...みたいなトークン';
var slack = GASlacker.methods(token);
function doPost(e){
var event = JSON.parse(e.postData.contents).event;
if(event.text.match(/hello/)){
var text = "Hello," + event.message.username;
slack.chat.postMessage(event.channel, text);
}
}
@yhay81
yhay81 / memo.py
Last active January 3, 2023 08:49
メモを記憶させたり、出したりできるdiscordのbotです
import sqlite3
import discord
client = discord.Client()
@client.event
async def on_ready():
print('Logged in as')
print(client.user.name)