Skip to content

Instantly share code, notes, and snippets.

View jonschlinkert's full-sized avatar
🤔
Trying to stay in the right branch of the wave function.

Jon Schlinkert jonschlinkert

🤔
Trying to stay in the right branch of the wave function.
View GitHub Profile
export const fixJson = (ast, stack) => {
const fixValue = last => {
if (last.type === 'text' && /\d\.$/.test(last.value)) {
last.value += '0';
} else if (last.type === 'text' && /tr?u?e?$/.test(last.value)) {
last.value = 'true';
} else if (last.type === 'text' && /fa?l?s?e?$/.test(last.value)) {
last.value = 'false';
} else if (last.type === 'text' && /nu?l?l?$/.test(last.value)) {
last.value = 'null';
[
{
"name": "openai_chat_completion",
"title": "Create Chat Completion Schema",
"description": "Schema to validate requests for OpenAI's createChatCompletion endpoint",
"type": "object",
"properties": {
"frequency_penalty": {
"type": ["number", "null"],
"title": "frequency_penalty",
const NEWLINE_REGEX = /\r?\n/;
const INCLUDE_REGEX = /^(\s*)include\(([A-Z][0-9a-zA-Z]*?)\)/;
const SECTION_START_REGEX = /^([a-z]+) ([A-Z][0-9a-zA-Z]*?)\s*{/;
const SECTION_END_REGEX = /(?<=})/;
class Section {
type = '';
name = '';
leading = [];
body = [];
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Ansi 0 Color</key>
<dict>
<key>Alpha Component</key>
<real>1</real>
<key>Blue Component</key>
<real>0.13333329558372498</real>
@jonschlinkert
jonschlinkert / parse-regex.js
Last active February 8, 2024 08:24
I created this to see how hard it would be to provide syntax highlighting for regex in the terminal. Try it out and see for yourself!
'use strict';
const colors = require('ansi-colors');
const chars = {
backslash: '\\',
backtick: '`',
caret: '^',
colon: ':',
comma: ',',
@jonschlinkert
jonschlinkert / hash.js
Created May 18, 2021 06:25
Attempt at creating a Ruby-ish Hash using JavaScript's Proxy.
'use strict';
const values = new Map();
const getValues = hash => {
const v = values.get(hash) || new Map();
values.set(hash, v);
return v;
};
'use strict';
const download = require('download');
/**
* Download all ballots
*/
const dl = async (baseurl, dest) => {
const pending = [];
@jonschlinkert
jonschlinkert / keybindings.json
Created December 7, 2020 16:36
VS Code - Open Keyboard Shortcuts (JSON) - Add the following key binding configuration to your `keybindings.json` file to automatically wrap angle brackets around selected text by typing "<".
[
{
// wrap a selection with angle brackets (<)
"key": "shift+,",
"command": "editor.action.insertSnippet",
"when": "editorHasSelection && editorTextFocus",
"args": {
"snippet": "<${0:${TM_SELECTED_TEXT}}$0>"
}
}
{
// Editor
// Controls whether the editor shows CodeLens.
"diffEditor.codeLens": false,
// When enabled, the diff editor ignores changes in leading or trailing whitespace.
"diffEditor.ignoreTrimWhitespace": true,
// Timeout in milliseconds after which diff computation is cancelled. Use 0 for no timeout.
@jonschlinkert
jonschlinkert / first-amendment.md
Last active November 16, 2021 17:36
Free speech is not without exceptions.

What Does Free Speech Mean?

Among other cherished values, the First Amendment protects freedom of speech. The U.S. Supreme Court often has struggled to determine what exactly constitutes protected speech. The following are examples of speech, both direct (words) and symbolic (actions), that the Court has decided are either entitled to First Amendment protections, or not.

Freedom of speech includes the right:

  • Not to speak (specifically, the right not to salute the flag). West Virginia Board of Education v. Barnette, 319 U.S. 624 (1943).
  • Of students to wear black armbands to school to protest a war (“Students do not shed their constitutional rights at the schoolhouse gate.”). Tinker v. Des Moines, 393 U.S. 503 (1969).
  • To use certain offensive words and phrases to convey political messages. Cohen v. California, 403 U.S. 15 (1971).
  • To contribute money (under certain circumstances) to political campaigns. Buckley v. Valeo, 424 U.S. 1 (1976).