Skip to content

Instantly share code, notes, and snippets.

View shapkarin's full-sized avatar
🔍
looking for a job

Shapkarin shapkarin

🔍
looking for a job
View GitHub Profile
@shapkarin
shapkarin / README.md
Last active April 2, 2024 14:55
Golang socket random

Solutions

  • crypto.go uses crypto/rand, which returns a big.Int.
  • uuid.go uses github.com/google/uuid that converts to a big.Int.

For both solutions:

Sockets are provided by github.com/gorilla/websocket.

9f973d2866fdd083ef30fe4fcc955fbb search query for the gist.github testing proposes that can be found at https://github.com/github/feedback/discussions/4862#discussioncomment-1104441
find . -type f -size +100000k -exec ls -lh {} \; | awk '{ print $9 ": " $5 }'
@shapkarin
shapkarin / infinite.js
Last active April 23, 2019 22:48 — forked from jebeck/infinite.js
infinite interactivity with Inquirer and RxJS's Subject
// run with `node infinite.js` in node v4.x+
// must have Inquirer installed (`npm install inquirer`)
const inquirer = require('inquirer');
const Rx = require('rx');
const prompts = new Rx.Subject();
function makePrompt(msg, i) {
return {
@shapkarin
shapkarin / random_hex.rb
Created April 18, 2019 14:44
generate random hex
Random.new.bytes(3).unpack("H*")[0]
@shapkarin
shapkarin / cancel.js
Last active June 22, 2019 14:25
Close axios with saga worker cancellation. thank's to that issue https://github.com/redux-saga/redux-saga/issues/651
import axios, { CancelToken } from 'axios';
import { CANCEL } from 'redux-saga';
export const fetchAutocomplete = () => {
const url = 'some/url';
const source = CancelToken.source();
const request = axios.get(url, { cancelToken: source.token });
request[CANCEL] = () => source.cancel();
return request;
};
@shapkarin
shapkarin / fetch-worker-example.js
Last active June 21, 2019 21:21
redux-saga fetch worker example
import { fork, debounce } from 'redux-saga/effects';
import fetch from './fetch';
import { fetchSomeInfo } from './someApi';
import {
loadSomeInfoStart,
loadSomeInfoSuccess,
loadSomeInfoError
} from './actions';
function* getRandomNumberSeed(counter = 0, min = 0, max = 100) {
while (counter--) {
yield Math.floor(Math.random() * (max - min + 1)) + min
}
}
const seed = [...getRandomNumberSeed(10)];
console.log(seed);
@shapkarin
shapkarin / importAll.js
Last active January 21, 2019 16:52
import all files from folder with webpack
const modules = require.context('path/to/folder', false, /\.type$/);
modules.keys().forEach(modules);