Skip to content

Instantly share code, notes, and snippets.

View zachlysobey's full-sized avatar

Zachary Lysobey zachlysobey

View GitHub Profile
@zachlysobey
zachlysobey / obj-shorthand.md
Last active August 7, 2023 01:39
Thoguhts on JS object shorthand vs longhand

I appreciate the brevity of the shorthand 🤷

const foo = () => ({ a: 1, b: 2 });

compare that to:

const foo = () => {
@zachlysobey
zachlysobey / flatten-array.js
Created October 15, 2019 00:31
JS function to flatten an arbitrarily nested array
// creates a new array with all sub-array elements concatenated into it recursively
// equivalent to array.prototype.flat with Infinity passed for depth
const flattenArray = (arr) =>
arr.reduce(
(result, value) => result.concat(
Array.isArray(value)
? flattenArray(value)
: value
),
[],
@zachlysobey
zachlysobey / keybase.md
Last active August 5, 2019 14:48
keybase.md

Keybase proof

I hereby claim:

  * I am zachlysobey on github.   * I am zlysobey (https://keybase.io/zlysobey) on keybase.   * I have a public key ASBv6iUdNuzND9RnzxBV99QvwKlaMOM-ywxoPJ7YFV1eHgo

To claim this, I am signing this object:

@zachlysobey
zachlysobey / abi-helper.js
Last active January 22, 2019 18:59
Solidity Testing Patterns
class AbiHelper {
constructor (Contract) {
this._abi = Contract.toJSON().abi
}
abi() {
return this._abi
}
publicMethodNames() {
@zachlysobey
zachlysobey / partition.ts
Last active April 6, 2023 16:33
TypeScript array `partition` utility
/**
* Takes a predicate and a list of values and returns a a tuple (2-item array),
* with each item containing the subset of the list that matches the predicate
* and the complement of the predicate respectively
*
* @sig (T -> Boolean, T[]) -> [T[], T[]]
*
* @param {Function} predicate A predicate to determine which side the element belongs to.
* @param {Array} arr The list to partition
*
@zachlysobey
zachlysobey / angular-resources.md
Last active November 19, 2015 15:59
Angular Resources & Best Practices

#Angular Resources & Best Practices

John Papa's Styleguide - Required reading. We try to follow this blindly.

Tips

  • The above styleguide has snippets for different editors
  • Organize directories by feature, not type
  • One Injectable "thing" per file.
  • Thin controllers. Think of them as the View Model (vm), not a MVC controller.
  • Avoid the link function and doing things with element (this isn't jQuery)
@zachlysobey
zachlysobey / uibModalExample.js
Last active May 29, 2018 12:07
UIB Modal Example
(function() {
'use strict';
angular
.module('dkProject.quota')
.factory('sourceListModal', sourceListModal);
const modalTemplate = `
<div class="source-list-modal">

Whats the best, most idiomatic way to make a self-closable directive?

Pass in ng-if?

<toggleBox ng-if="someCondition"></toggleBox>
angular.module('myModule').directive('toggleBox', function() {
angular.module('my.Module').directive('dateControl', dateControl);
function dateControl() {
return {
bindToController: true,
controller: Controller,
controllerAs: 'vm',
scope: {
isDataReady: '=',
dateMilliseconds: '='
@zachlysobey
zachlysobey / alternative-to-vm-equals-this.md
Last active October 16, 2015 13:53
Concept for angular "Vm" Injectable to replace `vm = this`

The standard approach

function MyController($scope, Vm) {
  const vm = this;
  vm.myData = 'foo';
  vm.myData; // 'foo'
  
  const stopWatching = $scope.$watch('controllerAsName.myData', (newVal, oldVal) => {
 doSomething(newVal, oldVal);