Skip to content

Instantly share code, notes, and snippets.

View aneurysmjs's full-sized avatar
💭
асинхорнный

Аневризма aneurysmjs

💭
асинхорнный
View GitHub Profile
@aneurysmjs
aneurysmjs / noUncheckedIndexAccess.ts
Created August 7, 2022 16:30
'noUncheckedIndexAccess' Typescript compiler option
function upper(arr: string[]) {
for (let i = 0; i < arr.length; i += 1) {
let str = arr[i];
console.log(str.upperCase())
}
}
upper(['foo', 'bar', 'baz']);
// In Typescript when index into an array you get the element type of the array.
@aneurysmjs
aneurysmjs / remove_brew-mongo_osx.sh
Created January 11, 2020 09:55 — forked from katychuang/remove_brew-mongo_osx.sh
remove mongodb that was installed via brew
#!/usr/bin/env sh
# checks to see if running
launchctl list | grep mongo
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.mongodb.plist
launchctl remove homebrew.mxcl.mongodb
pkill -f mongod
function replaceRange(str: string, start: number, end: number, substitute: string): string {
const chunk = substitute.repeat(end - start);
return `${str.substring(0, start)${chunk}${str.substring(end)}`;
}
@aneurysmjs
aneurysmjs / regexes.ts
Last active November 8, 2019 14:39
regexes tricks
/**
* match first character after white space
*/
const firstAtWhiteSpace = /(^|\s)[a-z]/g;
@aneurysmjs
aneurysmjs / store.js
Last active November 5, 2019 13:39
redux stuff
// in this case the state is each individual product
const product = (state, action) => {
switch (action.type) {
case 'CREATE_PRODUCT':
return {
id: action.id,
name: action.name,
price: action.price,
};
case 'EDIT_PRODUCT':
@aneurysmjs
aneurysmjs / index.html
Last active October 29, 2019 08:58
CSS stuff
<!--
even though the "blue" comes later in the list of classes,
but CSS rules of precedence actually depends of the order of
classes in the stylesheet
-->
<span class="red blue">
so I'm red
</span>
@aneurysmjs
aneurysmjs / git-tricks.md
Last active July 6, 2023 09:00
git tricks

ignore files temporarily

start ignoring changes to a file:

git update-index --assume-unchanged path/to/file

keep tracking again:

git update-index --no-assume-unchanged path/to/file

see here

get a list of files marked --assume-unchanged:

git ls-files -v | grep '^[[:lower:]]'

@aneurysmjs
aneurysmjs / useErrorHook.tsx
Last active October 21, 2019 21:05
handle promise exceptions inside a hook
/**
* @link this is taken from here for reference
* https://github.com/testing-library/react-hooks-testing-library/issues/20#issuecomment-476628600
*/
import { useState, useEffect } from 'react';
import { renderHook } from '@testing-library/react-hooks';
describe('error hook tests', () => {
function useError(obj: Error | string): boolean {
if (obj.constructor.name === 'Error') {
@aneurysmjs
aneurysmjs / bundle.js
Last active October 17, 2019 09:20
bundle-tricks
// .babelrc
{
"presets": [
[
"@babel/preset-env",
{
// this tells @babel "hey, don'y change any of the modules, let Webpack handle it
"modules": false
// you only get the individual pollyfill that you need
"useBuiltIns": "usage"
@aneurysmjs
aneurysmjs / types-vs-interface.ts
Created October 15, 2019 17:10
types vs interfaces
interface Base {
id: string;
timestamp: string;
}
interface Product extends Base {
price: number;
stock: number;
}