Skip to content

Instantly share code, notes, and snippets.

View bssth's full-sized avatar
:accessibility:
Exist

Borys S. bssth

:accessibility:
Exist
  • VortalCoil
  • Ukraine
View GitHub Profile
@bssth
bssth / paginate.go
Created September 5, 2025 12:44
Golang slice pagination
func Paginate[T any](list []T, limit, page uint) []T {
if page == 0 {
page = 1
}
if limit == 0 {
limit = 10
}
var arrayTo = int(limit * page)
if arrayTo > len(list) {
@bssth
bssth / json_values.go
Created February 25, 2025 16:17
Golang Json []byte To Values
package utils
import (
"github.com/goccy/go-json"
"net/url"
)
func JsonToValues(jsonData []byte) (url.Values, error) {
var data map[string]string
err := json.Unmarshal(jsonData, &data)
@bssth
bssth / delete-friends.mjs
Created February 17, 2025 14:20
Delete all friends, leave as subscribers
const delay = ms => new Promise(resolve => setTimeout(resolve, ms));
(async () => {
let list = (await vk.api.friends.get({'count': 1000}))?.items;
if (!list?.length) {
console.log('Error: List is empty');
return;
}
for (let k in list) {
@bssth
bssth / docker.go
Created February 8, 2025 17:54
IsDocker check (Golang)
package main
const DockerEnv = ".dockerenv"
func IsDocker() bool {
if _, err := os.Stat("/" + DockerEnv); err == nil {
return true
}
return false
@bssth
bssth / meta.go
Created February 8, 2025 17:52
File extensions metadata
package main
import "strings"
type FileType struct {
Extension string `json:"extension"`
Type string `json:"type"`
Desc string `json:"desc"`
}
@bssth
bssth / json-rpc.go
Created February 8, 2025 17:47
JSON RPC utils for golang
package main
import (
"encoding/json"
)
type JsonRpcRequest struct {
JsonRpcVersion string `json:"jsonrpc"`
ID uint `json:"id"`
Method string `json:"method"`
@bssth
bssth / app.js
Created August 26, 2024 17:59
Old (2019) socket.io comet server example
var express = require('express');
var app = express();
var server = require('http').createServer(app);
var io = require('socket.io')(server, {cookie: false, path: '/comet'});
var port = process.env.PORT || 1337;
//var decode = require('urldecode');
var bodyParser = require('body-parser')
var requestIp = require('request-ip');
app.use(requestIp.mw());
@bssth
bssth / set-field.go
Last active June 29, 2024 15:53
Universal Go struct setField function
// setField sets field value in struct by string key
// Supports bool, string, uint, int and slices of these types
// Dirty and not idiomatic way to solve problem, but works and sometimes is very comfortable
// Not recommended to use in production
func setField(item interface{}, fieldName string, value string) (err error) {
v := reflect.ValueOf(item).Elem()
if !v.CanAddr() {
return fmt.Errorf("internal error, bad destination struct")
}
import { VK } from 'vk-io';
import fs from 'fs';
const vk = new VK({
token: 'PLACE TOKEN HERE'
});
(async () => {
// Read all ids from file. Change filename if you want
// Stdin is not supported because I was too lazy to implement it
@bssth
bssth / get-chats.mjs
Created May 14, 2024 03:53
VK.com: get all chats list
import { VK } from 'vk-io';
const vk = new VK({
token: process.env.TOKEN
});
const excludePm = []; // list of user IDs to exclude
const excludeChats = []; // list of chat IDs to exclude
const chatsOffset = 2000000000;