Skip to content

Instantly share code, notes, and snippets.

💭
some may never live

Brad Greenwald bradgreens

💭
some may never live
Block or report user

Report or block bradgreens

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View active record notes.rb
# Minimal query
MyModel.where(property: true)
# Minimal non-null query
MyModel.where.not(property: nil)
# Query multiple values for a column
MyModel.where(enum_type: [1,2])
@bradgreens
bradgreens / snaggles.ts
Last active Oct 9, 2019
Dat Falseness - Protect data against react controlled input `value` warnings
View snaggles.ts
/* potential snaggles:
`myThing` // server did not provide property
`myThing.property: null` // server provided null
`myThing.property: undefined` // client-side parsing provided undefined
`myThing.property: 0` // persisted enum property is falsey 0, typeof 'number'
*/
/** guarantee schroedinger's server property is in string format */
function ensureInputString(value: string): string {
if (value === undefined || value == null) {
View grep the shit.md

grep examples that don't suck, er, they're so simple they kinda suck

Minimal use cases

In these examples, the is the string we're searching for.

Search one file

grep the README.md

Search files in current directory, non-recursive

grep the *

@bradgreens
bradgreens / load-jquery-in-console.js
Created Aug 9, 2019
Load jQuery in the browser JS Console
View load-jquery-in-console.js
var script = document.createElement('script');script.src = "https://code.jquery.com/jquery-3.4.1.min.js";document.getElementsByTagName('head')[0].appendChild(script);
View rank-items.ts
// Just archiving a ranking script I made for an app
// Assigns rank to items based on the `votes` property, and handles ties
answers.sort( ( a, b ) => b.votes - a.votes )
const clonedAnswers = answers.slice() as any
let rank = 1
clonedAnswers.forEach((answer) => {
if (answer.rank) {
View top 10 commands.sh
history | cut -c8- | sort | uniq -c | sort -rn | head -n 10
View kebab To Title Case.test.ts
import { kebabToTitleCase } from './';
describe(kebabToTitleCase, () => {
it('formats a camelCase string to Title Case', () => {
expect(kebabToTitleCase('theCrazyNeverDie'))
.toBe('The Crazy Never Die');
});
it('formats to Title Case and strips whitespace', () => {
expect(kebabToTitleCase('I could never explainMyself'))
View ts-js-fucking-dece-ass-pull-requests.md

Fucking Dece-Ass Pull Requests (for TS/JS)

Prior to opening your pull request, try not to suck.

If you are seeking review/feedback before meeting this criteria, meet as much as you can and TAP a DRAFT PR.

  • Remove unecessary debugging, Ctrl+F for debugger and console.log, remove unecessary noise
  • Review & improve comments, Ctrl+F for // and /**, pretend you're not you and see if they make sense
  • TS/JS Lint passes
View wget site clone.sh
# https://www.guyrutenberg.com/2014/05/02/make-offline-mirror-of-a-site-using-wget/
brew install wget
wget -mkEpnp http://example.org
View markdownify.js
document.getElementsByTagName("head")[0].insertAdjacentHTML("beforeend", "<link rel=\"stylesheet\" href=\"https\:\/\/mrcoles.com\/demo\/markdown-css\/markdown.css?1\" />");
document.body.className += " markdown";
You can’t perform that action at this time.