Skip to content

Instantly share code, notes, and snippets.

View VehpuS's full-sized avatar
🦔

Moshe Jonathan Gordon Radian VehpuS

🦔
View GitHub Profile
@VehpuS
VehpuS / for-each-glob-match.sh
Created August 22, 2021 08:36
Run a bash command on every glob match
#!/bin/bash
for glob in $(ls *.json); do echo $glob; done

Git pre-commit hook for large files

This hook warns you before you accidentally commit large files to git. It's very hard to reverse such an accidental commit, so it's better to prevent it in advance.

Since you will likely want this script to run in all your git repos, a script is attached to add this hook to all git repos you create / clone in the future.

Of course, you can just download it directly to the hooks in an existing git repo.

Installation

@VehpuS
VehpuS / git_archive.md
Created August 8, 2021 11:30
Getting a specific file / folder in a specific commit / branch from a remote git

git archive --remote=git@.... --format=tar branch-or-commit path/in/git > output.tar

@VehpuS
VehpuS / LICENSE
Last active August 8, 2021 11:40
This license applies to all public gists https://gist.github.com/vehpus, unless specified otherwise in the gist itself
MIT License
Copyright (c) 2021 Moshe Jonathan Gordon Radian
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
@VehpuS
VehpuS / .eslintignore
Created July 17, 2021 17:48
Auto linting / testing / prettifying on commits - template package.json, .eslintrc, .prettierrc, .prettierignore, .husky, .eslintignore, commitlint.config.js files from a react native project - demonstrating a setup that worked, possibly to be maintained with my continuous best practiices
node_modules
dist
.expo
.expo-shared
web-build
@VehpuS
VehpuS / center-on-screen.css
Created July 16, 2021 05:24
A quick reference to cool ways to center elements
.el {
position: absolute;
left: 50%;
transform: translateX(-50%);
top: 0;
transform: translateY(calc(50vh - 50%));
}
@VehpuS
VehpuS / DeepPartial.ts
Created July 6, 2021 13:02
DeepPartial type - allow undefined / null instantiation of nested fields in a Typescript type (implemented before I found standard implementations + good practice :) ).
export type DeepPartial<T> = {
[P in keyof T]?: NonNullable<T[P]> extends Array<infer U>
? Array<DeepPartial<NonNullable<U>>> | null
: NonNullable<T[P]> extends ReadonlyArray<infer V>
? ReadonlyArray<DeepPartial<NonNullable<V>>> | null
: NonNullable<T[P]> extends Date
? Date
: NonNullable<T[P]> extends {}
? DeepPartial<NonNullable<T[P]>> | null
: NonNullable<T[P]> | null;
@VehpuS
VehpuS / git-cleaning.md
Created June 29, 2021 20:32
Cleaning up git repos (focus on freeing space locally for now)

Listing large files

git rev-list --objects --all |
  git cat-file --batch-check='%(objecttype) %(objectname) %(objectsize) %(rest)' |
  sed -n 's/^blob //p' |
  sort --numeric-sort --key=2 |
  cut -c 1-12,41- |
  $(command -v gnumfmt || echo numfmt) --field=2 --to=iec-i --suffix=B --padding=7 --round=nearest
@VehpuS
VehpuS / json-stream-read.js
Created June 14, 2021 15:02
Read large JSON using filestream
const fs = require("fs");
const json = require("big-json");
const saveStringifiedData = (fileName, body) => {
const out = fs.createWriteStream(fileName); // `output/new-employee-data-${new Date().toISOString()}.json`);
const stringifyStream = json.createStringifyStream({ body });
stringifyStream.pipe(out);
};
zip -er9 zip_name.zip ./files_to_zip_path/