View vue-3-render-optimization.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
<template> | |
<div id="foo" @click="handleClick">Yo!</div> | |
</template> | |
*/ | |
import { | |
createElementVNode as _createElementVNode, | |
openBlock as _openBlock, | |
createElementBlock as _createElementBlock, |
View jscodeshift-scope-methods.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// getScope() is a method provided by jscodeshift that can be used to get the Scope object for a given Node. | |
// A Scope object represents the lexical scope of a node in the abstract syntax tree (AST). | |
// It contains information about the variables, functions, and other declarations that are in scope at a given point in the code. | |
// Here's an example of how getScope() can be used: | |
import { getScope } from 'jscodeshift'; | |
const source = ` | |
function foo() { |
View generics.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Point<T, U> { | |
x: T, | |
y: U, | |
} | |
impl<T, U> Point<T, U> { | |
// Methods that use different generic types than their struct’s definition | |
fn mixup<V, W>(self, other: Point<V, W>) -> Point<T, W> { | |
Point { | |
x: self.x, |
View rust_cheat_sheet.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// represents the `possible` absence of a value | |
enum Option<T> { | |
Some(T), | |
None, | |
} | |
let email: Option<String> = Some(email_str); | |
let email: Option<String> = None; | |
// representsan operation that could have failed |
View noUncheckedIndexAccess.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function upper(arr: string[]) { | |
for (let i = 0; i < arr.length; i += 1) { | |
let str = arr[i]; | |
console.log(str.upperCase()) | |
} | |
} | |
upper(['foo', 'bar', 'baz']); | |
// In Typescript when index into an array you get the element type of the array. |
View remove_brew-mongo_osx.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env sh | |
# checks to see if running | |
launchctl list | grep mongo | |
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.mongodb.plist | |
launchctl remove homebrew.mxcl.mongodb | |
pkill -f mongod |
View replaceAtRange.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function replaceRange(str: string, start: number, end: number, substitute: string): string { | |
const chunk = substitute.repeat(end - start); | |
return `${str.substring(0, start)${chunk}${str.substring(end)}`; | |
} |
View regexes.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* match first character after white space | |
*/ | |
const firstAtWhiteSpace = /(^|\s)[a-z]/g; |
View store.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// in this case the state is each individual product | |
const product = (state, action) => { | |
switch (action.type) { | |
case 'CREATE_PRODUCT': | |
return { | |
id: action.id, | |
name: action.name, | |
price: action.price, | |
}; | |
case 'EDIT_PRODUCT': |
View index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- | |
even though the "blue" comes later in the list of classes, | |
but CSS rules of precedence actually depends of the order of | |
classes in the stylesheet | |
--> | |
<span class="red blue"> | |
so I'm red | |
</span> |
NewerOlder