Skip to content

Instantly share code, notes, and snippets.

View mikkipastel's full-sized avatar

Monthira Chayabanjonglerd mikkipastel

View GitHub Profile
@mikkipastel
mikkipastel / app.js
Created April 19, 2022 14:51
connect with
const rest = new REST({ version: '9' }).setToken(process.env.DISCORD_BOT_TOKEN);
rest.put(Routes.applicationGuildCommands(process.env.BOT_CLIENT_ID, process.env.SERVER_ID), { body: commands })
.then(() => console.log('Successfully registered application commands.'))
.catch(console.error);
@mikkipastel
mikkipastel / app.js
Created April 19, 2022 14:28
init discord bot command
const commands = [
new SlashCommandBuilder().setName('ping').setDescription('Replies with pong!'),
new SlashCommandBuilder().setName('holiday').setDescription('Replies with 10 holiday date!')
].map(command => command.toJSON());
@mikkipastel
mikkipastel / server.js
Created April 17, 2022 07:44
ping standup meeting to discord text channel by webhook
client.once('ready', async () => {
console.log('Ready!');
try {
const webhook = new WebhookClient({ id: process.env.WEBHOOK_ID, token: process.env.WEBHOOK_TOKEN });
await cron.schedule('00 10 * * Mon-Fri', async () => {
webhook.send('@everyone, standup meeting', {});
});
@mikkipastel
mikkipastel / server.js
Created April 17, 2022 07:44
ping standup meeting to discord text channel by channel id
client.once('ready', async () => {
console.log('Ready!');
try {
const channel = client.channels.cache.get(process.env.GENERAL_CHANNEL_ID);
await cron.schedule('00 10 * * Mon-Fri', async () => {
channel.send('@everyone, standup meeting', {});
});
@mikkipastel
mikkipastel / calendar.js
Created April 17, 2022 07:06
create function for get today is holiday event
function checkTodayIsHoliday(webhook) {
let minNow = new Date();
minNow.setHours(7, 0, 0, 0);
const timeMin = minNow.toISOString();
let maxNow = new Date();
maxNow.setDate(maxNow.getDate() + 1);
maxNow.setHours(7, 0, -1, 0);
const timeMax = (new Date(maxNow)).toISOString();
function setRoleIdString() {
const roleId = process.env.ROLE_ID;
return '<@&' + roleId + '>';
}
module.exports = {
setRoleIdString
}
@mikkipastel
mikkipastel / reentrancy.sol
Last active March 31, 2022 04:57
SWC-107 : Reentrancy / CWE-841: Improper Enforcement of Behavioral Workflow from KBTG Inspire2
pragma solidity ^0.8.0;
contract EtherStore {
mapping(address => uint256) public balances;
function deposit() public payable {
balances[msg.sender] += msg.value;
}
function withdraw() public {
@mikkipastel
mikkipastel / overflow.sol
Created March 30, 2022 13:54
SWC-101 : Integer Overflow and Underflow / CWE-682 : Incorrect Calculation from KBTG Inspire2
pragma solidity ^0.6.0;
/*
* Step
* 1. Deploy TimeLock Contract
* 2. Deploy Attack(TimeLock) contract
* 3.1 Try attack() -> automated process
* 3.2 Manual
* 1) Deposit x ether
* 2) Get locktime (for checking)
// [1] ประกาศ solidity ว่าใช้ version อะไร
pragma solidity ^0.8.7;
// [2] import smart contract อื่นเข้ามา ซึ่งอันนี้ไม่ต้องก็ได้ เผื่อใช้ 3rd-party
////import "openzeppelin-contracts/token/ERC20/ERC20.sol";
////import "openzeppelin-contracts/access/Ownable.sol";
// [3] ชื่อของ smart contract ในที่นี้ชื่อ Token
// และ inherit สืบทอดคุณสมบัติต่างๆของ smart contract อะไร ในที่นี้คือ ERC20 และ Ownable ใส่หลัง is
contract Token is ERC20, Ownable {
@mikkipastel
mikkipastel / SegmentCircleView.kt
Created February 14, 2022 14:24
try to draw segment
import android.content.Context
import android.graphics.*
import android.util.AttributeSet
import android.view.View
class SegmentCircleView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : View(context, attrs, defStyleAttr) {