Skip to content

Instantly share code, notes, and snippets.

View supernovaplus's full-sized avatar

SuperNova+ supernovaplus

View GitHub Profile
@supernovaplus
supernovaplus / discord_webhook_image_compress_upload.php
Last active June 25, 2021 05:16
PHP - Compress and upload image to Discord via Webhook
<?php
// ini_set('display_errors', 1);
// ini_set('display_startup_errors', 1);
// error_reporting(E_ALL);
//from https://stackoverflow.com/questions/65133851/uploading-file-to-discord-with-webhook-in-php
//file is being called by a POST request in my case
//print_r for debugging
//default max size discord accepts is 8MB
@supernovaplus
supernovaplus / discord_webhook_upload_file.php
Last active November 21, 2024 09:52
PHP - Send file to Discord via Webhook
<?php
//from https://stackoverflow.com/questions/65133851/uploading-file-to-discord-with-webhook-in-php
//file is being called by a POST request in my case
//print_r for debugging
//default max size discord accepts is 8MB
echo "<pre>";
$webhookurl = "https://discord.com/api/webhooks/xxxx/xxxxxxx";
const discord_permissions = [["CREATE_INSTANT_INVITE",1],["KICK_MEMBERS *",2],["BAN_MEMBERS *",4],["ADMINISTRATOR *",8],["MANAGE_CHANNELS *",16],["MANAGE_GUILD *",32],["ADD_REACTIONS",64],["VIEW_AUDIT_LOG",128],["PRIORITY_SPEAKER",256],["STREAM",512],["VIEW_CHANNEL",1024],["SEND_MESSAGES",2048],["SEND_TTS_MESSAGES",4096],["MANAGE_MESSAGES *",8192],["EMBED_LINKS",16384],["ATTACH_FILES",32768],["READ_MESSAGE_HISTORY",65536],["MENTION_EVERYONE",131072],["USE_EXTERNAL_EMOJIS",262144],["VIEW_GUILD_INSIGHTS",524288],["CONNECT",1048576],["SPEAK",2097152],["MUTE_MEMBERS",4194304],["DEAFEN_MEMBERS",8388608],["MOVE_MEMBERS",16777216],["USE_VAD",33554432],["CHANGE_NICKNAME",67108864],["MANAGE_NICKNAMES",134217728],["MANAGE_ROLES *",268435456],["MANAGE_WEBHOOKS *",536870912],["MANAGE_EMOJIS *",1073741824]];
discord_permissions.forEach(perm=>{
console.log(perm[0], (discord_user_guild_permissions & perm[1]) === perm[1])
})
function hexToDouble1(num){//expensive
const splittedNum = num.match(/../g);
const buf = new ArrayBuffer(8);
const view = new DataView(buf);
splittedNum.forEach(function (val, index) {
view.setInt8(index, parseInt(val, 16));
});
return view.getFloat64(0, 0);
}
@supernovaplus
supernovaplus / main.java
Last active September 29, 2020 12:29
printBonusDatesBetween
import java.text.SimpleDateFormat;
import java.util.*;
public class Main {
static void printBonusDatesBetween(int fromYear, int toYear) {
SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd");
Calendar cal = Calendar.getInstance();
cal.set(fromYear, 0, 1);
@supernovaplus
supernovaplus / timestamp.js
Created July 16, 2020 16:09
convert timestamp to seconds
data.duration.split(".")[0].split(":").reduce((acc,val,i)=>i===0 ? acc += +val * 60 * 60 : i===1 ? acc += +val * 60 : acc += +val,0)
<?php
//case(3): array_push($fetch_array, [&$response->vouchers,"select * from vouchers_config;"]); break;
function fetchdb($data){
global $response, $conn;
$query = "";
for ($i=0; $i < count($data); $i++) {
$query .= $data[$i][1];
}
if (mysqli_multi_query($conn, $query)) {
@supernovaplus
supernovaplus / dl.js
Last active April 17, 2020 15:26
downloading file with node js
const fs = require('fs')
const fetch = require("node-fetch")
const path = "C:\\DOWNLOADS\\";
const urlArray = [
//["url","fileName"]
//"url"
//["url","filename"],"url",["url","filename"]
"http://somesite.com/somevideo.mp4",
["http://somesite.com/somevideo2.mp4","renamedvideo.mp4"],
@supernovaplus
supernovaplus / Day 1 - Advent of Code 2019.js
Last active December 2, 2019 22:23
Day 1 - Advent of Code 2019
var input = `149579
95962
97899
etc...`;
input = input.split("\n").map(n=>Number(n));
const part1 = (number) => {
let val = (Math.floor(number/3)-2)
return val > 0 ? val : 0
function COPYVOUCHERSONDATE() {
//if(new Date().getDay()!=6)return Logger.log("not today ;)");
var DATETIMESTRING = Utilities.formatDate(new Date(),"GMT+1","M/d");
var spreadsheet = SpreadsheetApp.openById("-");
spreadsheet.setActiveSheet(spreadsheet.getSheetByName('Vouchers'), true);
spreadsheet.duplicateActiveSheet();
spreadsheet.moveActiveSheet(17);