Skip to content

Instantly share code, notes, and snippets.

View cocodrino's full-sized avatar
🏠
Working from home

carlos L cocodrino

🏠
Working from home
  • Venezuela
View GitHub Profile
@cocodrino
cocodrino / file.jsx
Created October 17, 2022 14:47
wesocket react
export const WebsocketContext = createContext(false, null, () => {});
// ready, value, send
// Make sure to put WebsocketProvider higher up in
// the component tree than any consumers.
export const WebsocketProvider = ({ children }) => {
const [isReady, setIsReady] = useState(false);
const [val, setVal] = useState(null);
const ws = useRef(null);
@cocodrino
cocodrino / code.jsx
Created September 1, 2022 00:35
same ReactJS incremental counter in functional style using HOC,render props and Hooks
import React,{useEffect,useState} from "react";
const useCounter=()=>{
const [count,setCount] = useState(0)
useEffect(()=>{
let timer = setInterval(()=>{setCount(v=>v+10)},2000)
return ()=>{clearInterval(timer)}
},[])
@cocodrino
cocodrino / gist:f6298e5e593c7615f74687a5823ac1d6
Created August 5, 2022 19:22
remove unused imports automatically from typescript files
1) install eslint-plugin-unused-imports
`yarn add -D eslint-plugin-unused-imports`
2) add "unused-imports" to your "plugins"section under .eslitrc.json file
```
"plugins": [
"react",
"@typescript-eslint",
@cocodrino
cocodrino / download
Created November 1, 2018 02:48
download subfolder github
For other users who just want to download a file/folder from github, simply use:
svn export <repo>/trunk/<folder>
e.g.
svn export https://github.com/lodash/lodash.com/trunk/docs
(yes, that's svn here. apparently in 2016 you still need svn to simply download some github files)
Courtesy: Download a single folder or directory from a GitHub repo
@cocodrino
cocodrino / wrapper.tsx
Created July 14, 2021 14:35
wrapper for react testing library and redux
import { configureStore, Store } from '@reduxjs/toolkit';
import React, { ComponentType, ReactElement } from 'react';
import { Provider } from 'react-redux';
import { createMemoryHistory } from 'history';
import { Router } from 'react-router';
import { reducer } from '../state/store';
export const makeStore = (): Store => configureStore({ reducer });
const history = createMemoryHistory();
@cocodrino
cocodrino / factory.ts
Created April 16, 2021 13:59
factory typescript
class Person {
firstName = 'John';
lastName = 'Doe';
}
class Factory {
create<T>(type: (new () => T)): T {
return new type();
}
}
@cocodrino
cocodrino / gist:3c3513fa6b36022a22c9b732822b44c4
Created April 6, 2021 14:03
search text across git branches
git grep "string/regexp" $(git rev-list --all)
or filtering every commit and only show branches
git grep "your-search" `git show-ref --heads` or git show-ref --heads | xargs git grep "your-search"
@cocodrino
cocodrino / docker-compose.yaml
Created March 3, 2021 01:58
docker rabbitmq
version: "3.2"
services:
rabbitmq:
image: rabbitmq:3-management-alpine
container_name: 'rabbitmq'
environment:
RABBITMQ_ERLANG_COOKIE: "SWQOKODSQALRPCLNMEQG"
RABBITMQ_DEFAULT_USER: "rabbitmq"
RABBITMQ_DEFAULT_PASS: "rabbitmq"
RABBITMQ_DEFAULT_VHOST: "/"
@cocodrino
cocodrino / partition.js
Last active November 6, 2020 19:50
javascript partition similar to clojure partition
function partition(input, step,pad){
const output = [];
for (let i = 0; i < input.length; i += pad){
const part = input.slice(i, i + step)
if(part.length >=step )
output[output.length] = part
}
return output;
@cocodrino
cocodrino / elliot.ps
Last active June 27, 2020 02:38
Moving Averages helper for detect Elliot Waves
//@version=1
//@Author: cocodrino
//This indicator was made to allow three moving averages to be displayed without needing to use up 3 charting indicators individually
// based on https://elitecurrensea.com/education/wave-mystery-solved-via-simple-methods-based-on-fibs-and-mas/
study(title="MA Elliot Helpers", shorttitle="Melliot", overlay=true)