Last active
January 8, 2019 19:53
-
-
Save Fumesover/3e5c5529a493635126a264878c2a1fa0 to your computer and use it in GitHub Desktop.
CodiMD Edit test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Variables for tests | |
SERVER= # codimd instance | |
NOTEID= # a note id | |
# Authentification is handeled by https://github.com/hackmdio/codimd-cli/pull/9 | |
# The socket url | |
URL=$SERVER/socket.io/?noteId=$NOTEID\&EIO=3\&transport=polling | |
# get the 'io' token | |
curl -c /tmp/codimd-cookies.txt \ | |
-b /tmp/codimd-cookies.txt \ | |
$URL\&t=$(python yeast.py) \ | |
&> /dev/null | |
TOKEN=$(cat /tmp/codimd-cookies.txt | grep io | awk '{print $7}') | |
# Now, send some payloads to the socket.io Websocket | |
curl -b /tmp/codimd-cookies.txt \ | |
$URL\&t\=$(python yeast.py)\&sid\=$TOKEN \ | |
-H "Content-Type: text/plain;charset=UTF-8" \ | |
-d @msg_0 | |
curl -b /tmp/codimd-cookies.txt \ | |
$URL\&t\=$(python yeast.py)\&sid\=$TOKEN \ | |
-H "Content-Type: text/plain;charset=UTF-8" \ | |
-d @msg_1 | |
curl -b /tmp/codimd-cookies.txt \ | |
$URL\&t\=$(python yeast.py)\&sid\=$TOKEN \ | |
-H "Content-Type: text/plain;charset=UTF-8" \ | |
-d @msg_2 | |
curl -b /tmp/codimd-cookies.txt \ | |
$URL\&t\=$(python yeast.py)\&sid\=$TOKEN \ | |
-H "Content-Type: text/plain;charset=UTF-8" \ | |
-d @msg_3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20:42["selection",null] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50:42["cursor focus",{"line":0,"ch":8,"sticky":null}] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50:42["selection",{"ranges":[{"anchor":8,"head":8}]}] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59:42["operation",0,[7,-1],{"ranges":[{"anchor":7,"head":7}]}] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# yeast.py: Tiny script to generate the timestampParam required by the socket.io server | |
# Author: https://gist.github.com/avramit/271d1cd1465022ba17218609343ae5a7 | |
import math | |
from datetime import datetime | |
import http.client, urllib.parse | |
class Yeast: | |
def __init__(self): | |
self.alphabet = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_' | |
self.length = 64 | |
self.seed = 0 | |
self.prev = None | |
def encode(self, num): | |
encoded = '' | |
while num > 0: | |
encoded = self.alphabet[num % self.length] + encoded | |
num = math.floor(num / self.length) | |
return encoded | |
def decode(self, encoded): | |
decoded = 0 | |
for i in range(len(encoded)): | |
decoded = decoded * self.length + self.alphabet.index(encoded[i]) | |
return decoded | |
def __call__(self): | |
now = self.encode(int(datetime.now().timestamp() * 1000)) | |
if now != self.prev: | |
self.seed = 0 | |
self.prev = now | |
return now | |
self.seed += 1 | |
return f'{now}.{self.encode(self.seed)}' | |
yeast = Yeast() | |
print(yeast()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment