Skip to content

Instantly share code, notes, and snippets.

require 'rails_helper'
RSpec.describe TodosController, :type => :controller do
describe "GET #index" do
#describe "POST #create" do
#describe "GET #show" do
#describe "PATCH #update" do (or PUT #update)
#describe "DELETE #destroy" do
#describe "GET #new" do
@yesvods
yesvods / gist:51af798dd1e7058625f4
Created August 15, 2015 11:13
Merge Arrays in one with ES6 Array spread
const arr1 = [1,2,3]
const arr2 = [4,5,6]
const arr3 = [...arr1, ...arr2] //arr3 ==> [1,2,3,4,5,6]
@andrewheins
andrewheins / qs_to_hash.rb
Created December 7, 2011 17:29
QueryString to Hash in Ruby
# Today's little useless tidbit converts a url's query string into a hash
# set of k/v pairs in a way that merges duplicates and massages empty
# querystring values
def qs_to_hash(querystring)
keyvals = query.split('&').inject({}) do |result, q|
k,v = q.split('=')
if !v.nil?
result.merge({k => v})
elsif !result.key?(k)
@solnic
solnic / am_dry_validation_1.rb
Last active May 21, 2022 13:42
dry-validation vs activemodel
require 'benchmark/ips'
require 'active_model'
require 'virtus'
require 'dry-validation'
require 'dry/validation/schema/form'
class User
include ActiveModel::Validations
include Virtus.model
@armw4
armw4 / redux-is-smarter-than-you-think.md
Last active June 19, 2021 20:10
Optimizing your react components via redux....shouldComponentUpdate for free and more...

The Beginning

Yes...it's true...redux is smart....smarter than you even know. It really does want to help you. It strives to be sane and easy to reason about. With that being said, redux gives you optimizations for free that you probably were completely unaware of.

connect()

connect is the most important thing in redux land IMO. This is where you tie the knot between redux and your underlying components. You usually take state and propogate it down your component hiearchy in the form of props. From there, presentational

@chantastic
chantastic / AudioFileStepSelector.coffee
Created January 18, 2015 19:20
My First React Component
# My First React Component
# Added to this Gist for posterity.
# Extracted from https://github.com/ministrycentered/transposr/commit/fa616871914ac16b72d0d1b035a08e01e337bd07
# January 08, 2014
{ div, input } = React.DOM
AudioFileStepSelector = React.createClass
getInitialState: ->
halfSteps: 2
@dariocravero
dariocravero / Gemfile
Created September 5, 2012 18:48
Minimal sinatra app with puma's config.
source "https://rubygems.org"
gem 'puma'
gem 'sinatra'
@davemo
davemo / app.coffee
Last active March 25, 2020 13:25
Got a .coffee file with JSX? Here's how you can transpile to .js with Reacts JSX parsed.
`/** @jsx React.DOM */`
converter = new Showdown.converter
Comment = React.createClass
render: ->
rawMarkup = converter.makeHtml @props.children.toString()
`<div className="comment">
<h2 className="comment">{this.props.author}</h2>
<span dangerouslySetInnerHTML={{__html: rawMarkup}} />
@jrus
jrus / gist:2145082
Created March 21, 2012 06:08
sort a javascript array using a decorate-sort-undecorate pattern; especially useful if the sort comparison is expensive to compute
# Accepts a list and a key function to apply to each item,
# and then uses a decorate-sort-undecorate pattern to actually
# do the sorting. Returns a new list. Keeps track of the index
# to make sure the sort is stable.
sort_by = (list, key) ->
cmp = ({key: k_a, index: i_a}, {key: k_b, index: i_b}) ->
if k_a == k_b then i_a - i_b else if k_a < k_b then -1 else 1
decorated = ({item, index, key: key item} for item, index in list)
item for {item} in decorated.sort cmp
@c80609a
c80609a / task.md
Last active January 22, 2020 10:46
Rails Junior+ Test

Задача

Необходимо посчитать количество перепостов новости (а-ля в соцсети).

Прикладная структура новости:

  1. Заголовок
  2. Тело новости
  3. Автор
  4. Время создания