Skip to content

Instantly share code, notes, and snippets.

View vadimii's full-sized avatar

Vadim Gusev vadimii

View GitHub Profile
@vadimii
vadimii / 1-variable.js
Last active December 17, 2015 06:19
JavaScript variable declaration test
window.test = 'global test';
(function () {
console.log(typeof test); // "undefined"
var test = 'context test';
console.log(test); // "context test"
})();
console.log(test); // "global test"
@vadimii
vadimii / mongounzip.py
Last active December 14, 2015 00:59
Download ZIP archive with a MongoDB database, unpack it and import it to the local MongoDB instance
# -*- coding: utf-8 -*-
'''Download ZIP archive with a MongoDB database, unpack it
and import it to the local MongoDB instance
Usage: python mongounzip.py
'''
import os
import os.path
import shutil
import subprocess
import sys
@vadimii
vadimii / mongozip.py
Last active September 7, 2018 16:41
Dump MongoDB databases to the zip archives and copy its to the output folder.
# -*- coding: utf-8 -*-
'''Dump MongoDB databases to the zip archives
and copy its to the output folder.
Usage: python mongozip.py
'''
import os
import os.path
import datetime
import tempfile
import shutil
@vadimii
vadimii / asana_stories.py
Created February 17, 2013 14:43
Read Asana's task stories
# -*- coding: utf-8 -*-
import json
import requests
ASANA_API_URL = 'https://app.asana.com/api/1.0'
ASANA_AUTH = ('qhXkFMH.GSCXOSYJbKfOd2U26NqaQxNf', '')
PROJECTS = {
u'Лифт в будущее': {
'id': 1493261729734,
@vadimii
vadimii / run-tasks.ps1
Created February 17, 2013 12:27
Fetch URL data with PowerShell
param($url)
$webclient = new-object Net.WebClient
$webclient.Credentials = new-object Net.NetworkCredential("admin", "pass")
$webpage = $webclient.DownloadString($url)
@vadimii
vadimii / vimeo_channel.py
Created February 3, 2013 19:55
Load Vimeo channel feed
import requests
import json
REQ_FROMAT = 'json'
CHANNEL_REQ = 'http://vimeo.com/api/v2/channel/%s/%s.%s'
SAMPLE_CHANNEL = 'leeseidenbergadvertising'
CHANNEL_INFO = 'info'
CHANNEL_VIDEOS = 'videos'
FEED_PAGE_SIZE = 20
@vadimii
vadimii / gist:4621929
Last active December 11, 2015 15:38
Ffmpeg/x264 (profile High, level 3.0) (latest versions of x264)
infile ="video.avi"
tmpfile="video_tmp.mp4"
outfile="video.mp4"
options="-vcodec libx264 -b 512k -flags +loop+mv4 -cmp 256 \
-partitions +parti4x4+parti8x8+partp4x4+partp8x8+partb8x8 \
-me_method hex -subq 7 -trellis 1 -refs 5 -bf 3 \
-flags2 +bpyramid+wpred+mixed_refs+dct8x8 -coder 1 -me_range 16 \
-g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -qmin 10\
-qmax 51 -qdiff 4"
@vadimii
vadimii / cases.cs
Created January 11, 2013 11:36
Numbers with word cases
public static string Case(
this int val,
string one,
string two,
string five) {
var t = (val % 100 > 20) ? val % 10 : val % 20;
switch (t) {
case 1:
return one;
case 2:
@vadimii
vadimii / 0_validate.py
Created November 23, 2012 00:26
Validate and transform XML with lxml
from lxml import etree
with open('./sportobj.xsd') as f:
schema = etree.XMLSchema(etree.parse(f))
with open('./sportobj-sample.xml') as f:
sample = etree.parse(f)
with open('./sportobj.xsl') as f:
transform = etree.XSLT(etree.parse(f));
@vadimii
vadimii / coords.cs
Created November 21, 2012 01:55
Geo coords for address line via Yandex API
const string cs = "<CONNECTION_STRING>";
const string key = "<YANDEX_API_CODE>";
const string requestUrlTemplate =
"http://geocode-maps.yandex.ru/1.x/" +
"?geocode={0}&key={1}&&results=1";
var addresses = new List<string>();
using (var connection = new SqlConnection(cs))
using (var select = connection.CreateCommand())
{