Skip to content

Instantly share code, notes, and snippets.

View leviroth's full-sized avatar

Levi Roth leviroth

View GitHub Profile
@leviroth
leviroth / sqlite3_test.ml
Created September 27, 2020 11:13
Sqlite3_utils error
open! Core
let sexp_of_return_code return_code : Sexp.t = Atom (Sqlite3.Rc.to_string return_code)
let create_tables database =
Sqlite3_utils.exec0_exn database "CREATE TABLE ids(id INTEGER PRIMARY KEY)"
;;
let insert database =
ignore
@leviroth
leviroth / day04.ml
Last active December 5, 2019 01:09
Advent of code 2019
open! Core
let meets_criteria criteria n = List.for_all criteria ~f:(fun criterion -> criterion n)
let solve_criteria criteria (lower, upper) =
List.range lower upper |> List.count ~f:(meets_criteria criteria)
;;
let to_char_list n = Int.to_string n |> String.to_list
@leviroth
leviroth / day03.ml
Created December 5, 2019 00:34
Advent of code 2019 / day 3
open! Core
open! Import
module Direction = struct
type t =
| Up
| Down
| Left
| Right
[@@deriving sexp]
@leviroth
leviroth / day02.ml
Created December 3, 2019 01:30
Advent of Code 2019 - Day 2 - just the essentials
open! Core
let run_program program =
let get_indirect index = program.(program.(index)) in
let set_indirect index value = program.(program.(index)) <- value in
let rec solve index =
let apply_simple_op operator =
let value = operator (get_indirect (index + 1)) (get_indirect (index + 2)) in
set_indirect (index + 3) value;
solve (index + 4)
@leviroth
leviroth / download.py
Created October 26, 2019 17:41
"New Reddit" flair transfer
import argparse
import json
import sys
import praw
parser = argparse.ArgumentParser()
parser.add_argument("-s", "--subreddit", help="subreddit", type=str, required=True)
parser.add_argument(
@leviroth
leviroth / conflict.py
Last active May 27, 2017 19:52
Reddit response body on conflicting wiki edit
{'diffcontent': '\n'
' <table class="diff" id="difflib_chg_to0__top"\n'
' cellspacing="0" cellpadding="0" rules="groups" >\n'
' <colgroup></colgroup> <colgroup></colgroup> '
'<colgroup></colgroup>\n'
' <colgroup></colgroup> <colgroup></colgroup> '
'<colgroup></colgroup>\n'
' <thead><tr><th class="diff_next"><br /></th><th '
'colspan="2" class="diff_header">current edit</th><th '
'class="diff_next"><br /></th><th colspan="2" '
@leviroth
leviroth / modmail-api.markdown
Last active March 23, 2022 21:18
Tips and tricks for Reddit's "new modmail" API

This document collects various quirks and useful pieces of information that I came across in adding support for the new modmail API to PRAW.

Secret Codes

Certain pieces of data are represented by numerical codes, which had to be deciphered through trial and error. These lists could easily be incomplete.

Mod actions

@leviroth
leviroth / examples.py
Last active March 7, 2017 15:42
Reddit new modmail API response examples
conversation:
{'authors': [{'id': 56923181,
'isAdmin': False,
'isDeleted': False,
'isHidden': False,
'isMod': True,
'isOp': False,
'isParticipant': False,
'name': 'BJO_test_mod'},
<!DOCTYPE html>
<meta charset="utf-8" />
<!-- version 1 -->
<title>[Gen 1] OU replay: clotis vs. Lucifernandes</title>
<style>
html,body {font-family:Verdana, sans-serif;font-size:10pt;margin:0;padding:0;}body{padding:12px 0;} .battle-log {font-family:Verdana, sans-serif;font-size:10pt;} .battle-log-inline {border:1px solid #AAAAAA;background:#EEF2F5;color:black;max-width:640px;margin:0 auto 80px;padding-bottom:5px;} .battle-log .inner {padding:4px 8px 0px 8px;} .battle-log .inner-preempt {padding:0 8px 4px 8px;} .battle-log .inner-after {margin-top:0.5em;} .battle-log h2 {margin:0.5em -8px;padding:4px 8px;border:1px solid #AAAAAA;background:#E0E7EA;border-left:0;border-right:0;font-family:Verdana, sans-serif;font-size:13pt;} .battle-log .chat {vertical-align:middle;padding:3px 0 3px 0;font-size:8pt;} .battle-log .chat strong {color:#40576A;} .battle-log .chat em {padding:1px 4px 1px 3px;color:#000000;font-style:normal;} .chat.mine {background:rgba(0,0,0,0.05);margin-left:-8px;margin-right:-8px;padding-left:8