render() { let { sortedPosts, sortedReviews } = this.props; let firstPosts = take(sortedPosts, 3); let firstReviews = take(sortedReviews, 4); let reviewRegex = /Book Review: (.+)/; let getReviewTitle = page => { let title = get(page, 'data.title') || page.path; let result = reviewRegex.exec(title); return result ? result[1] : title; }; return ( <div> <h1> The Latest Articles </h1> {firstPosts.map(post => ( <Section> <LinkBox page={post} titleFn={page => ( <span> <Bold>{get(page, 'data.title') || page.path}</Bold> </span> )} /> </Section> ))} <hr /> <div> <LayoutContainer> <Link className={`${leftSide} ${bottomLink}`} to={'/archive/'}> See More Articles » </Link> </LayoutContainer> </div> <Spacer /> <h1> The Latest Book Reviews </h1> <Section> <ReviewList pages={firstReviews} titleFn={page => ( <span> <Bold>{getReviewTitle(page)}</Bold> </span> )} /> </Section> <hr /> <div> <LayoutContainer> <Link className={`${leftSide} ${bottomLink}`} to={'/reviews-archive/'} > See More Reviews » </Link> </LayoutContainer> </div> </div> ); }
export const getSortedPosts = ( pages, count = Infinity, includeReviews = false ) => { let mostPopular = getSlugsForMostPopularPosts(pages, 10); let trending = getSlugsForTrendingPosts(pages, 10); const buildPage = rawPage => { let path = getSlug(rawPage); let data = rawPage.node.frontmatter; data.isTrending = includes(trending, path); data.isPopular = includes(mostPopular, path); return { data, path }; }; let pageTypes = ['post']; if (includeReviews) { pageTypes.push('review'); } return take( sortBy(pages, page => new Date(get(page, 'node.frontmatter.date'))) .reverse() .filter( page => includes(pageTypes, get(page, 'node.frontmatter.layout')) && !isDraft(page) && !get(page, 'node.frontmatter.dontfeature') ) .map(buildPage), count ); };
send = () => { const { quotation, socket, handleMessageSend, input, lastSentAt, user : sender, channel, slowMode, dispatch } = this.props; let body = take(trim(input), bodyLimit).join(''); if (body) { if (body.length === bodyLimit) body += ' ...'; const {owner, moderators} = channel; if (!equals(sender, owner) && includes(moderators, sender._id)) { if (lastSentAt && slowMode.enabled) { const lastSentAtWithSlowMode = moment(lastSentAt).add(slowMode.seconds, 'seconds'); if (lastSentAtWithSlowMode.isAfter(Date.now())) { return dispatch(addSpeakingTooFastMessage()); } } } this.addHistoryEntry(body); dispatch(clearInput()); const message = {sender, body, quotation}; dispatch(addMessage(message)); const emitMessageSend = messageSend(socket); emitMessageSend(message) .then(_message => dispatch(replaceMessage(message, _message))) .catch(() => dispatch(ackMessageSentFail(message))); dispatch(setLastSentAt(Date.now())); handleMessageSend(body); } };
function getTopArtists(artists) { //Return the artists with the 3 highest number of occurrence, reject any not > 0 return take(Object.keys(artists).filter( (artist) => artists[artist] > 0 ).sort(function(a,b) { return artists[b] - artists[a]; }), 3); }
export const getSlugsForMostPopularPosts = (pages, count) => take( sortBy(pages, getPageViews) .reverse() .filter(isEligiblePage) .map(getSlug), count );
export const getWeeklyLinks = (pages, count = Infinity) => take( sortBy(pages, page => get(page, 'node.frontmatter.date')) .reverse() .filter(page => get(page, 'node.frontmatter.layout') === 'weekly-links') .map(p => ({ data: p.node.frontmatter, path: p.node.fields.slug })), count );
module.exports = function postSingle(data) { const rule = Event.parseRRule(data).parsedRRule; const until = rule.options.until || moment.utc(rule.options.dtstart).add(1, 'week').toDate(); const dates = rule.between(moment.utc().toDate(), until, true); extend(data, { start_time: take(dates, 3), }); };
export const getSortedReviews = (pages, count = Infinity) => take( sortBy(pages, page => get(page, 'node.frontmatter.date')) .reverse() .filter( page => get(page, 'node.frontmatter.layout') === 'review' && !isDraft(page) ) .map(p => ({ data: p.node.frontmatter, path: p.node.fields.slug })), count );
export function filterByQualification( list: Course[], qualification: Qualification, { distinct = false, fullList, counter, }: {distinct: boolean, fullList?: Course[], counter?: Counter} = {}, ) { assertKeys(qualification, '$key', '$operator', '$value') const value = qualification.$value if (typeof value === 'object' && !Array.isArray(value)) { if (value.$type === 'boolean') { if (!('$or' in value) && !('$and' in value)) { throw new TypeError( `filterByQualification: neither $or nor $and were present in ${JSON.stringify( value, )}`, ) } } else if (value.$type === 'function') { applyQualifictionFunction({value, fullList, list}) } else { throw new TypeError( `filterByQualification: ${ value.$type } is not a valid type for a query.`, ) } } let filtered = filter(list, course => compareCourseToQualification(course, qualification), ) // If we have a limit on the number of courses, then only return the // number that we're allowed to accept. if ( counter && (counter.$operator === '$lte' || counter.$operator === '$eq') ) { filtered = take(filtered, counter.$num) } if (distinct) { filtered = uniqBy(filtered, simplifyCourse) } return filtered }
function addOldSearches(oldSearches, input) { const matchingOldSearches = filterMatchingToInput(oldSearches, input, ['address', 'locationName']); return Promise.resolve(take(matchingOldSearches, 10).map(item => ({ type: 'OldSearch', properties: { label: item.address, layer: 'oldSearch', mode: item.properties ? item.properties.mode : null }, geometry: item.geometry, }) )); }
export const getSlugsForTrendingPosts = (pages, count) => { let eligiblePages = pages .filter(isEligiblePage) // prevent cases where we're just moving up a deep pit at the bottom .filter(page => getRecentPageViews(page) > 30) // don't include things posted in the last 30 days .filter(page => getRecentPageViews(page) !== getPageViews(page)); let rankByPopular = sortBy(pages, getPageViews); let rankByRecentlyPopular = sortBy(eligiblePages, getRecentPageViews); let rankByTrending = sortBy(eligiblePages, page => { let getRankInList = list => findIndex(list, popPage => getSlug(popPage) === getSlug(page)); return getRankInList(rankByPopular) - getRankInList(rankByRecentlyPopular); }); return take(rankByTrending.map(getSlug), count); };
readyToExpand(ops, index = ops.length - 1) { const cursorToLook = [ `${this.cursor}expand.width`, `${this.cursor}expand.distr`, `${this.cursor}expand.angle`, `${this.cursor}x`, `${this.cursor}y`, ]; const done = _take(ops, index + 1); // if all the op are done we should have a length 5 short because // we removed the 5 necessary cursor return ( _difference(done, cursorToLook).length === done.length - cursorToLook.length ); }
isReadyForHandles(ops, index = ops.length - 1) { const cursorToLook = _flatMap(this.nodes, node => [ `${node.cursor}typeOut`, `${node.cursor}typeIn`, `${node.cursor}dirIn`, `${node.cursor}dirOut`, `${node.cursor}tensionIn`, `${node.cursor}tensionOut`, `${node.cursor}x`, `${node.cursor}y`, ]); const done = _take(ops, index + 1); return ( _difference(done, cursorToLook).length === done.length - cursorToLook.length ); }
return paths.reduce((result, path) => { reducedPaths.push(path); if (!isNaN(path)) { // collection if (!isCollection(result)) { const collectionPath = take(reducedPaths, reducedPaths.length - 1); throw new MethodError(`Path ${JSON.stringify(collectionPath)} is not inside a collection`); } return result.at(path); } // model if (!(path in result)) { throw new MethodError(`Path ${JSON.stringify(reducedPaths)} does not exist`); } return result[path]; }, this);
isReadyForHandles(ops, index = ops.length - 1) { const cursorToLook = _flatMap(this.nodes, (node) => { if (node.expanding) { return [ `${node.cursor}expand.width`, `${node.cursor}expand.distr`, `${node.cursor}expand.angle`, `${node.cursor}typeOut`, `${node.cursor}typeIn`, `${node.cursor}dirIn`, `${node.cursor}dirOut`, `${node.cursor}tensionIn`, `${node.cursor}tensionOut`, `${node.cursor}x`, `${node.cursor}y`, ]; } return [ `${node.cursor}expandedTo.0.x`, `${node.cursor}expandedTo.0.y`, `${node.cursor}expandedTo.1.x`, `${node.cursor}expandedTo.1.y`, `${node.cursor}dirIn`, `${node.cursor}dirOut`, `${node.cursor}tensionIn`, `${node.cursor}tensionOut`, ]; }); const done = _take(ops, index + 1); return ( _difference(done, cursorToLook).length === done.length - cursorToLook.length ); }
.then(suggestions => take(filterMatchingToInput(suggestions, input, ['properties.label', 'properties.code']), 20))
authButtonBySignedInStatus } from '../helpers' import styles from '../components/settings/settings-styles.scss' const P1controls = '1, 2, 3' const P2controls = '8, 9, 0' const controls = [P1controls, P2controls] const settingsContainer = { view(vnode: Object) { return m(settingsComponent, { ...vnode.attrs, playerControlsInfo: take(controls.map((playerInfo, index) => { return m('ul', [ m('li', `P${index + 1}`), m('li', controls[index]) ]) }), isMobile(vnode.attrs.state) ? 1 : 2), settingsComponentAttrs: { class: styles.settings }, checkboxAttrs: { checked: isSoundOn(vnode.attrs.state) }, soundsLabel: `Sounds Settings Checkbox, ${isSoundOn(vnode.attrs.state) ? 'checked' : 'unchecked'}`, checkmarkAttrs: { onclick: () => vnode.attrs.dispatch(toggleSounds(isSoundOn(vnode.attrs.state))), onkeyup: (e) => { if (e.keyCode === 13 || e.keyCode === 32) { vnode.attrs.dispatch(toggleSounds(isSoundOn(vnode.attrs.state))) }
getDataForRender: function getDataForRender(data, cols, pageList) { var _this = this; var that = this; // get the correct page size if (this.state.sortColumn !== "") { var column = this.state.sortColumn; var sortColumn = _filter(this.props.columnMetadata, { columnName: column }); var customCompareFn; var multiSort = { columns: [], orders: [] }; if (sortColumn.length > 0) { customCompareFn = sortColumn[0].hasOwnProperty("customCompareFn") && sortColumn[0]["customCompareFn"]; if (sortColumn[0]["multiSort"]) { multiSort = sortColumn[0]["multiSort"]; } } if (this.state.sortDirection) { if (typeof customCompareFn === 'function') { if (customCompareFn.length === 2) { data = data.sort(function (a, b) { return customCompareFn(_get(a, column), _get(b, column)); }); if (this.state.sortDirection === 'desc') { data.reverse(); } } else if (customCompareFn.length === 1) { data = _orderBy(data, function (item) { return customCompareFn(_get(item, column)); }, [this.state.sortDirection]); } } else { var iteratees = [_property(column)]; var orders = [this.state.sortDirection]; multiSort.columns.forEach(function (col, i) { iteratees.push(_property(col)); if (multiSort.orders[i] === 'asc' || multiSort.orders[i] === 'desc') { orders.push(multiSort.orders[i]); } else { orders.push(_this.state.sortDirection); } }); data = _orderBy(data, iteratees, orders); } } } var currentPage = this.getCurrentPage(); if (!this.props.useExternal && pageList && this.state.resultsPerPage * (currentPage + 1) <= this.state.resultsPerPage * this.state.maxPage && currentPage >= 0) { if (this.isInfiniteScrollEnabled()) { // If we're doing infinite scroll, grab all results up to the current page. data = first(data, (currentPage + 1) * this.state.resultsPerPage); } else { //the 'rest' is grabbing the whole array from index on and the 'initial' is getting the first n results var rest = drop(data, currentPage * this.state.resultsPerPage); data = (dropRight || initial)(rest, rest.length - this.state.resultsPerPage); } } var meta = this.columnSettings.getMetadataColumns; var transformedData = []; for (var i = 0; i < data.length; i++) { var mappedData = data[i]; if (typeof mappedData[that.props.childrenColumnName] !== "undefined" && mappedData[that.props.childrenColumnName].length > 0) { //internally we're going to use children instead of whatever it is so we don't have to pass the custom name around mappedData["children"] = that.getDataForRender(mappedData[that.props.childrenColumnName], cols, false); if (that.props.childrenColumnName !== "children") { delete mappedData[that.props.childrenColumnName]; } } transformedData.push(mappedData); } return transformedData; },
export function menuButtonsByRoute(state: Object, dispatch: Object, route: string) { return take(map(getAttribuesForMenuButtonsByRoute(dispatch, route), (buttonComponentAttributes: Object) => { return m(buttonComponent, buttonComponentAttributes) }), isMobile(state) ? 1 : 2 ) }
import Chart from 'chart.js'; import uniq from 'lodash/uniq'; import take from 'lodash/take'; import groupBy from 'lodash/groupBy'; import randomColor from 'randomcolor'; var Stats = require('../../components/stats/Stats'); var getLatestsStats = require('../../helpers/api').getLatestsStats; var chartOptions = require('./chartOptions/chartOptions'); const BUSES = require('../../data/busData').BUSES; const OUTPUT_DATE_FORMAT = 'DD/MM/YYYY HH:mm'; const SINGLE_BUS_STATS = ['meanwaitingtimebybus', 'maxwaitingtimebybus', 'minwaitingtimebybus']; const MULTI_BUS_STATS = ['meanwaitingtimebybus']; var defaultBusDisplayed = take(BUSES, 15); var StatsContainer = React.createClass({ getInitialState: function () { return { selectedBus: '', callbackFunction: this.callbackSelect } }, callbackSelect: function (e) { var busNumber = e.target.value; var typeOfStats = busNumber ? SINGLE_BUS_STATS : MULTI_BUS_STATS; var busesToFetch = busNumber ? [busNumber] : defaultBusDisplayed; getLatestsStats(typeOfStats, busesToFetch, busNumber) .then(function (statsData) { var __ret = this.generateLabelsAndDatasets(statsData, busNumber);
export const getPopularPosts = (pages, count = Infinity) => take(sortBy(pages, p => +p.data.last30pageViews).reverse(), count);
export const getTopicLinks = (topics, count = Infinity) => take( topics.map(topic => ({ data: { title: topic }, path: `topics/${topic}` })), count );