Skip to content

Instantly share code, notes, and snippets.

function monkeyPatchXMLHttpRequest() {
const { xhook } = require("xhook");
xhook.before(function (request) {
if (request.headers[ "X-Passphrase" ]) {
request.passphrase = request.headers[ "X-Passphrase" ];
delete request.headers[ "X-Passphrase" ];
}
});
import * as React from 'react';
export function Voter() {
const [ state, setState ] = React.useState(0);
return (
<div>
<button onClick={e => setState(x => x + 1)}>click</button>
Hello there {state}
</div>
function removeAndReinsert(element: Element) {
const parent = element.parentNode;
if (parent.childElementCount > 1) {
const nextSibling = element.nextSibling;
parent.removeChild(element);
parent.insertBefore(element, nextSibling)
} else if (parent.childElementCount === 1) {
parent.removeChild(element);
parent.appendChild(element);
defmodule AlchemyWeb.UserChannelListener do
use GenServer
def start_link(name: name) do
GenServer.start_link(__MODULE__, [], name: name)
end
def init(_) do
{:ok, %{}}
end

Important! Please use this feature only when strictly necessary, otherwise it is very easy to end-up with large schemas with dozens of different associations polluting your schema and affecting your application performance. For instance, if you are using associations only for different querying purposes, then it is preferable to build and compose queries, rather than defining multiple associations:

posts
|> Ecto.assoc(:comments)
|> Comment.deleted()

Or when preloading:

[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
precomposeunicode = true
[remote "origin"]
url = /var/folders/26/cpffj2js733d5kmk6m9w0n840000gn/T/remote_repo-1553169570-79079-8z91wd
fetch = +refs/heads/master:refs/remotes/origin/master
➜ checkout_folder-1553168098-77024-9teiqi git:(master) git remote -v
origin /var/folders/26/cpffj2js733d5kmk6m9w0n840000gn/T/remote_repo-1553168098-77024-1739w62 (fetch)
origin /var/folders/26/cpffj2js733d5kmk6m9w0n840000gn/T/remote_repo-1553168098-77024-1739w62 (push)
# git branch -a
* master
remotes/origin/HEAD -> origin/master
remotes/origin/master
remotes/origin/newbranch
(END)
defmodule AlchemyWeb.LicenseChecker do
@moduledoc """
At a constant interval, confirm that all connected users have a license. If not then
send a message to their channel telling the client to kick them out.
"""
use GenServer
alias Alchemy.Licensing
# The interval between checks
@interval 1000
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
# Frontend SSL server
server {
listen 443;
server_name xxx;