Skip to content

Instantly share code, notes, and snippets.

View gitex's full-sized avatar
🏠
Working from home

Evgeniy Dorovatovskiy gitex

🏠
Working from home
  • R7
  • Kazachstan
  • 02:31 (UTC +05:00)
View GitHub Profile
@gitex
gitex / mongodb_view.py
Last active May 2, 2016 09:36
My Mongo
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from pymongo import MongoClient
import json
client = MongoClient('localhost', 27017)
database = client.mydb['collection_name']
items = list(database.find({}, {'_id': 0}))
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
from PyQt4 import QtGui
class Widget(QtGui.QDialog):
def __init__(self, parent=None):
QtGui.QDialog.__init__(parent)
@gitex
gitex / function_cache.py
Created June 1, 2016 16:38
Python: caching the values of functions at certain times
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from datetime import timedelta, datetime
from time import sleep
from functools import partial
class Cache(object):
"""Class caching function's results for some time.
@gitex
gitex / Item.py
Last active September 15, 2016 16:08
class Item(model.Model):
# что-то
def get_options(self):
"""Получить опции этого Item в JSON"""
item_options = ItemOption.objects.all(item__id=self.id):
for topic in item_options.values_list('option__topic').distinct():
data = {'name': topic.name, 'options': []}
@gitex
gitex / timezone.js
Created September 21, 2016 01:23
Get user' timezone in JavaScript
// You must set the timezone offset by JavaScript into cookies using JavaScript
var userDate = new Date();
var tzOffset = userDate.getTimezoneOffset();
// Now set the cookie
@gitex
gitex / download.js
Created December 30, 2017 01:28
Create and download file by JS
function download(filename, text) {
var element = document.createElement('a');
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
element.setAttribute('download', filename);
element.style.display = 'none';
document.body.appendChild(element);
element.click();
@gitex
gitex / gist:fc10c4b155f45827190815b81452455c
Last active April 3, 2020 16:26
Docker Postgress Dump
# Dump database from container
docker exec -t %CONTAINER_NAME% pg_dumpall -c -U %USER% | gzip > /tmp/dump_`date +%d-%m-%Y"_"%H_%M_%S`.gz
@gitex
gitex / git-failed-to-push.sh
Last active April 27, 2020 10:05 — forked from OmeGak/git-failed-to-push.sh
Fix for cleaning a repository when: "error: Couldn't set refs/heads/branchName"
# Solves:
# error: Couldn't set refs/heads/branchName
# To X:xxx.git
# ! [remote rejected] branchName -> branchName (failed to write)
# error: failed to push some refs to 'X:xxx.git'
git fsck —unreachable
git reflog expire —expire=0 —all
git repack -a -d -l
git prune
@gitex
gitex / python_and_go_diff.txt
Last active August 7, 2020 09:19
Python and Go diff
# Python and Go
def (*args) -> func (args...)
[
{
"id": 369,
"day": 108,
"order": 0,
"question": "Question 1",
"answers": [
{
"id": 1101,
"title": "1",