Skip to content

Instantly share code, notes, and snippets.

defmodule Snowflake do
use Application
def start(_type, _args) do
import Supervisor.Spec
children = [
worker(:riak_core_vnode_master, [Snowflake.VNode]),
]
def handle_call({:publish, message}, _from, %{sessions: sessions}=state) do
Enum.each(sessions, &send(&1.pid, message))
{:reply, :ok, state}
end
@vishnevskiy
vishnevskiy / gracex.go
Last active June 29, 2019 18:18
Allows running an Elixir/Erlang subprocess which can be gracefully restarted by daisy chaining spawned children.
package main
import (
"flag"
"fmt"
"io/ioutil"
"log"
"os"
"os/exec"
"os/signal"
import time
import pymongo
import gc
conn = pymongo.Connection('localhost', 27017)
system = conn.dkp.systems.find_one()
for raid in conn.dkp.raids.find({'system_id': system['_id']}):
pass
import time
import pymongo
conn = pymongo.Connection('localhost', 27017)
system = conn.dkp.systems.find_one()
raids = list(conn.dkp.raids.find({'system_id': system['_id']}))
del raids
# no matter how much time passes, the RAM is not being reclaimed
import types
class Column(object):
def __init__(self, name):
self._name = name
def __add__(self, other):
return {self._name: {'$inc': other}}
def __eq__(self, other):
from lib.mongomapper import Document
from lib.db import mongo
class Raid(Document):
"""
_id = ObjectId
event_id = ObjectId
outcome = Integer
participants = List
loot = List
%% if not value: return None
%% parts = value.split("|")
%% if len(parts) != 3: return None
%% if include_name:
%% signature = self._cookie_signature(name, parts[0], parts[1])
%% else:
%% signature = self._cookie_signature(parts[0], parts[1])
%% if not _time_independent_equals(parts[2], signature):
%% logging.warning("Invalid cookie signature %r", value)
%% return None
@route('/forum/p/(\w+)/', 'forum_post')
class PostHandler(BaseHandler):
def get(self, id):
post = Post.documents.find_one({'_id': ObjectId(id), 'guild_id': self.guild_id}, fields=['thread_id', 'n'])
assert post, 'Post does not exist.'
thread = Thread.documents.get(post.thread_id, fields=['slug'])
if post.n == None:
post.n = Post.documents.eval("""function() {
var n = -1;
class Forums(Module):
can_moderate_forums = Permission('Can moderate forums')
can_start_threads = Permission('Can start new threads', groups=['root_user', 'guild_guest', 'guild_member'])
can_reply_to_threads = Permission('Can reply to threads', groups=['root_user', 'guild_guest', 'guild_member'])
can_delete_own_posts = Permission('Can delete own posts')
can_edit_own_posts = Permission('Can edit own posts', groups=['root_user', 'guild_guest', 'guild_member'])
can_create_polls = Permission('Can create polls', groups=['root_user', 'guild_guest', 'guild_member'])
can_vote_in_polls = Permission('Can vote in polls', groups=['root_user', 'guild_guest', 'guild_member'])
can_rate_posts = Permission('Can rate posts', groups=['root_user', 'guild_guest', 'guild_member'])