Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Adam adamgen

🏠
Working from home
View GitHub Profile
@adamgen
adamgen / cloned-wp-update.sh
Created Feb 23, 2021
Setting up a freshly cloned WP instance with CLI commands
View cloned-wp-update.sh
wp search-replace http://origin.com http://destination.com --all-tables
wp option update home http://destination.com
wp option update siteurl http://destination.com
# Make sure that you have write permissions first
wp rewrite flush
@adamgen
adamgen / effects.ts
Created May 6, 2020
NGRX | Use effects and router-store to isolate route related side 🧙🏼‍♂️ effects - effects injectable
View effects.ts
setCurrentCourse$ = createEffect(() => this.actions$.pipe(
ofType(ROUTER_NAVIGATED), // get router navigated ngrx actions
mergeMap(() => this.store.pipe(
select(selectRouteParam(‘id’))) // get the id from the router store
),
map((id: string) => setIds({ id })), // dispatch a new action to set the selected id
));
@adamgen
adamgen / good.component.ts
Created May 6, 2020
NGRX | Use effects and router-store to isolate route related side 🧙🏼‍♂️ effects - good component
View good.component.ts
import { Store, select } from @ngrx/store’;
import { Component } from @angular/core’;
@Component({
selector: ‘app-root’,
template: `{{selectedId$ | async | json}}`,
})
export class HomeComponent {
selectedId$ = this.store.pipe(select((state: any) => state.featureName.selectedId));
constructor(
private store: Store,
@adamgen
adamgen / bad.component.ts
Created May 6, 2020
NGRX | Use effects and router-store to isolate route related side 🧙🏼‍♂️ effects
View bad.component.ts
@Component({
export class MyComponent {
id: string;
id$ = this.activatedRoute.params.pipe(
map(params => params.id),
tap(id => this.id = id),
);
constructor(
private activatedRoute: ActivatedRoute,
) {}
View General debug settings for node.js on vs code
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "attach",
"name": "Node: Nodemon",
"processId": "${command:PickProcess}",
"restart": true,
"protocol": "inspector",
@adamgen
adamgen / bash completeion
Last active Aug 29, 2019
initial bash profile scripts that run on startup
View bash completeion
# install: brew install bash-completion
# then in .bash_profile
if [ -f $(brew --prefix)/etc/bash_completion ]; then
. $(brew --prefix)/etc/bash_completion
fi
View Make SVG element from browser into a d3 code
getAtts = (elem) => {
const attrs = {};
Object.values(elem.attributes).forEach(attr => {
attrs[attr.name] = attr.value;
});
return attrs
}
atts = getAtts($0);
d3Str = '';
d3Str += `.append('${$0.tagName}')\n`
View Typescript Helpful Types
// any type of callable
type callable = (...args: any[]) => any;
// only acept values of object T
type ValueOf<T> = T[keyof T];
View Type script string literal dynamic type using a guard
type a = 'aaa';
const b = 'a' + 'a' + 'a';
let c: a;
const IsA = (string: string): string is a => string === 'aaa';
c = b; // gives an error
if (IsA(b)) {
View Update mongoose schema
// change old_key_name with new_key_name
db.collection.find().forEach(function(document) {
var old_key_name = document.old_key_name;
db.collection.update(
{ _id: document._id },
{
$set: {
new_key_name: old_key_name,
},