Skip to content

Instantly share code, notes, and snippets.

View dorokhin's full-sized avatar
🎯
Focusing

dorokhin

🎯
Focusing
View GitHub Profile
@dorokhin
dorokhin / DS1307.py
Created September 30, 2016 09:08 — forked from sorz/DS1307.py
Read and wite datetime on DS1307 via I2C by Python.
#!/usr/bin/env python
#encoding: utf-8
# Copyright (C) 2013 @XiErCh
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
@dorokhin
dorokhin / rpi-cat9532.py
Created October 8, 2016 12:55 — forked from electronut/rpi-cat9532.py
Raspberry Pi communicating with I2C PWM chip CAT9532 (16-bit Programmable LED Dimmer)
###############################################################################
# rpi-cat9532.py
#
# Author: electronut.in
#
# Description:
#
# Raspberry Pi communicating with I2C PWM chip CAT9532
# (16-bit Programmable LED Dimmer)
#
@dorokhin
dorokhin / template.html
Created May 15, 2017 08:23
django bootstrap grid
{% for article in articles %}
{% if forloop.first %}<div class="row">{% endif %}
<div class="col-xs-4">
<a href="#"> {{ sub_article.name }} </a>
</div>
{% if forloop.counter|divisibleby:3 %}</div><div class="row">{% endif %}
{% if forloop.last %}</div>{% endif %}
@dorokhin
dorokhin / template_pagination.html
Created May 26, 2017 15:49
django pagination template cut
{% if page_obj.has_other_pages %}
<div class="row justify-content-md-center">
<nav aria-label="Page navigation example">
<ul class="pagination justify-content-center">
<!-- Older page -->
{% if page_obj.has_previous %}
<li class="page-item">
<a class="page-link" href="?page={{ page_obj.previous_page_number }}">Назад</a>
</li>
{% else %}
@dorokhin
dorokhin / stats_middleware.py
Created June 17, 2017 01:25
Displaying the page generation time
import time
class StatsMiddleware(object):
'''
MIDDLEWARE_CLASSES = (
'project.stats_middleware.StatsMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
...
)
@dorokhin
dorokhin / client.md
Last active January 3, 2018 12:25
OpenVPN client config (*.ovpn)

OpenVPN client config (*.ovpn)

extract certificates/keys, required to import profile into network manager.

From client.ovpn file (in end of each file must be new line \n):

  • Copy symbols between <ca> tags into ca.crt, remove <ca> tags.
  • Copy symbols between <cert> from -----BEGIN CERTIFICATE----- to -----END CERTIFICATE----- tags into client.crt, remove <cert> tags.
  • Copy symbols between <key> tags into client.key, remove <key> tags.
  • Copy symbols between <tls-auth> tags into ta.key, remove <tls-auth> tags.

insert the following lines:

import ctypes
import struct
def get_uptime():
libc = ctypes.CDLL('libc.so.6')
buf = ctypes.create_string_buffer(4096) # generous buffer to hold struct sysinfo
if libc.sysinfo(buf) != 0:
print('failed')
return -1
@dorokhin
dorokhin / csvtojson.py
Created March 15, 2018 07:21
CSV to JSON
import csv
import json
f = open('./csv/data.csv', 'rU')
reader = csv.DictReader(f, fieldnames=('id', 'name'))
out = json.dumps([row for row in reader])
f=open('./output1.json', 'w+')
f.write(out)
@dorokhin
dorokhin / index.html
Created March 23, 2018 04:13
css simple menu
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Vertical menu</title>
</head>
<body>
<ul class="main-menu">
<li><a href="#">Index</a></li>
<li class="active"><a href="#">Demo</a></li>
@dorokhin
dorokhin / css-selectors.md
Created April 4, 2018 07:40 — forked from magicznyleszek/css-selectors.md
CSS Selectors Cheatsheet

CSS Selectors Cheatsheet

Element selectors

Element -- selects all h2 elements on the page

h2 {
    foo: bar;