Skip to content

Instantly share code, notes, and snippets.

View groupsky's full-sized avatar
💭
I may be very slow to respond.

Geno Roupsky groupsky

💭
I may be very slow to respond.
  • Plovdiv/Bulgaria
View GitHub Profile
@groupsky
groupsky / paranoid-jest.js
Created March 13, 2024 15:46
Paranoid jest console setup
const isPromise = (candidate) => candidate && typeof candidate?.then === 'function'
beforeEach(() => {
jest.spyOn(console, 'debug')
jest.spyOn(console, 'log')
jest.spyOn(console, 'warn')
jest.spyOn(console, 'error')
})
afterEach(() => {
@groupsky
groupsky / configure.js
Created April 20, 2021 17:28
ModBus read and setup for Dio Smart MBSL32DI
#!/usr/bin/env node
/*
* ModBus configuration for Dio Smart MBSL32DI 32-channel digital input module
* https://www.aliexpress.com/item/4001220947199.html
*/
////////////////
// CONFIGURATION
////////////////
@groupsky
groupsky / travis-builds-stats.js
Created February 16, 2021 16:58
Fetch travis builds info
// SET PROPER VALUES
let authToken = 'token zxcvbnmsdfhjkqwrt'
let end = '2021-00-00T00:00:00Z'
let repo = 123456
// runtime variables
let finished = false
let data = []
let offset = 0
let limit = 50
// the main cycle
@groupsky
groupsky / noark-ex9em.js
Last active January 21, 2022 18:42
ModBus read for Noark Ex9EM 1P 1M 80A MO MT
#!/usr/bin/env node
/*
* ModBus read for Noark Ex9EM 1P 1M 80A MO MT Electric Meter
* https://www.noark.com.hr/en/products/107281
*/
////////////////
// CONFIGURATION
////////////////
@groupsky
groupsky / sinotype-dds024mr.js
Last active October 15, 2020 18:39
ModBus read for Sinotype DDS024MR Electric Meter (https://s.click.aliexpress.com/e/_eNIqlR)
#!/usr/bin/env node
/*
* ModBus read for Sinotype DDS024MR Electric Meter
* https://s.click.aliexpress.com/e/_eNIqlR
*/
////////////////
// CONFIGURATION
////////////////
@groupsky
groupsky / sinotype-dds519mr.js
Last active October 8, 2022 16:33
ModBus read for Sinotype DDS519MR Electric Meter (https://s.click.aliexpress.com/e/_eNvkb3)
#!/usr/bin/env node
/*
* ModBus read for Sinotype DDS519MR Electric Meter
* https://s.click.aliexpress.com/e/_eNvkb3
*/
////////////////
// CONFIGURATION
////////////////
@groupsky
groupsky / MockTimer.js
Last active September 10, 2020 16:56
Allow to manually trigger specific timers
import { act } from 'react-dom/test-utils'
class UniqueNumber extends Number {}
/**
* Mock specific timer and allow the others to passthrough normally
*/
export default class MockTimer {
/**
* timeout value to pass to setTimeout as second parameter
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@groupsky
groupsky / _cors.php
Last active May 2, 2019 11:46
php CORS with multi origin support
<?php
// List of allowed origins, should be in some config place, or even loaded from env
$ALLOWED_ORIGINS = array(
'http://localhost:8080',
'... any other origin',
);
// Validate request is allowed - should be in every entry file
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
import java.lang.Math;
import java.lang.System;
public class fast_roulette {
/* program n_select=1000 times selects one of n=4 elements with weights weight[i].
* Selections are summed up in counter[i]. For the weights as given in the example
* below one expects that elements 0,1,2 and 3 will be selected (on average)
* 200, 150, 600 and 50 times, respectively. In good agreement with exemplary run.
*/