Skip to content

Instantly share code, notes, and snippets.

View singhpratyush's full-sized avatar

Pratyush Singh singhpratyush

View GitHub Profile
@singhpratyush
singhpratyush / plot_top.py
Created May 13, 2017 16:48
A program to plot output of top command, dumped in several files for different processes.
"""
This program plots output of top commands dumped in different files
"""
import sys
import numpy
from matplotlib import pyplot
def clean(line):
@singhpratyush
singhpratyush / request_loklak.py
Last active June 14, 2017 04:50
A small script that keeps requesting random searches from a loklak instance
import os
import requests
link = 'http://api.wordnik.com/v4/words.json/randomWords?hasDictionaryDef=tru'
'e&minCorpusCount=0&minLength=5&maxLength=15&limit=1&api_key='
+ os.environ.get('WORDNIK_KEY')
loklak_host = 'http://35.188.118.126'
while True:
@singhpratyush
singhpratyush / plot_kaizen_probability.py
Last active June 29, 2017 17:27
A small code to illustrate the behaviour of how KaizenHarvester from loklak server project
"""
Kaizen Harvester - https://github.com/loklak/loklak_server/blob/development/src/org/loklak/harvester/strategy/KaizenHarvester.java
loklak server project - https://github.com/loklak/loklak_server
"""
import random
from matplotlib import pyplot
m = []
@singhpratyush
singhpratyush / priority_kaizen_score.py
Created July 11, 2017 12:44
A plot to visualise the score for a Tweet with various properties in loklak's PriorityKaizen harvester
import numpy
from matplotlib import pyplot
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
x = numpy.arange(0, 30, 0.1)
y = numpy.arange(0, 30, 0.1)
x, y = numpy.meshgrid(x, y)
I  [2017-09-09 14:53:35,843][WARN ][cluster.action.shard     ] [Controller] [messages_week][4] received shard failed for [messages_week][4], node[3cz-CBk5Ro-0MCy0A9cp6A], [P], v[137], s[INITIALIZING], a[id=2gM_hcRETP2Eg2vsAjJkyQ], unassigned_info[[reason=ALLOCATION_FAILED], at[2017-09-09T14:52:56.492Z], details[failed recovery, failure IndexShardRecoveryException[failed to recovery from gateway]; nested: EngineCreationFailureException[failed to recover from translog]; nested: EngineException[failed to recover from translog]; nested: TranslogCorruptedException[translog corruption while reading from stream]; nested: TranslogCorruptedException[translog stream is corrupted, expected: 0x64332db9, got: 0x74223a30]; ]], indexUUID [vhW2TG5uTHiYPUwNZRJSiQ], message [failed recovery], failure [IndexShardRecoveryException[failed to recovery from gateway]; nested: EngineCreationFailureException[failed to recover from translog]; nested: EngineException[failed to recover from translog]; nested: TranslogCorruptedExcepti
import steem from 'steem';
// Get the form values
let username = document.getElementById('steem-username').value;
let privatePostingKey = document.getEmenentById('steem-posting-key').value;
// Get user details
steem.api.getAccounts([username], (err, result) => {
if (err) {
// Something went wrong
@app.after_request
def after_request(response):
response.headers.add('Accept-Ranges', 'bytes')
return response
r = requests.get(url)
range_header = request.headers.get('Range', None)
if range_header: # Client has requested for partial content
size = int(r.headers.get('content-length')) # Actual size of song
# Look up for ranges
m = re.search('(\d+)-(\d*)', range_header)
g = m.groups()
byte1, byte2 = 0, None
if g[0]:
range_header = request.headers.get('Range', None)
if range_header:
from_bytes, until_bytes = range_header.replace('bytes=', '').split('-')
if not until_bytes: # No until bytes is set, set it to start + 3MB
until_bytes = int(from_bytes) + int(1024 * 1024 * 3) # 1MB * 3 = 3MB
# Get only what required from YouTube
headers = {'Range': 'bytes=%s-%s' % (from_bytes, until_bytes)}
r = requests.get(url, headers=headers)
data = r.content