Skip to content

Instantly share code, notes, and snippets.

View singhpratyush's full-sized avatar

Pratyush Singh singhpratyush

View GitHub Profile
@singhpratyush
singhpratyush / rc.py
Created October 30, 2018 12:34
Steem Resource Credits for a User
import beem
from datetime import datetime
def get_resource_credits(username):
client = beem.Steem()
rc = beem.rc.RC(steem_instance=client)
account = beem.account.Account(username).json()
comment_requirement = rc.comment()
@singhpratyush
singhpratyush / webpack.config.dev.js
Last active November 11, 2019 09:50
Webpack configurations from CRA to use SCSS modules
'use strict';
const autoprefixer = require('autoprefixer');
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
const InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin');
const WatchMissingNodeModulesPlugin = require('react-dev-utils/WatchMissingNodeModulesPlugin');
const eslintFormatter = require('react-dev-utils/eslintFormatter');
def generate_data_from_response(resp, chunk=2048):
for data_chunk in resp.iter_content(chunk_size=chunk):
yield data_chunk
def serve_partial(url, range_header, mime, size=3145728):
from_bytes, until_bytes = range_header.replace('bytes=', '').split('-')
if not until_bytes:
until_bytes = int(from_bytes) + size # Default size is 3MB
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
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]:
@app.after_request
def after_request(response):
response.headers.add('Accept-Ranges', 'bytes')
return response
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
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
@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)