Skip to content

Instantly share code, notes, and snippets.

View JonWallsten's full-sized avatar

Jon Wallsten JonWallsten

  • Jon Wallsten Web Consulting AB
  • Sweden
View GitHub Profile
@JonWallsten
JonWallsten / dts-bundle.ts
Last active February 14, 2018 10:49
Bundle generated and user made definition/declaration/d.ts files into a single d.ts bundle
/**
* This script bundles d.ts files generated by typescript compiler and your own d.ts files.
* The reason for the need of copying your own d.ts is that tsc won't generate typings for files with only types/interfaces,
* hence they won't end up in the declaration folder.
*
* Specify typings in package.json
* "types": "dist/index.d.ts"
*
* Set the following props in tsconfig.json under "compilerOptions":
* "declaration": true,
@JonWallsten
JonWallsten / move_root_with_history.sh
Created July 31, 2018 18:04
[GIT] Move root files into subfolder and preserve history
git filter-branch --index-filter 'git ls-files -s | sed "s-\t\"*-&[INSERT_PATH_HERE]/-" |
GIT_INDEX_FILE=$GIT_INDEX_FILE.new \
git update-index --index-info &&
mv "$GIT_INDEX_FILE.new" "$GIT_INDEX_FILE"' [INSERT_COMMIT_HASH_HERE]..HEAD
@JonWallsten
JonWallsten / git_move_file_keep_history.sh
Last active October 8, 2018 05:33
Move/rename any file and keep git commit history
# Move/rename any file and keep git history
git filter-branch --index-filter 'git ls-files -s | sed "s|[old_path]|[new_path]|g" |
GIT_INDEX_FILE=$GIT_INDEX_FILE.new \
git update-index --index-info &&
mv "$GIT_INDEX_FILE.new" "$GIT_INDEX_FILE"' [first_commit_hash]..HEAD
# Example
git filter-branch --index-filter 'git ls-files -s | sed "s|packages/web-app|packages/web-app-new|g" |
GIT_INDEX_FILE=$GIT_INDEX_FILE.new \
git update-index --index-info &&
@JonWallsten
JonWallsten / angular-clean-scope.js
Last active February 18, 2021 10:37
Clean AngularJs (1.5) child scopes to fix memory leak when using large data sets in template with transclude
// We've been working for a full day hunting down why AngularJS 1.5 retains large data sets after a component is removed.
// We don't know the exact cause, since there are many parts involved.
// But jQuery cache, $scope.$$watchers, $transclude all seems to be different players in this issue.
// We provided a super large data (used about 1GB+ of memory) to a sub component in our template.
// But when resetting the component to apply new data instead of using the same amount,
// the memory doubled until the new component was rendered and Angular eventually cleared the scoped.
// Since this ended up using almost 3GB it crashed Chrome for our users.
// After testing everything trying to clean our objects it was still an issue since the data was references in so many places by Angular.
// Our solution was to thoroughly clean all child scopes for our destroyed component by deleting all watchers, all non-angular props,
// and if those props where objects, also delete those sub props in case other references to t