Skip to content

Instantly share code, notes, and snippets.

@maca134
maca134 / redis-stream.ts
Created March 17, 2024 02:14
Redis Streams for Nodejs
import { Readable, Writable } from "stream";
import { commandOptions, createClient } from "redis";
export const createWriteStream = (client: ReturnType<typeof createClient>, key: string, opts?: { ttlMs?: number }) =>
new Writable({
objectMode: false,
construct: (callback) =>
client
.del(key)
.then(() => callback())
@maca134
maca134 / NinjectBootstrapper.cs
Last active May 20, 2022 16:27
Caliburn.Micro/Ninject Bootstrapper
using System;
using System.Collections.Generic;
using System.Windows;
using Caliburn.Micro;
using Ninject;
namespace Maca134.Stuff
{
internal abstract class NinjectBootstrapper<TViewModel> : BootstrapperBase
{
@maca134
maca134 / index.ts
Last active November 16, 2021 00:24
Get Chrome Extension ID in NodeJS
import { readFileSync } from 'fs';
import { parse } from 'protobufjs';
if (!process.argv[2]) throw new Error('no arg');
const file = readFileSync(process.argv[2]);
if (!file) throw new Error('no file');
const root = parse(`
package chromeextensionid;
@maca134
maca134 / WorkshopUploader.bat
Created April 20, 2021 15:46
Workshop Uploader
@ECHO off
SETLOCAL enableextensions enabledelayedexpansion
CD /D "%~dp0"
SET BASEPATH=%~dp0
REM =============================[CONFIG START]=============================
SET STEAMCMDPATH=.steamcmd
REM Steam login details, you may need to run this twice if you have Auth Guard enabled (which you should)
@maca134
maca134 / bigint.ts
Last active November 30, 2019 03:13
BigInt to Buffer and Buffer to BigInt Nodejs
function bigIntToBuffer(num: bigint, endian: 'be' | 'le') {
const bytes: number[] = [];
while (num > 0) {
bytes.push(Number(num & 0xffn));
num = num >> 8n;
}
return Buffer.from(endian === 'be' ? bytes.reverse() : bytes);
}
function bufferToBigInt(bytes: Buffer, endian: 'be' | 'le') {
@maca134
maca134 / Group.cs
Created August 29, 2018 01:46
SQLite table sql from POCO
namespace SQLiteTableBuilder
{
[Table]
public class Group
{
[Column(PrimaryKey = true, AutoIncrement = true)]
public int Id { get; set; }
[Column(Unique = true)]
public string Name { get; set; }
private _traders = [];
{
_traders pushBack [
typeOf _x,
(_x get3DENAttribute 'face') select 0,
["HubStanding_idle1"],
getPosATL _x,
getDir _x
];
} forEach ((get3DENSelected "group") apply {units _x select 0});
MMC_fnc_getConfig = {
params [
['_base', configfile, [configfile]]
];
private _inherts = inheritsFrom _base;
private _output = [
if (configName _inherts != '') then {
format ['class %1 : %2 {', configName _base, configName _inherts]
} else {
format ['class %1 {', configName _base]
var async = require('async');
findMatches.prototype.find = function(checkhash, complete) {
var self = this;
var matches = [];
async.eachLimit(hashes, 5, function (hash, next) {
if (hamming(checkhash, hash.hash) < 10) {
console.log('emiiting match');
self.emit('found-match', hash);
matches.push(hash);
}
@maca134
maca134 / gist:94b78268f6727f5967f8
Created May 29, 2015 23:24
Parse ARMA String Array in C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace mgroups.Core
{
public class ArmaArray : List<object>
{
public static ArmaArray Unserialize(string strarray)