Skip to content

Instantly share code, notes, and snippets.

View dmtmov's full-sized avatar

Dima dmtmov

  • Ukraine, Lviv
  • 00:00 (UTC +03:00)
View GitHub Profile
#!/usr/bin/env python
"""
These are the core lines extracted from a live, working torrenter that
uses DHT to avoid a single point of faliure, the torrent server.
Adapt to suit your needs and enjoy. Please read the docs.
Prerequisites:
PORT_RANGE must be open for bidirectional TCP and UDP traffic.
libtorrent needs to be installed. Something like:
@iconara
iconara / download.sh
Last active September 29, 2020 07:48
Download a CloudWatch Logs group
#!/bin/bash
log_group=$1
list_command="aws logs describe-log-streams --log-group-name $log_group"
group_next_token=''
while true; do
if [[ -n $group_next_token ]]; then
response=$($list_command --next-token $group_next_token)
else
@lu911
lu911 / mixins.py
Created December 13, 2014 17:52
SQLAlchemy Mixins
# -*- coding:utf-8 -*-
from flask import abort
from datetime import datetime
from project.ext import db
class IdMixin(object):
"""
Provides the :attr:`id` primary key column
@yuvadm
yuvadm / models.py
Created September 26, 2014 09:09
Django 1.5+ username field length monkey patch
# https://stackoverflow.com/questions/25136282/what-is-the-right-way-to-extend-the-username-field-length-in-django-1-5
from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth.models import AbstractUser
class MyUser(AbstractUser):
pass
USERNAME_LENGTH = 50
@grenade
grenade / 01-generate-ed25519-ssh-key.sh
Last active April 11, 2025 19:59
generate ed25519 ssh and gpg/pgp keys and set file permissions for ssh keys and config
#!/bin/bash
mkdir -p ~/.ssh
# generate new personal ed25519 ssh keys
ssh-keygen -o -a 100 -t ed25519 -f ~/.ssh/id_ed25519 -C "rob thijssen <[email protected]>"
ssh-keygen -o -a 100 -t ed25519 -f ~/.ssh/id_robtn -C "rob thijssen <[email protected]>"
# generate new host cert authority (host_ca) ed25519 ssh key
# used for signing host keys and creating host certs
@kendellfab
kendellfab / goto-sublime
Created August 1, 2013 20:53
Add mouse click `goto definition` in sublime text 3.
Linux - create "Default (Linux).sublime-mousemap" in ~/.config/sublime-text-3/Packages/User
Mac - create "Default (OSX).sublime-mousemap" in ~/Library/Application Support/Sublime Text 3/Packages/User
Win - create "Default (Windows).sublime-mousemap" in %appdata%\Sublime Text 3\Packages\User
[
{
"button": "button1",
"count": 1,
"modifiers": ["ctrl"],
"press_command": "drag_select",
@sprin
sprin / create_test_db.py
Last active November 30, 2022 04:57
A demo of creating a new database via SQL Alchemy. This module takes the form of a nosetest with three steps: - Set up the new database. - Create a table in the new database. - Teardown the new database.
"""
A demo of creating a new database via SQL Alchemy.
Under MIT License from sprin (https://gist.github.com/sprin/5846464/)
This module takes the form of a nosetest with three steps:
- Set up the new database.
- Create a table in the new database.
- Teardown the new database.
"""
@goldhand
goldhand / Django + Ajax dynamic forms .py
Last active September 29, 2023 06:32
Django form with Ajax. A simple Task model that can be updated using a CBV with an AJAX mixin. The view sends post data with ajax then updates the view with a callback to a DetailView with a json mixin.There is an abstract CBV, AjaxableResponseMixin, based on the example form django docs, that is subclassed in the TaskUpdateView CBV. TaskUpdateV…
#models.py
class Task(models.Model):
title = models.CharField(max_length=255)
description = models.TextField()
def __unicode__(self):
return self.title
@techniq
techniq / audit_mixin.py
Created March 16, 2013 01:05
Useful SQLAlchemy Mixins
from datetime import datetime
from sqlalchemy import Column, Integer, DateTime, ForeignKey
from sqlalchemy.orm import relationship
from sqlalchemy.ext.declarative import declared_attr
from flask_security import current_user
class AuditMixin(object):
created_at = Column(DateTime, default=datetime.now)
updated_at = Column(DateTime, default=datetime.now, onupdate=datetime.now)
@issackelly
issackelly / gist:928783
Created April 19, 2011 16:48
Django Template {{ block.super }} example
# Template: A.html
<html>
<head></head>
<body>
{% block hello %}
HELLO
{% endblock %}
</body>
</html>