Skip to content

Instantly share code, notes, and snippets.

View mendes5's full-sized avatar
📉
[object Object]

mendes5

📉
[object Object]
View GitHub Profile
fn mount<T, P, B: FnMut(&mut P)>(
component: fn(this: Option<T>, props: P, block: B) -> T,
props: P,
block: B,
) {
component(None, props, block);
}
struct Props<T: FnMut()> {
on_click: T,
@mendes5
mendes5 / LinkedHeightContainer.js
Created September 14, 2022 18:01
A container that can have many elements but will not influence its container height, to do that, it should be linked to another element inside the same container to get its height from.
const LinkedHeightContainer = ({ children, link }) => {
const ref = useRef(null);
useEffect(() => {
const observer = new ResizeObserver((entries) => {
const entry = entries[entries.length - 1];
const height = `${entry.contentRect.height}px`;
ref.current.style.height = height;
});
@mendes5
mendes5 / s.js
Created September 9, 2022 19:36
Poor mans version of S.js
const effects = [];
let isCollectingEffects = false;
const data = (init) => {
const deps = [];
let oldValue = init;
return (value) => {
@mendes5
mendes5 / subtract.ts
Created August 10, 2022 21:35
Subtract one from a number inside a string in typescript
type SubtractOne<T> =
T extends '9' ? '8'
: T extends '8' ? '7'
: T extends '7' ? '6'
: T extends '6' ? '5'
: T extends '5' ? '4'
: T extends '4' ? '3'
: T extends '3' ? '2'
: T extends '2' ? '1'
: T extends '1' ? '0'
Math.max(NaN, 100) === NaN
@mendes5
mendes5 / debug-rerender.ts
Created June 28, 2022 22:25
Helps debugging react hooks re-render reasons
const useDebug = (deps: Record<string, any>) => {
Object.entries(deps).forEach(([key, value]) => {
useEffect(() => console.log(`${key} Changed`), [value]);
});
};
@mendes5
mendes5 / events.js
Created June 26, 2022 04:50
Pretty print a micromark events list
console.log(self.events.map(x => [x[0], x[1].type, x[2].sliceSerialize(x[1], true)]).map(x => x.join(' | ')).reduce((prev, curr) => {
if (curr.startsWith('enter')) {
prev = { i: prev.i, t: prev.t + '\n' + ' '.repeat(prev.i) + curr };
prev.i+=2
return prev
} else {
prev.i-=2
return { i: prev.i, t: prev.t + '\n' + ' '.repeat(prev.i) + curr }
}
}, { i: 0, t: '' }).t)
@mendes5
mendes5 / ocs.json
Created March 9, 2022 04:04
Deep Rock Galatic overclocks by guns by characters, from karl.gg
{
"Engineer": {
"\"Warthog\" Auto 210": [
{
"id": 25,
"character_id": 1,
"gun_id": 1,
"overclock_type": "Clean",
"overclock_index": 1,
"overclock_name": "Stunner",
@mendes5
mendes5 / README.md
Created February 11, 2022 16:54
aws-iot-device-sdk + Nx Webpack config

Packages Needed:

  • aws-iot-device-sdk
  • buffer
  • process
  • util
  • @types/aws-iot-device-sdk(optional)

Override the default webpack config in project.json

While using @nrwl/web:build as the executor for the build target, add a custom webpack config file to your build configurations:

@mendes5
mendes5 / yaml.yml
Last active January 10, 2022 12:48
How to skip a GitLabCI job from a before_script
build-job:
before_script:
- |
if [[ "${CI_COMMIT_BRANCH}" != "${CI_DEFAULT_BRANCH}" ]]; then
git fetch origin $CI_DEFAULT_BRANCH
SKIPPABLE_CHANGES=`git diff origin/$CI_DEFAULT_BRANCH --name-only $SKIP_SOURCE_STAGES_FOR_DIRS`
ALL_CHANGES=`git diff origin/$CI_DEFAULT_BRANCH --name-only`
if [[ $SKIPPABLE_CHANGES == "" ]]; then
echo "There were no skippable changes, the script will continue"
elif [[ $SKIPPABLE_CHANGES == $ALL_CHANGES ]]; then