Skip to content

Instantly share code, notes, and snippets.

View Hammer2900's full-sized avatar
🚚
Working from home

Yevhen Ts. Hammer2900

🚚
Working from home
View GitHub Profile
Installing Arch:
sudo vim /etc/pacman.conf
Update packages list: sudo pacman -Syy
run sudo pacman -Syu before installing any software (to update the repositories first)
* Timing issue:
- Change hardware clock to use UTC time:
sudo timedatectl set-local-rtc 0
# Something in lines of http://stackoverflow.com/questions/348630/how-can-i-download-all-emails-with-attachments-from-gmail
# Make sure you have IMAP enabled in your gmail settings.
# Right now it won't download same file name twice even if their contents are different.
import email
import getpass, imaplib
import os
import sys
detach_dir = '.'
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Topmenu and the submenus are based of the example found at this location http://blog.skeltonnetworks.com/2010/03/python-curses-custom-menu/
# The rest of the work was done by Matthew Bennett and he requests you keep these two mentions when you reuse the code :-)
# Basic code refactoring by Andrew Scheller
from time import sleep
import curses, os #curses is the interface for capturing key presses on the menu, os launches the files
screen = curses.initscr() #initializes a new window for capturing key presses
curses.noecho() # Disables automatic echoing of key presses (prevents program from input each key twice)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# python_rdesktop_gui.py
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
@Hammer2900
Hammer2900 / list to N dicts
Created May 22, 2015 09:41
python list to N dicts
a = [1,2,3,4,5,6,7,8]
print zip(*[iter(a)]*3)
#[(1, 2, 3), (4, 5, 6)]
@Hammer2900
Hammer2900 / normalize
Created May 25, 2015 13:09
normalize string
#!/usr/bin/python
# -*- coding: utf-8 -*-
import pafy
import re
url = "https://www.youtube.com/watch?v=h1klFHmcw64"
video = pafy.new(url)
print video.title
@Hammer2900
Hammer2900 / pickle class
Created June 4, 2015 19:53
Pickle class for save load object in file
class PickleFileManager(object):
def __init__(self, homedir):
self.HOMED = homedir
self.dir_is_exsist()
def dir_is_exsist(self):
if os.path.exists(self.HOMED):
pass
else:
os.mkdir(self.HOMED)
@Hammer2900
Hammer2900 / time
Created June 4, 2015 19:56
Time function
# -*- coding: utf-8 -*-
import datetime
now_date = datetime.date.today() # Текущая дата (без времени)
now_time = datetime.datetime.now() # Текущая дата со временем
cur_year = now_date.year # Год текущий
cur_month = now_date.month # Месяц текущий
cur_day = now_date.day # День текущий
cur_hour = now_time.hour # Час текущий
@Hammer2900
Hammer2900 / one list item
Created June 6, 2015 19:24
If you want to find one element or None
lst = [1,2,3]
first_or_default = next((x for x in lst if x == 10), None)
print first_or_default
@Hammer2900
Hammer2900 / sets_as_table
Created June 7, 2015 19:09
When writing BDD code with behave, you may want to include a set of examples for scenario outline, or provide a table for setting up initial conditions. This snippet ease the pain of formatting the table properly as text
import string
def as_behave_table(data):
""" nosetests --with-doctest --with-coverage report_table.py
>>> from report_table import as_behave_table
>>> data = [('what', 'how', 'who'),
... ('lorem', 'that is a long value', 3.1415),
... ('ipsum', 89798, 0.2)]