Skip to content

Instantly share code, notes, and snippets.

View dev99problems's full-sized avatar
🤷
Little By Little

Gene Chulkov dev99problems

🤷
Little By Little
View GitHub Profile
def make_readable_size(size_in_bytes)
suffix = %W(B KB MB)
idx = 0
rest = 0
size = size_in_bytes
while size / 1024 > 1
idx += 1
new_size = size / 1024
rest = size - new_size * 1024
@dev99problems
dev99problems / table_signs.js
Created September 6, 2021 09:13
List of signs to easily draw table in CLI
const signs = {
topLeft: '┌',
topVert: '┬',
topRight: '┐',
bottomLeft: '└',
bottomVert: '┴',
bottomRight: '┘',
horizLeft: '├',
horizRight: '┤',
vert: '│',
WEBVTT
1
00:00:03.643 --> 00:00:07.514
You know, we should all do?
2
00:00:07.557 --> 00:00:10.086
Go
see a musical.
const languages = [
{
"code": "af",
"langEnglishName": "Afrikaans"
},
{
"code": "ak",
"langEnglishName": "Akan"
},
{
@dev99problems
dev99problems / language_data.mock.js
Created June 11, 2021 13:25
Simple example of mocking dependencies with node-tap@15.0.9
module.exports = {
'ar-AR': {
'nativeName': 'العربية',
'englishName': 'Arabic'
},
'cs': {
'nativeName': 'Čeština',
'englishName': 'Czech'
},
'uk': {
@dev99problems
dev99problems / test.ts
Created February 8, 2021 10:45
jest + process.env
// How to test something with Jest and process.env
// Details link to original author's response on SO
// https://stackoverflow.com/questions/48033841/test-process-env-with-jest
describe('environmental variables', () => {
const OLD_ENV = process.env;
beforeEach(() => {
// MOST IMPORTANT THING IS 👇
jest.resetModules() // Most important - it clears the cache
@dev99problems
dev99problems / persistData.ts
Last active February 3, 2021 12:02
Really simple util class to use localStorage
class PersistData {
storageName: string
constructor(storageName: string) {
this.storageName = storageName
}
get() {
try {
const value = window.localStorage.getItem(this.storageName) || ''
@dev99problems
dev99problems / getRecordsToSave.js
Last active September 25, 2020 12:14
Mocking `new Date()` in tests with a specific date
const _isEmpty = require('lodash/isEmpty')
module.exports = (news, prevResults) => {
const recordsToSave = []
if (_isEmpty(news) || _isEmpty(prevResults)) {
return recordsToSave
}
// some loop over values

CRA 2.x + TS setup:

This will give you complete intellisense and type safety within your app and CSS modules

typesafe-css-modules

🚨 NOTE

  • refactoring className from ts file wont update your css/scss className, to change class names you have to change it within your .module.scss file
@dev99problems
dev99problems / react-file-upload.js
Created March 2, 2020 15:57 — forked from AshikNesin/react-file-upload.js
Simple React File Upload
import React from 'react'
import axios, { post } from 'axios';
class SimpleReactFileUpload extends React.Component {
constructor(props) {
super(props);
this.state ={
file:null
}