Skip to content

Instantly share code, notes, and snippets.

View wesbos's full-sized avatar
🔥
SLAYING BUGS

Wes Bos wesbos

🔥
SLAYING BUGS
View GitHub Profile
@wesbos
wesbos / is_blog.php
Created September 2, 2011 19:32
WordPress is_blog()
function is_blog () {
global $post;
$posttype = get_post_type($post );
return ( ((is_archive()) || (is_author()) || (is_category()) || (is_home()) || (is_single()) || (is_tag())) && ( $posttype == 'post') ) ? true : false ;
}
Usage:
<?php if (is_blog()) { echo 'You are on a blog page'; } ?>
@wesbos
wesbos / async-await.js
Created February 22, 2017 14:02
Simple Async/Await Example
// 🔥 Node 7.6 has async/await! Here is a quick run down on how async/await works
const axios = require('axios'); // promised based requests - like fetch()
function getCoffee() {
return new Promise(resolve => {
setTimeout(() => resolve('☕'), 2000); // it takes 2 seconds to make coffee
});
}
@wesbos
wesbos / logger.js
Created January 8, 2024 15:55
console.log line numbers in Node.js
// Use like this: node --import logger.js yourapp.js
import path from 'path';
const { log } = console;
[`debug`, `log`, `warn`, `error`, `table`, `dir`].forEach((methodName) => {
const originalLoggingMethod = console[methodName];
console[methodName] = (...args) => {
const originalPrepareStackTrace = Error.prepareStackTrace;
Error.prepareStackTrace = (_, stack) => stack;
Delivered-To: wesbos@gmail.com
Received: by 2002:a05:7000:d13:b0:844:ae73:58c with SMTP id mt19csp142934mab;
Thu, 26 Mar 2026 07:30:27 -0700 (PDT)
X-Received: by 2002:a17:903:2f50:b0:2ae:593c:48fe with SMTP id d9443c01a7336-2b0b09e6752mr81510745ad.13.1774535427275;
Thu, 26 Mar 2026 07:30:27 -0700 (PDT)
ARC-Seal: i=2; a=rsa-sha256; t=1774535427; cv=pass;
d=google.com; s=arc-20240605;
b=HBU7W/ibdMOp54XGM04Ej2KUuxJIlupSJZHxpFegVj3CX1ll6JrX1dUqEk0YWZLcs5
pIfMltp4F4WSd1TPCPSwveepGqqNXR5O1eJZzfURnL5LOH2I1RTaaYyk03G/jYGFjsUc
xTajrq0d52O5Mud4jMDAKB5UWojnHpBIHmirY9zvDL1/Me537me9bUclHgt26+VteevX
[
"",
"AC",
"AD",
"AE",
"AF",
"AG",
"AI",
"AL",
"AM",
@wesbos
wesbos / recent-places.md
Created October 29, 2015 14:04
Increase OSX "Recent Places

Increase the number of "Recent Places" that OSX shows in save dialogs. This allows you to quickly save files without having to dig through nested folders.

  1. Open your terminal and run defaults write .GlobalPreferences NSNavRecentPlacesLimit -int 10 && killall Finder
  2. OSX will now save 10, instead of the default. You won't see it take effect right away, but only after you save 5 more things.
  3. Enjoy your better life.

@wesbos
wesbos / tab-trigger.js
Created November 16, 2015 19:33
How to properly get a TAB trigger working with Emmet inside of JSX
{
"keys": ["tab"],
"command": "expand_abbreviation_by_tab",
// put comma-separated syntax selectors for which
// you want to expandEmmet abbreviations into "operand" key
// instead of SCOPE_SELECTOR.
// Examples: source.js, text.html - source
"context": [
{
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>🔥 Make a photo booth app in about 15 lines of JavaScript</title>
<link rel="icon" href="https://fav.farm/🎥" />
</head>
<body>
"workbench.editor.customLabels.patterns": {
"**/routes/**/+page.svelte": "${dirname(1)}/${dirname}",
"**/routes/**/+page.server.ts": "/${dirname} [server]",
"**/app/**/page.tsx": "${dirname}.${extname}",
"**/app/**/layout.tsx": "${dirname}/layout.${extname}"
}
class PathMe {
moves: string[] = [];
constructor() {
this.moves = [];
return this;
}
moveTo(x: number, y: number) {