Skip to content

Instantly share code, notes, and snippets.

View Rulexec's full-sized avatar
💭
It's complicated

Alexander Ruliov Rulexec

💭
It's complicated
View GitHub Profile
import java.util.concurrent.atomic.AtomicInteger
interface IController {
fun handle(request: AtomicInteger)
}
fun createController(handler: (request: AtomicInteger) -> Unit): IController {
return object : IController {
override fun handle(request: AtomicInteger) = handler(request)
}
@Rulexec
Rulexec / crypto.js
Created January 27, 2018 21:39
Telegram crypto AES 256 IGE node.js implementation
var crypto = require('crypto');
/*
msg_key_large = SHA256 (substr (auth_key, 88+x, 32) + plaintext + random_padding);
msg_key = substr (msg_key_large, 8, 16);
sha256_a = SHA256 (msg_key + substr (auth_key, x, 36));
sha256_b = SHA256 (substr (auth_key, 40+x, 36) + msg_key);
aes_key = substr (sha256_a, 0, 8) + substr (sha256_b, 8, 16) + substr (sha256_a, 24, 8);
aes_iv = substr (sha256_b, 0, 8) + substr (sha256_a, 8, 16) + substr (sha256_b, 24, 8);
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main(int argc, char *argv[]) {
long size = 36L * 1024 * 1024 * 1024 - 1;
void *x = malloc(size);
printf("Malloc: %lld\n", (long long) x);
export { getResult };
function getResult() {
return 42;
}
// If you uncomment this, HRM in `main.js` will stop work and `getResult()` will return 42 everytime
//if (module.hot) module.hot.accept();
@Rulexec
Rulexec / example.js
Last active November 5, 2024 09:34
const wialon = require('./wialon.node.js').wialon;
// Print message to log
function msg(text) { console.log(text); }
function init() { // Execute after login succeed
var sess = wialon.core.Session.getInstance(); // get instance of current Session
// flags to specify what kind of data should be returned
var flags = wialon.item.Item.dataFlag.base | wialon.item.Unit.dataFlag.lastMessage;
let playButton = document.createElement('button');
playButton.textContent = 'Play';
document.body.appendChild(playButton);
playButton.addEventListener('click', () => {
let audioCtx = new AudioContext();
let sampleRate = audioCtx.sampleRate;
let totalSeconds = 2;
@Rulexec
Rulexec / xoroshiro128plus.js
Created May 1, 2020 08:43
JavaScript xoroshiro128+ implementation, can be optimized
export { Xoroshiro128Plus };
function Xoroshiro128Plus(options) {
let { state } = options || {};
if (!state) {
let time = (Date.now() | 0) >>> 0;
state = [
(time & ((Math.random() * 0xffffffff) | 0)) >>> 0,
(time & ((Math.random() * 0xffffffff) | 0)) >>> 0,
@Rulexec
Rulexec / punycode.lua
Last active July 14, 2020 07:15
Port of punycode encode function in lua from https://github.com/bestiejs/punycode.js
local bit = require "bit"
local _M = {}
local maxInt = 2147483647
local base = 36
local tMin = 1
local tMax = 26
local skew = 38
local damp = 700
#define PIN_PEDAL_ANALOG A0
#define PIN_LED 8
#define MIN_LEVEL 590
#define MAX_LEVEL 620
bool pedalEnabled = false;
void setup() {
pinMode(PIN_LED, OUTPUT);