Skip to content

Instantly share code, notes, and snippets.

SSH agent forwarding and screen

When connecting to a remote server via SSH it is often convenient to use SSH agent forwarding so that you don't need a separate keypair on that server for connecting to further servers.

This is enabled by adding the

ForwardAgent yes

option to any of your Host entries in ~/.ssh/config (or alternatively with the -A option). Don't set this option in a wildcard Host * section since any user on the remote server that can bypass file permissions can now als use keys loaded in your SSH agent. So only use this with hosts you trust.

@sapamja
sapamja / wrap_view.py
Created October 30, 2015 07:02 — forked from MacMaru/wrap_view.py
Override Tastypie wrap_view() to return custom (JSON) response
class YourResource(ModelResource):
def wrap_view(self, view):
"""
Wraps views to return custom error codes instead of generic 500's
"""
@csrf_exempt
def wrapper(request, *args, **kwargs):
try:
@sapamja
sapamja / ping.py
Created September 24, 2015 05:16 — forked from pklaus/ping.py
A pure python ping implementation using raw socket.
#!/usr/bin/env python2
"""
Other Repositories of python-ping
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* https://github.com/l4m3rx/python-ping supports Python2 and Python3
* https://bitbucket.org/delroth/python-ping
@sapamja
sapamja / golang_resouce
Last active January 19, 2018 01:18
GoLang Resouces
Facebook:
https://www.facebook.com/notes/learn-golang/free-go-resources-available-in-internet/781530568600486
Go learning resources available in Internet.
Official GoLang Sites:
Golang: http://golang.org
Golang Blog: https://blog.golang.org/
@sapamja
sapamja / adapter.py
Last active August 29, 2015 14:06 — forked from pazdera/adapter.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Example of `adapter' design pattern
# Copyright (C) 2011 Radek Pazdera
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
@sapamja
sapamja / dict_get.py
Created September 22, 2014 21:42
dictionary get for nested dictionary
>>>
>>> d = {
... 'key1' : {
... 'value': "parent-key1",
... 'subkey1': {
... 'value': "child1"
... },
... 'subkey2': {
... 'value': "child2"
... }
@sapamja
sapamja / ip_sub.py
Created September 2, 2014 07:01
ip_sub.py
import socket, struct
def ip_to_decimal(ip):
return struct.unpack("!L", socket.inet_aton(ip))[0]
def decimal_to_ip(decimal):
return socket.inet_ntoa(struct.pack("!L", decimal))
cidr = '192.168.0.1/24'
network, netmask = cidr.split('/')
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import urllib2
gh_url = 'https://api.github.com'
req = urllib2.Request(gh_url)
password_manager = urllib2.HTTPPasswordMgrWithDefaultRealm()
@sapamja
sapamja / load_module.py
Created August 17, 2014 19:48
Load all module from path
import os
import sys
import importlib
import inspect
import logging
def load_module(module_path, filename):
""" returns the module if filename is a module else None """
if filename.endswith('.py'):
module = filename[:-3]
@sapamja
sapamja / storage_class.py
Created August 14, 2014 23:55
storage_class to store data
# -*- coding: utf-8 -*-
"""
This file contains Storage class to storage data.
"""
class Storage(dict):
"""
A Storage object is like a dictionary except `obj.foo` can be used
in addition to `obj['foo']`.