Skip to content

Instantly share code, notes, and snippets.

View devinrhode2's full-sized avatar
😀

Devin Rhode devinrhode2

😀
View GitHub Profile
@devinrhode2
devinrhode2 / safeCall.ts
Last active December 30, 2022 20:23
safely call function, and return `returnValue | Error` https://www.swyx.io/errors-not-exceptions
/**
* Calls `callback`, catches any errors and returns `returnValue | Error`
*
* TODO: create npm package
*
* See: https://dev.to/devinrhode2/comment/1fcga
*/
export const safeCall = <
TCallback extends (
...args: unknown[]
import { execaCommandSync } from 'execa'
/** @type {(cmdString: string, debug?: 'debug') => [string | undefined, string | unknown]} */
export const exec = (cmdString, debug) => {
let exception
let result
try {
result = execaCommandSync(cmdString, {
env: {
// @ts-expect-error - not application code
@rwjblue
rwjblue / application.controller.js
Created December 14, 2015 18:07 — forked from barneycarroll/application.controller.js
Can't access object values by dynamic key in Handlebars
import Ember from 'ember';
export default Ember.Controller.extend({
numbers:['1','2','3','4'],
letters:['a','b','c','d']
});
@RSNara
RSNara / decorators.js
Last active July 7, 2019 00:24
An example of using decorators in ES5.
function memoize(object, name, descriptor) {
var fn = descriptor.value;
var memoized = function() {
memoized.cache = memoized.cache || {};
var key = JSON.stringify(arguments);
return memoized.cache[key] = memoized.cache[key]
? memoized.cache[key]
: fn.apply(this, arguments);
}
descriptor.value = memoized;
@devinrhode2
devinrhode2 / StrictjQuery.js.markdown
Last active November 27, 2018 17:12
warn on empty jquery selection badSelectorAction devinrhode2

warn on empty jquery selection

Graduated to github: https://github.com/devinrhode2/StrictjQuery.js

But for the simple version (quite possibly better): (wait no its broke use the one on GH)

Warns when you have an empty jQuery selection, unless you do $('foo', failsafe);

 $.badSelectorAction = function badSelectorActionFn( selector, context ) {
@Raynos
Raynos / jQuery.md
Created January 14, 2012 22:44
Why you don't need jQuery

Why the jQuery Abstraction isn't needed.

(One needs some form of browser normalization so that modern features works, no-one is doubting that).

Related: [jQuery library critique][2]

Abstractions that aren't needed

Selectors

@devinrhode2
devinrhode2 / typeCheck.js
Last active November 19, 2018 21:14
Working on a typeCheck function
function postTweet(tweet /*string*/, from /*string*/) {
typeCheck(arguments);
}
postTweet('string', 'asdf');
postTweet('string', 222); //TypeError! run in console to see a nice error message!
function typeCheck(a) {
var newArr = [].slice.call(a);
var types = [];
var f = a.callee.toString();
// It's composable
const compose = (a,b) => v => a(b(v))
const isValid = valid => fn => (...p) => valid(...p) && fn(...p)
const hasTwoParams = isValid((...params) => params.length === 2)
const firstParamIsArray = isValid(a => Array.isArray(a))
const hasTwoFirstArray = compose(hasTwoParams, firstParamIsArray)
const myValidatedFn = hasTwoFirstArray((a, b) => console.log('It worked', a, b))

An example of a simple form

Consider the following markup:

<form class="root" state:theme=dark state:compact>
  <div class="input-area">
    <label for="username" class="label">Username:</label>
    <input id="username" class="input" type="text">
  </div>

A small sampling of external projects initially built for Ember use but designed to be used standalone: