Skip to content

Instantly share code, notes, and snippets.

@AronDavis
AronDavis / randomParentComment.js
Last active April 24, 2017 15:13
Reddit - Select 1st Level Comment at Random
//Run this at thread level to select a random 1st level (aka parent/top-tier) comment. Useful for giveaways.
var parentComments = $(".sitetable.nestedlisting > .thing > .parent");
var index = Math.floor(Math.random() * parentComments.length);
var selectedComment = $(parentComments[index]).parent();
var commentId = selectedComment.attr('id');
var username = selectedComment.find(".entry > .tagline > .author").text();
var commentText = selectedComment.find(".usertext > .usertext-body").text();
console.log(`Selected comment "${commentId}" by "${username}"\n\n${commentText}`);
@AronDavis
AronDavis / JTokenExtensions.cs
Last active August 17, 2016 14:30
Newtonsoft JToken Extensions for dealing with nulls with Value<T> where T is a struct.
using System;
using Newtonsoft.Json.Linq;
public static class JTokenExtensions
{
/// <summary>
/// Extension of JToken Value<T> method. Used to avoid null exceptions with value types when parsing JToken.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="token"></param>