This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Add IE11 support | |
const crypto = window.crypto || window.msCrypto | |
const generatePassword = (length = 10) => { | |
const buffer = new Uint8Array(12) | |
crypto.getRandomValues(buffer) | |
return btoa(String.fromCharCode.apply(null, buffer)).substr(0, length) | |
} | |
export default generatePassword |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const flattenArray = (arr) => arr.reduce((result, value) => result.concat(value), []) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Issue: `react-select` `onChange` method doesn't return a proper event | |
// | |
// Solution used: | |
// | |
// The main idea is to have an hidden `select` that will trigger a real event | |
// When `ReactSelect` triggers it's `onChange` we set the state with the `selectedOptions` | |
// these `selectedOptions` will be what populate our hidden select. | |
// Using the callback from `setState` (it ensures that the new values are already into our hidden select), | |
// we then create a change event and dispatch it into our hidden select. | |
// This will cause the `onChange` from this select to be triggered with a proper `event`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// From: https://stackoverflow.com/questions/50963215/can-we-specify-a-generic-getter-on-an-object-in-javascript | |
// Allows you to access nested property (1 level) without the need to to safety check | |
const properties = { email: { title: "Email", value: "[email protected]" } } | |
const proxy = new Proxy(properties, { | |
get: (target, prop) => (prop in target) ? target[prop] : {}, | |
}) | |
// or |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Utility function to get access nested object properties securely | |
// | |
// Usage: | |
// const invoiceName = get(account, "user.invoiceAddress.name") | |
// | |
// Instead of: | |
// const invoiceName = (account && account.user && account.user.invoiceAddress && account.user.invoiceAddress.name) || null | |
// https://stackoverflow.com/a/23809123/1410020 | |
const get = (obj, key) => |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Inspired by https://github.com/MicheleBertoli/react-automata/blob/d9128bebe30df83c41bff4ed806549241fcf3b04/src/withStatechart.js | |
// Example of how to use a custom life-cycle method for a wrapped component | |
import React from 'react' | |
const isStateless = Component => | |
!(Component.prototype && Component.prototype.isReactComponent) | |
const withSomething = Component => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Improvement proposal | |
$IncludedByStateFilter.$inject = ['$state']; | |
function $IncludedByStateFilter($state) { | |
var includesFilter = function (state, params, options) { | |
return $state.includes(state, params, options); | |
}; | |
includesFilter.$stateful = true; | |
return includesFilter; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* BjyAuthorize Module (https://github.com/bjyoungblood/BjyAuthorize) | |
* | |
* @link https://github.com/bjyoungblood/BjyAuthorize for the canonical source repository | |
* @license http://framework.zend.com/license/new-bsd New BSD License | |
*/ | |
namespace BjyAuthorize\Provider\Identity; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* hasNestedProperties check if an object has the nested | |
* properties passed in params | |
* | |
* @param {Object} obj object we want to test | |
* @param {String} properties nested property we want | |
* @return {Boolean} either the object has these | |
* nested properties or not | |
*/ | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Save your We Are Hunted playlist | |
// Download all your We Are Hunted tracks infos in a JSON file | |
// by Cyril F (github.com/cyrilf) | |
// Instructions | |
// | |
// Go to wearehunted.com | |
// Change the USERNAME below by your username or email. | |
// Copy and paste the following code into your javascript | |
// console. |
NewerOlder