Skip to content

Instantly share code, notes, and snippets.

@mnicole
mnicole / gist:2cb3686e101d7827273eb7479ff7cc05
Created October 18, 2017 04:36
function to check for the position of 2 numbers that equal a certain sum
/**
* Function to check for the position of 2 numbers that equal a certain sum. Only one pair per array.
* @param {number[]} nums
* @param {number} target
* @return {number[]}
*/
const twoSum = function(nums, target) {
let checked = {},
found;
nums.forEach((n, index) => {
{
"presets": [
"es2015", // whichever presets your projects use should match here
"stage-0",
"react"
],
"plugins": [
"transform-runtime", // for polyfills
"transform-react-remove-prop-types" // we use this to remove the propTypes
]
@mnicole
mnicole / gist:882f1a99cbfeabced8c1f985ab32d758
Created July 28, 2017 04:33
component lib package.json
“module”: “dist-es6/index”,
“prebuild”: “rimraf dist dist-es6”, // removes the /dist-es6 folder before building
“build”: “babel components — out-dir dist-es6 — source-maps inline”, // builds everything in /components/index.js to /dist-es6
“postinstall”: “postinstall-build — only-as-dependency dist”
import React, { PropTypes } from ‘react’;
const Badge = ({ text, context, className, style, ...otherProps }) => {
const classes = `${context} ${className}`;
return (
<span className={ classes } style={ style } { ...otherProps }>{ text }</span>
);
};
Badge.defaultProps = {
text: ‘’,
context: ‘default’,
@mnicole
mnicole / bookmarkletautofillformurl.md
Last active August 29, 2015 13:56
Bookmarklet to autofill forms (URL and TITLE of page you're on when you click the bookmarklet)

BOOKMARKLETS TO AUTO FILL FORMS

I wanted to create a bookmarklet that would find the user's URL and title of the page they were on when they clicked the bookmarklet, go to my website's create new link form, and autofill the fields with that information. While researching, I found that nothing I could find fit this description, so I cobbled the code together from a few different sources.

FIRST, create a link to the bookmarklet, which you will tell people to drag to their browser bookmark bar. This will also take in the website and decode it so it shows up as http:// in the form. Make sure you match the name of your fields in your form that you want to be autofilled.

<a href="javascript:(function(){var newURI='YOUR_URL_TO_YOUR_FORM_PAGE?NAME_OF_URL_FIELD='+encodeURIComponent(decodeURIComponent(window.location.href))+'&NAME_OF_TITLE_FIELD='+encodeURIComponent(document.title.replace('%20',' ')); window.location.href=newURI;})();">TEXT THAT THE BOOKMARKLET WILL SAY WHEN YOU DRAG IT TO YOUR BOOKMAR