Skip to content

Instantly share code, notes, and snippets.

View creationspirit's full-sized avatar

Andrija Perušić creationspirit

View GitHub Profile
/**
* range()
*
* Returns an array of numbers between a start number and an end number incremented
* sequentially by a fixed number(step), beginning with either the start number or
* the end number depending on which is greater.
*
* @param {number} start (Required: The start number.)
* @param {number} end (Required: The end number. If end is less than start,
* then the range begins with end instead of start and decrements instead of increment.)
@creationspirit
creationspirit / format.js
Created August 30, 2019 13:24
Convert seconds to HH:MM:SS in JavaScript
export const formatSeconds = seconds => {
const measuredTime = new Date(null);
measuredTime.setSeconds(seconds);
return measuredTime.toISOString().substr(11, 8);
};
@creationspirit
creationspirit / GreaterThanRefinement.jsx
Created August 30, 2019 12:15
A custom Algolia React InstantSearch widget. It is a toggle refinement filtering on some attribute with 'greater than a given threshold' condition. One of my projects needed this feature and original library does not support this kind of widget so I made a custom one. Hope it helps to someone
import React from 'react';
import { createConnector } from 'react-instantsearch-dom';
const connect = createConnector({
displayName: 'GreaterThanRefinement',
getProvidedProps(props, searchState) {
const currentRefinement = searchState.greaterThan[props.attribute] || false;
return { currentRefinement };
},
refine(props, searchState, nextRefinement) {
@creationspirit
creationspirit / serial_reader.py
Created August 30, 2019 11:45
A simple python script for reading two types of sensor readings on a serial port and writing them in two separate .csv files with timestamps.
import serial
import datetime
import csv
import sys
import keyboard
if len(sys.argv) != 2:
print('Wrong number of arguments! First and only argument must be serial port name.')
exit(-1)