This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# rsync files | |
rsync -rv --include '*/' --include '*.jpg' --exclude '*' --prune-empty-dirs [email protected]:~/videos/ ~/ | |
rsync -rv --prune-empty-dirs [email protected]:~/images/ ~/ | |
# change backup | |
mix ecto.drop ; mix ecto.create ; psql my_reelty_dev < ~/development/my_reelty/production/backup.sql | |
# Remove all reviews except last 200 | |
required_ids = Ecto.Query.from(r in Review, limit: 200, order_by: [desc: :id], select: [:id], where: is_nil(r.deleted_at)) |> Repo.all |> Enum.map(fn(r) -> r.id end) | |
Ecto.Query.from(r in Review, where: not(r.id in ^required_ids), order_by: [asc: :id]) |> Repo.update_all(set: [deleted_at: Ecto.DateTime.utc]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DownloadController < ActionController::API | |
def bill | |
user_id = DownloadToken.verify(params[:token]) | |
return head :unprocessable_entity if user_id.nil? | |
user = User.find_by(id: user_id) | |
return head :not_found if user.nil? | |
member = Member.find_by(id: params[:id]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Movie < ActiveRecord::Base | |
has_many :sessions | |
def self.next_week_list | |
next_week_beginning = Date.today.at_beginning_of_week.next_week | |
next_week_end = Date.today.at_end_of_week.next_week | |
joins(:session).where("sessions.beginning_of > ? and sessions.beginning_of < ?", next_week_beginning, next_week_end)9 | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react' | |
import PropTypes from 'react-proptypes' | |
class MyComponent extends React.Component { | |
// render logic here | |
} | |
MyComponent.propTypes = { | |
collectorGroup: PropTypes.shape({ | |
target_count: PropTypes.number.isRequired, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react' | |
INNER_CIRCLE_TARGETS_COUNT = 10 | |
class MyComponent extends React.Component { | |
render() { | |
// A big function with a complex logic | |
const { collectorGroup } = this.props | |
const collectorGroupHasFewCircles = (collectorGroup.targets_count > INNER_CIRCLE_TARGETS_COUNT) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
o = { a: 'b' } | |
o.fetch(:a) # => returns 'b' | |
o.fetch(:nonexistant) # => throws prog.rb:2:in `fetch': key not found (KeyError) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import zealit from 'zealit' | |
// A reminder - collectorGroup looks like: | |
// const collectorGroup = { target_count: 10 } | |
const fetchedObject = zealit(collectorGroup) | |
fetchedObject.target_count // returns 10 | |
fetchedObject.targets_count // throws a ReferenceError |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const objectFetch = (object, propertyName) => { | |
if (object.hasOwnProperty(propertyName)) { | |
return object[propertyName] | |
} | |
throw new ReferenceError(`key not found: ${propertyName}`) | |
} | |
const collectorGroup = { target_count: 10 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The only significant difference between TS and JavaScript is interface. | |
// Interface declarates that object passed as `obj` should be an object actually | |
interface PassedObject { | |
readonly [key: string]: any; | |
} | |
// Same logic as in our ES6 code | |
const objectFetch = (obj: PassedObject, property: string): any => { | |
// tslint:disable-next-line:no-if-statement | |
if (obj.hasOwnProperty(property)) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// tslint:disable:no-expression-statement | |
import { test } from 'ava'; | |
import objectFetch from './index'; | |
const object = { a: 'b' }; | |
test('returns key if it exists', t => { | |
t.is(objectFetch(object, 'a'), 'b'); | |
}); |
OlderNewer