Skip to content

Instantly share code, notes, and snippets.

View adrianmcli's full-sized avatar
:shipit:
What's happening?

Adrian Li adrianmcli

:shipit:
What's happening?
View GitHub Profile
@adrianmcli
adrianmcli / layout.js
Created January 21, 2015 23:18
Apply Foundation topbar listener when a Meteor template is loaded
Template.layout.rendered = function(){
$(document).foundation('topbar', 'reflow'); // apply listener
}
@adrianmcli
adrianmcli / typeahead.css
Created January 22, 2015 00:07
Typeahead CSS Stylesheet
.typeahead,
.tt-query,
.tt-hint {
height: 30px;
padding: 8px 12px;
font-size: 24px;
line-height: 30px;
border: 2px solid #ccc;
-webkit-border-radius: 8px;
-moz-border-radius: 8px;

Keybase proof

I hereby claim:

  • I am adrianmc on github.
  • I am adrianmcli (https://keybase.io/adrianmcli) on keybase.
  • I have a public key ASBfyo8kunHt6ETIM0v8Gb6kjZETpAmPl-wmyqbMf68slgo

To claim this, I am signing this object:

scrollHandler = () => {
// Get the element
const ele = $(this._container);
// Compare these two metrics to get the distance scrolled from the bottom
const metricA = ele[0].scrollHeight - ele.scrollTop();
const metricB = ele.outerHeight();
const distanceFromBottom = metricA - metricB;
console.log(`distanceFromBottom: ${distanceFromBottom}`);
componentWillReceiveProps() {
// before the new props come in, save the current scroll position
const ele = $(this._container);
const distanceFromBottom = ele[0].scrollHeight - ele.scrollTop() - ele.outerHeight();
this.setState({
distanceFromBottom,
});
}
import React from 'react';
import Avatar from 'material-ui/lib/avatar';
import CloseIcon from 'material-ui/lib/svg-icons/navigation/cancel';
export default class Chip extends React.Component {
constructor(props) {
super(props);
this.state = {
const hasFocus = editorState.getSelection().getHasFocus();
if (hasFocus) {
// make an array of blocks we need to request locks for
// 1. which locks do we currently have?
const currentLocks = this.locks.map(lock => lock.blockKey);
// 2. which locks does the user want? (getSelectedBlocks)
const desiredLocks = getSelectedBlocks().map(block => block.getKey());
// 3. Make a list of all elements in the desiredLocks not contained in currentLocks
const requestLocks = R.difference(desiredLocks, currentLocks);
// 4. Make a list of all elements in currentLocks not contained in desiredLocks
// ### Note ###
//
// R.difference(currentKeys, newKeys) returns an
// array of keys that I have, but the server does
// not have.
//
// Note also that the injectChanges function does not have any changes
componentWillReceiveProps(nextProps) {
this.locks = nextProps.locks;
@adrianmcli
adrianmcli / fetchYTduration.js
Created April 14, 2016 05:27
A function that returns the duration of a YouTube video from the YouTube API V3.
function fetchDuration(videoId, apiKey) {
const baseURL = 'https://www.googleapis.com/youtube/v3/videos?';
const url = `${baseURL}id=${videoId}&key=${apiKey}&part=snippet,contentDetails`;
$.ajax({
async: false,
type: 'GET',
url: url,
success: function(data) {
const item = data.items[0];
const result = item ? item.contentDetails.duration : null;
import React from 'react';
import PureRenderMixin from 'react-addons-pure-render-mixin';
import {convertFromRaw, ContentState} from 'draft-js';
import {stateToHTML} from 'draft-js-export-html';
import linkifyIt from 'linkify-it';
import tlds from 'tlds';
const linkify = linkifyIt();
linkify.tlds(tlds);