Skip to content

Instantly share code, notes, and snippets.

@sqrtsanta
sqrtsanta / image_manager_modal.jsx
Created February 27, 2017 13:14
React component: dropzone, check - paste/delete pictures from editor
import React, { PropTypes, Component } from 'react';
import { connect } from 'react-redux';
import Dropzone from 'react-dropzone';
import pictureable from 'shared/pictures/components/pictureable.jsx';
const _getPictureIds = (pictureCheckStatuses) => R.filter(key =>
pictureCheckStatuses[key], R.keys(pictureCheckStatuses)
);
@sqrtsanta
sqrtsanta / scraper.js
Created February 27, 2017 13:03
Scraper based on Horseman, written in functional way with Ramda/Folktale.Task
/* global $ document */
const Horseman = require('node-horseman');
const cheerio = require('cheerio');
const R = require('ramda');
const phantomjs = require('phantomjs-prebuilt');
const { Task, mapf } = require('../utils/f.js');
// fetch :: string -> Task Error HTML
@sqrtsanta
sqrtsanta / reverse_pagination.rb
Last active August 29, 2015 14:25
Reverse pagination
class ReversePagination
attr_reader :page, :per_page, :total_count, :total_pages, :records
def initialize(scope, page)
initialize_params(scope.klass, page)
@records = scope.limit(limit).offset(offset).order(:created_at).reverse
end
def initialize_params(klass, page)
@sqrtsanta
sqrtsanta / activity_finder.rb
Created April 22, 2015 11:33
Preload associations of polymorphic objects
class ActivityFinder
attr_reader :activities, :user
def initialize(user)
@user = user
@activities = Activity.all.where(:user_id => user_ids).
with_subject.with_user.desc
activities.group_by(&:subject_type).each do |name, group|