Skip to content

Instantly share code, notes, and snippets.

View KamMif's full-sized avatar
Focusing

Kam KamMif

Focusing
View GitHub Profile
read = IO.read(ARGV.first)
puts 'hello' if a == nil
read.chomp
one_str = read.split("\n")
name = "Time"
one_str.each {|x| a = x.split("|")
if a[1].include?(name)
d = a[7].to_i
e = a[7].to_f - d
puts a[1]
var matrixExample = [
[1, 2, 3, 4],
[4, 5, 6, 5],
[7, 8, 9, 7],
[7, 8, 9, 7]
]
function sumMatrix(matrix) {
var arr = []
var arr2 = []
@KamMif
KamMif / array.includes(Obj)
Created November 7, 2017 08:20
find includes item in to array from obkect
const values = ['sadasdasd', 'sdfsdfsdf', 'sdfsdf'];
const obj = [{ id: 1, transaction: 'sdfsdf' }];
const sorted = values.filter(value => obj.map(item => item.transaction).includes(value));
console.log(sorted);
@KamMif
KamMif / filtred obj
Last active November 10, 2017 12:54
find includes in array and output filtred object
const values = ['sadasdasd', 'sdfsdfsdf', 'sdfsdf'];
const obj = [{ id: 1, transaction: 'sadasdasd' }];
const sorted = obj.filter(item => item.transaction.indexOf(values.transaction) !== -1);
console.log(sorted);
// Function for rinding min index of elemtnt in array
function smallest(arr) {
let smallest[0];
let smallestIndex = 0;
for (let i = 0; i < arr.length; i ++) {
if (arr[i] < smallest) {
smallest = arr[i]
smallestIndex = i
const times10 = n => n * 10;
const cache = {};
const memoTimes10 = n => {
if (n in cache) {
return cache[n];
}
else {
let res = times10(n);
cache[n] = res;
const memoizationClosuresTimes10 = n => {
let cache = {};
return n => {
if (n in cache) {
return cache[n]
} else {
let res = n * 10;
cache[n] = res;
return res;
}
function* RequestData() {
try {
yield put(requestData());
while (true) {
yield call(delay, 60000);
const data = yield call(fetchDataStatus);
if (data.res) {
yield put(requestDataSuccess(data.resp));
}
@KamMif
KamMif / async_function_chain.js
Created July 7, 2019 18:01
async function chain
function chain(prev = null) {
const cur = () => {
if (cur.prev) {
cur.prev.next = cur;
cur.prev();
} else {
cur.forward();
}
}
cur.prev = prev;
@KamMif
KamMif / timeout.js
Created July 7, 2019 18:05
add timeout
function timeout(ms, fn) {
let timer = setTimeout(() => {
if (timer) console.log('Function timedout');
timer = null;
}, ms);
return (...args) => {
if (timer) {
timer = null;
fn(...args);
}