This file contains hidden or 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 User < ActiveRecord::Base | |
def recent_activities(limit) | |
c_stream = comments.order_by(:created_at).to_enum :find_each | |
i_stream = items.comments.order_by(:created_at).to_enum :find_each | |
b_stream = bids.order_by(:created_at).to_enum :find_each | |
ActivityFeedAggregator.new([c_stream, i_stream, b_stream]).next_activities(limit) | |
end | |
end |
This file contains hidden or 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 ActivityAggregator | |
def initialize(streams) | |
@streams = streams | |
end | |
def next_activities(limit) | |
activities = [] | |
while (activities.size < limit) && more_activites? do | |
activities << next_activity | |
end | |
activities |
This file contains hidden or 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 User < ActiveRecord::Base | |
def recent_activities(limit) | |
c_stream = comments.order_by(:created_at).to_enum :find_each | |
i_stream = items.comments.order_by(:created_at).to_enum :find_each | |
b_stream = bids.order_by(:created_at).to_enum :find_each | |
end | |
end |
This file contains hidden or 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 User < ActiveRecord::Base | |
def recent_activities(limit) | |
[comments, items.map(&:comments), bids]. | |
flatten. | |
sort_by(&:created_at). | |
first(limit) | |
end | |
end |
This file contains hidden or 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
val n = wordsList.length | |
val wLength = List.newBuilder[Int] | |
val wCaps = List.newBuilder[Boolean] | |
for( word <- wordsList ) { | |
wLength += word.length | |
wCaps += isCapitalized(word) | |
} | |
( wLength.result(), wCaps.result() ) |
This file contains hidden or 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
val wLength = wordsIndexedSeq.map( _.length ) | |
val wCaps = wordsIndexedSeq.map( isCapitalized ) | |
(wLength, wCaps) |
This file contains hidden or 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
val UTF8 = "UTF-8" | |
val ISO8859 = "ISO-8859–1" | |
val REPLACEMENT_CHAR = '\uFFFD' | |
def bytesToString(bytes: Array[Byte], encoding: String) = { | |
val upper = encoding.toUpperCase | |
val firstEncoding = if (ISO8859 == upper) ISO8859 else UTF8 | |
val firstDecoded = new String(bytes, firstEncoding) | |
if (!firstDecoded.contains(REPLECEMENT_CHAR)) { | |
firstDecoded |
This file contains hidden or 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 io.Codec | |
import java.nio.ByteBuffer | |
val UTF8 = “UTF-8” | |
val ISO8859 = “ISO-8859–1” | |
val REPLACEMENT_CHAR = ‘\uFFFD’ | |
def bytesToString(bytes: Array[Byte], encoding: String) = { | |
val upper = encoding.toUpperCase | |
val codec = if (ISO8859 == upper) Codec.ISO8859 else Codec.UTF8 |
This file contains hidden or 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
<amq:connectionFactory id="connectionFactory" brokerURL="${jms.url}"/> | |
<bean id="singleConnectionFactory" p:targetConnectionFactory-ref="connectionFactory" p:reconnectOnException="true"/> | |
<bean id="cachingConnectionFactory" p:targetConnectionFactory-ref="singleConnectionFactory" p:sessionCacheSize="100"/> | |
<bean id="jmsTemplate" p:connectionFactory-ref="cachingConnectionFactory"/> | |
<jms:listener-container connection-factory="singleConnectionFactory"> | |
<jms:listener id="QueueHandler" destination="Queue" ref="queueHandler"/> | |
</jms:listener-container> |
This file contains hidden or 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
final Collection<String> parts = buildQueryParts( dbObj ); | |
if ( parts.isEmpty() ) { return ImmutableList.of(); } | |
final String query = "SELECT " + columnNames + " FROM " + dbObj.getTableName() + " WHERE " + join( parts, " AND " ); | |
return result = simpleJdbcTemplate.query( query, new BeanPropertyRowMapper<DbObj>( dbObj.getClass() ), new BeanPropertySqlParameterSource( dbObj ) ); | |
private static final Collection<String> buildQueryParts( final LocaDbObj dbObj ) { | |
return transform( filter( dbObj.getFieldNames(), new HasValue( dbObj.toMap() ) ), new BuildPart( dbObj ) ); | |
} | |
private static final class HasValue implements Predicate<String> { | |
private final Map<String, Object> map; | |
public HasValue( final Map<String, Object> map ) { |
NewerOlder