Skip to content

Instantly share code, notes, and snippets.

View uda's full-sized avatar

Yehuda Deutsch uda

View GitHub Profile
@uda
uda / trevnoc.py
Created September 15, 2019 19:46
Convert file contents from one encoding to another
#!/usr/bin/env python3
def trevnoc(source, target, source_encoding, target_encoding):
with open(source, 'r', encoding=source_encoding) as f:
content = f.read()
with open(target, 'w', encoding=target_encoding) as f:
f.write(content)
@uda
uda / README.md
Last active April 5, 2018 20:14
Run multiple instances of native telegram-desktop client from the same user

Multiple official telegram desktop instances

By manipulating the XDG_DATA_HOME environment variable I was able to run multiple instances of the official telegram desktop.

This will be useful until telegram provides a better manner, in the official release, to handle multiple users in telegram, just like they did in the mobile version.

Notice: ~/.TelegramDesktop

If the path ~/.TelegramDesktop exists, this solution won't work.

@uda
uda / LICENSE
Last active February 26, 2018 17:37
Django URL Custom path converter
Copyright (c) Yehuda Deutsch <yeh@uda.co.il>
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
@uda
uda / letsencrypt.cron
Last active February 18, 2018 08:14
Let's Encrypt / CertBot crontab
PATH=/sbin:/usr/sbin:/bin:/usr/bin
# Replace letsencrypt with certbot / certbot-auto or the full path to letsencrypt command
# Replace nginx test and reload with relevant HTTP server
# Try renewing certs once a week
0 0 * * 0 root letsencrypt renew && nginx -t && service nginx reload
# certbot-auto with apache2
#0 0 * * 0 root certbot-auto renew && apache2ctl configtest && service apache2 reload
@uda
uda / server.py
Created February 8, 2018 16:16
Twisted / Klein custom request usage
from klein.app import KleinRequest, Klein
from klein.interfaces import IKleinRequest
from twisted.python.components import registerAdapter
from twisted.web.server import Request, Site
class CustomRequest(Request):
def get_something_else(self):
return 'I am something else'
@uda
uda / nest.py
Created September 6, 2017 08:45
Python nesting by list of keys
def nest(key_list, value=None):
"""
Args:
key_list(Union[list, tuple]): A list or tuple of keys
value(any): Any value to assign the leaf
Returns:
A hierarchical dictionary
Examples:
@uda
uda / django_remote_addr.py
Created August 18, 2017 10:06
Django Remote IP
from django.conf import settings
from django.views.generic import View
class SomeBaseView(View):
_ip_address = None
def django_ip_address(self):
if self._ip_address is None:
x_forwarded_for = self.request.META.get('HTTP_X_FORWARDED_FOR') or ''
@uda
uda / _KleinController.py
Last active May 11, 2017 21:44
Klein controller concept
"""A basic controller concept for Twisted based micro web framework Klein"""

Keybase proof

I hereby claim:

  • I am uda on github.
  • I am uda (https://keybase.io/uda) on keybase.
  • I have a public key ASCg8FQdv3ycwWHHiHb1wJfLIHm66P7vfgIMf0qtCt3uSAo

To claim this, I am signing this object:

@uda
uda / bubbledict.py
Created January 29, 2017 10:06
BubbleDict
"""
License: MIT https://uda.mit-license.org/
Author: Yehuda Deutsch <yeh@uda.co.il>
BubbleDict is a stupid to need class, but given some data structures, this might come handy.
When you need to populate a dict recursively, and some levels might not be set yet, this is to avoid multiple ifs in the code.
Before:
```
multi_level_dict = {}