Skip to content

Instantly share code, notes, and snippets.

// Name: Move code left
// Shortcut: cmd shift t
// Author: David Adams
// Twitter: @dadamssg
import "@johnlindquist/kit"
let text = await getSelectedText()
let lines = text.split("\n")
let lineStarts = lines.map(line => line.search(/\S/))
// Name: format-json
// Shortcut: cmd shift j
// Author: David Adams
// Twitter: @dadamssg
import "@johnlindquist/kit"
let jsonabc = await npm("jsonabc")
let text = await getSelectedText()

The problem

Time Machine will backup your files. For a developer, and having loads of node_modules and vendor directories for projects, this is huge time suck and waste since those can be brought back with npm, yarn, composer, etc.

The solution

Directories can be excluded from Time Machine using the cli.

Adding exclusions

First, verify that you can get a list of directories that you want to exclude:

cd "$HOME/code" && find $(pwd) -maxdepth 3 -type d \( -name vendor -o -name node_modules \)

Live Templates

Component boilerplate

Uses file name to generate component.

Template text:

import React, {Fragment} from 'react'
<?php
interface DBTransaction {
public function begin();
public function commit();
public function rollback();
}
class LaravelDBTransaction implements DBTransaction {
public function begin()
import {render as rtlRender} from 'react-testing-library'
function render ({foo = 'defaultFoo', doSomething = jest.fn()} = {}) {
const result = rtlRender(<MyComponent foo={foo} doSomething={doSomething} />)
return {
...result,
doSomething,
clickButton: () => fireEvent.click(result.querySelector('button'))
}
}
function Profile ({userId}) {
const [profile, setProfile] = useState(null)
useEffect(() => {
fetch(`/api/users/${userId}`)
.then(res => {
setProfile(res.json().profile)
})
}, [userId]) // run when it has new userId
return (
<div>{profile && profile.full_name}</div>
<?php
namespace Acme\Project\Bundle\AppBundle\Data;
use Acme\Project\Model\App\Data\TransactionManager;
use Doctrine\ORM\EntityManagerInterface;
class DoctrineTransactionManager extends TransactionManager
{
/**
<?php
use SimpleBus\Message\Message;
interface CommandPipe
{
/**
* @param Message $command
* @param callable $next
*/
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
export PS1="> \W\[\033[32m\]\$(parse_git_branch)\[\033[00m\] $ "