Skip to content

Instantly share code, notes, and snippets.

View meltingice's full-sized avatar

Ryan LeFevre meltingice

View GitHub Profile
@meltingice
meltingice / grail14.js
Last active August 9, 2023 16:07
Grail #14
// Utility function for shuffling an array
const shuffle = a => a.sort(() => Math.random() - 0.5)
// The current day of the week (0 = Sunday, 1 = Monday, etc.)
const cId = new Date().getDay()
// The set of symbols used for each day of the week
const cs = [
['🔳', '🟦', '🔲', '🟥'], // Sunday
[2018-03-01 11:17:26.549751]: While bootstrappping, fork between our block: D2AFFA6D4205258374F7B38CDAE9FAFA76D3905789818F339676A099D3C9817A and block 1A0E6679E59783E35295DEE23D0CB253F3D52F7FDFE7C6C4A7A7245C32929801 both with root 8F1FD01CD1407521F24AC315681DA5826D4D931A4EDA58E74F444B413AF170B8
[2018-03-01 11:17:58.762764]: While bootstrappping, fork between our block: 0978DE900C7B354122235C8C20BB4C0F9D8CE065B1EBBBC7AFD94FBD468E81BE and block F6B57FB5F1EF5D2919FB31454136D0A0EA7D000A73BEC603B8ECDBD36ADAB33B both with root EDE639C142DD851E4D162791DC7D803BDEA13A2EF53D7ED166DCD81DB4CD4239
[2018-03-01 11:18:00.986386]: While bootstrappping, fork between our block: 41C73322F0BF8513A16EAF75AE15CE7DB6F79CF98982C2C389EF1E1E2B03B652 and block CEC34C0D90E9AA43A833AB03103819970B2757B0DC7DE2A09206EBF1EB438E64 both with root 9B61AB4AAA741E9D395BB840951D81B5D1EB7B221FA857463DDB0D68A835F066
[2018-03-01 11:18:04.946908]: While bootstrappping, fork between our block: 7B9395B1144059204095138B9335CE192B1BBB14223734AB4FD284DE9D08
// In the TypeTool, the StyleRun defines all of the different styles
// that are applied to a text layer. Each style is defined in the RunArray,
// and the character indices for each style is defined in the RunLengthArray,
// i.e. the first style exists for 7 characters, the 2nd for 7 characters,
// and the third for 10 characters.
> typeTool.engineData.EngineDict.StyleRun
{ DefaultRunData: { StyleSheet: { StyleSheetData: {} } },
RunArray:
[ { StyleSheet: [Object] },
{ StyleSheet: [Object] },
@meltingice
meltingice / README.md
Created June 29, 2017 19:02
AWS Lambda Deploy Script

Project Structure

Put all of your application code (including your package.json and node_modules folder) into a folder in this directory named Package. The entry point is Package/index.js.

Getting Started

  1. Install AWS CLI
    • brew install awscli
  2. Configure AWS CLI
    • aws configure --profile [name of your project]
  • AWS Access Key ID: [paste-access-key-id-here]
comments.map do |comment|
comment['member']['blocked'] = member_is_blocking?(comment['member'])
comment['body'] = body_for(comment)
comment['member_has_voted'] = member_has_voted?(comment)
comment['children'] = decorate!(comment['children'])
comment
end
def member_is_blocking?(other_member)
blocked_member_ids.include?(other_member['id'])
end
def blocked_member_ids
return [] if @current_member.nil?
@blocked_member_ids ||= @current_member.blocked_members.pluck(:id)
end
def member_has_voted?(comment)
comments.
reject { |comment|
# Comment is deleted with no children, always hide
next true if deleted?(comment) && comment['children'].empty?
# Comment is your own, always show
next false if is_own_comment?(comment)
# Pending comment with no replies
next true if pending?(comment) && comment['children'].empty?
# If the comment tree exists in cache, it will be pulled from cache without
# doing any extra processing. If it doesn't exist in cache, we do all of the
# stuff I wrote about above.
data = Rails.cache.fetch(Comment.cache_key_for(@article, @params[:sort])) do
arranged_comments.map do |data|
# Each data object contains the comment, it's reply_to (if applicable), and
# the comment children. Calling as_json will convert all of the data to a
# plain JSON-like object.
Api::V1::CommentSerializer.new(data).as_json
end
# In order to build the tree structure, we select comments that are only root nodes,
# i.e. comments that are not a reply. From there, we can build the tree structure based
# on their children, which we collected earlier.
transform_node_index(node_index.select { |node_id, data| data[:parent].nil? }.values)
# This is a recursive method that will traverse the comment structure, and run for
# the children of each comment. In the end, once the recursion finishes, a tree pops out.
def transform_node_index(nodes)
nodes.map do |data|
{
node_index.each do |node_id, data|
# This is a root node, no processing to do.
next if data[:node].ancestry.nil?
# Here we check the nesting depth to make sure it is not over the max
# allowed depth.
assigned_parent_id = nil
if data[:node].depth > Comment::MAX_DEPTH
# Comment is nested deeper than the max allowed depth, which means we
# convert it to a "reply to" style comment and move it up the tree to