Skip to content

Instantly share code, notes, and snippets.

View Rast1234's full-sized avatar
💭
#OpenToWork! https://www.linkedin.com/in/rast1234/

Rostislav Kirillov Rast1234

💭
#OpenToWork! https://www.linkedin.com/in/rast1234/
View GitHub Profile
@Rast1234
Rast1234 / stats
Created June 26, 2014 19:43
log stats for content migration
#!/bin/bash
bytes=`cat $1* | grep -i 'to drive' | cut -d ' ' -f 8 | paste -s -d + | bc`
rows=`cat $1* | grep -i 'fetched' | cut -d ' ' -f 7 | paste -s -d + | bc`
start=`cat $1* | grep -i 'started' | head -n 1 | cut -d ' ' -f 1,2`
end=`cat $1* | grep -i 'finished' | tail -n 1 | cut -d ' ' -f 1,2`
echo "$start - $end; $rows rows; $bytes bytes"
seconds=`python -c "from dateutil.parser import parse; import sys; print (parse(sys.argv[2])-parse(sys.argv[1])).seconds" "$start" "$end"`
rs=`bc <<< "scale=2;$rows/$seconds"`
bs=`bc <<< "scale=2;$bytes/$seconds"`
@Rast1234
Rast1234 / line-endings
Created May 7, 2014 13:09
line-endings counter and converter (when you have mixed LF and CRLF in one file)
#!/usr/bin/python
import sys
from subprocess import call
def main():
if len(sys.argv) == 3 and sys.argv[1] == "-c":
filename = sys.argv[2]
(all, dos, nix) = doWork(filename)
cmd = "unix2dos" if dos > nix else "dos2unix"
call([cmd, "-q", "-k", filename])
@Rast1234
Rast1234 / torrents-md5.py
Created March 9, 2014 02:14
Count how much .torrents have md5 hashes for files
import os
import fnmatch
import bencode
from bencode import BTL
from pprint import pprint
def findTorrents(*searchDirs):
for searchDir in searchDirs:
for root, dirnames, filenames in os.walk(searchDir):
for filename in fnmatch.filter(filenames, '*.torrent'):
# Open file, generate voice and silence parts index, save
Read from file: "c:\Videolectures\a.mp3"
# set parameters for intensity analysis
min_pitch = 100 ; (Hz)
time_step = 0.0 ; (sec) 0 is auto
# set parameters for silent intervals detaction
silence_threshold = -27.0 ; (dB)
min_silent_interval = 0.5 ; (sec)
@Rast1234
Rast1234 / print_tests.html
Created January 24, 2014 15:03
Printing part of a webpage, different ways
<!DOCTYPE HTML>
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript" src="printThis.js"></script>
<script type="text/javascript">
$(document).ready(function () {
//printThis.js is a jQuery plugin, get it here:
ололо!
http://treeice.ru/stat/
сводная таблица
https://docs.google.com/spreadsheet/ccc?key=0AvOjE9_eerOJdGNoMmhIUjZnZWxqS01SdThIWU5Uc1E&usp=sharing#gid=0
матстат 2013 кб
https://docs.google.com/document/d/1HInPfEYKWq2-2a7Um-wMxSTDxmQPRWpdaUYnnRXJ2zI/edit
матстат 2014
@Rast1234
Rast1234 / susi calc
Last active December 30, 2015 13:49
http://minus-60.ru/index.php?catalog=8 - calculates price and koefficient rub/grams; price with 60% coupon (with cost = 80 rub)
$('div[class=b-container-content-item-col]').each(function(i,e){
var t = e.textContent;
var tmp = t.split('\n');
var weight = parseInt(tmp[1]);
var price = parseInt(tmp[2]);
var k = price/weight;
var lol = $("<div><br /><h2>"+k+"<br />$"+(80+price*0.4)+"</h2></div>");
$(e).append(lol);
})
@Rast1234
Rast1234 / gist:7812794
Created December 5, 2013 19:57
Hide all VK posts in a chat except yours; to find something you posted before
//load jQuery because Vk has no $'s :)
var jq = document.createElement('script');
jq.src = "//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js";
document.getElementsByTagName('head')[0].appendChild(jq);
// ... give time for script to load, then type.
jQuery.noConflict();
//drop other's posts
@Rast1234
Rast1234 / XML parsererror research
Last active March 13, 2018 12:00
Sniffing out what different DOMParser-enabled browsers return on invalid XML input. Launch and compare output across browsers.
function isValidXML(xmlString) {
var parser = new DOMParser();
var parsererrorNS = parser.parseFromString('INVALID', 'text/xml').getElementsByTagName("parsererror")[0].namespaceURI;
var dom = parser.parseFromString(xmlString, 'text/xml');
if(dom.getElementsByTagNameNS(parsererrorNS, 'parsererror').length > 0) {
return false
}
return true;
}
$ pip-2.7 show wxPython
---
Name: wxPython
Version: 2.8.12.1
Location: /usr/lib/python2.7/site-packages/wx-2.8-gtk2-unicode
Requires:
$ pip-2.7 install wxPython --upgrade -v --pre
Installed version (2.8.12.1) is most up-to-date (past versions: src-2.9.5.0, src-2.8.12.1, docs-2.9.5.0, docs-2.8.12.1, demo-2.9.5.0, demo-2.8.12.1)
Requirement already up-to-date: wxPython in /usr/lib/python2.7/site-packages/wx-2.8-gtk2-unicode