Snipt.net is closing on December 31st, 2016

For more information, please visit this blog post.

snipt

Ctrl+h for KB shortcuts

Bash

Add this to .bashrc to set http_proxy right at University of Bern

1
2
3
4
5
6
7
function reset_proxy {
  if [  `networksetup -getwebproxy Wi-Fi | grep ^Enabled | cut -c 10-11`  == "No" ]; then 
        export http_proxy=; 
     else export http_proxy=proxy:80 ;
  fi
}
reset_proxy
https://snipt.net/embed/d8a6dd82ae9420e11b80e77fc41604ac/
https://snipt.net/raw/d8a6dd82ae9420e11b80e77fc41604ac/
d8a6dd82ae9420e11b80e77fc41604ac
bash
Bash
7
2016-12-02T10:40:55
True
False
False
/api/public/snipt/30549/
add-this-to-bashrc-to-set-http_proxy-right-at-university-of-bern
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a> <a href="#L-7">7</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="k">function</span> reset_proxy <span class="o">{</span> </span><span id="L-2"><a name="L-2"></a> <span class="k">if</span> <span class="o">[</span> <span class="sb">`</span>networksetup -getwebproxy Wi-Fi <span class="p">|</span> grep ^Enabled <span class="p">|</span> cut -c 10-11<span class="sb">`</span> <span class="o">==</span> <span class="s2">&quot;No&quot;</span> <span class="o">]</span><span class="p">;</span> <span class="k">then</span> </span><span id="L-3"><a name="L-3"></a> <span class="nb">export</span> <span class="nv">http_proxy</span><span class="o">=</span><span class="p">;</span> </span><span id="L-4"><a name="L-4"></a> <span class="k">else</span> <span class="nb">export</span> <span class="nv">http_proxy</span><span class="o">=</span>proxy:80 <span class="p">;</span> </span><span id="L-5"><a name="L-5"></a> <span class="k">fi</span> </span><span id="L-6"><a name="L-6"></a><span class="o">}</span> </span><span id="L-7"><a name="L-7"></a>reset_proxy </span></pre></div> </td></tr></table>
bash, osx, proxy, unibe

Batchfile

Create ssh proxy (with key)

@echo off
plink -ssh -C -N -D 8080 [email protected] -i c:\mykey.ppk
https://snipt.net/embed/595937d5ea5ff72028746a677f9f5291/
https://snipt.net/raw/595937d5ea5ff72028746a677f9f5291/
595937d5ea5ff72028746a677f9f5291
bat
Batchfile
2
2016-12-02T10:40:58
True
False
False
/api/public/snipt/20556/
create-ssh-proxy-with-key
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="p">@</span><span class="k">echo</span> off </span><span id="L-2"><a name="L-2"></a>plink -ssh -C -N -D 8080 [email protected] -i c:\mykey.ppk </span></pre></div> </td></tr></table>
network, proxy, putty, ssh, windows

Python

Django image proxy

1
2
3
4
5
6
7
8
def proxy(request):
    url = request.GET.get('url')
    if url is not None:
        try:
            img = urllib2.urlopen(url)
            return HttpResponse(img.read(), mimetype=img.info().type)
        except urllib2.URLError:
            return HttpResponse('Proxy failed.', status=404)
https://snipt.net/embed/ab4badc33bba13060c2c1076202fb86a/
https://snipt.net/raw/ab4badc33bba13060c2c1076202fb86a/
ab4badc33bba13060c2c1076202fb86a
python
Python
8
2016-12-02T10:41:04
True
False
False
/api/public/snipt/13524/
django-image-proxy
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a> <a href="#L-7">7</a> <a href="#L-8">8</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="k">def</span> <span class="nf">proxy</span><span class="p">(</span><span class="n">request</span><span class="p">):</span> </span><span id="L-2"><a name="L-2"></a> <span class="n">url</span> <span class="o">=</span> <span class="n">request</span><span class="o">.</span><span class="n">GET</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;url&#39;</span><span class="p">)</span> </span><span id="L-3"><a name="L-3"></a> <span class="k">if</span> <span class="n">url</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span> </span><span id="L-4"><a name="L-4"></a> <span class="k">try</span><span class="p">:</span> </span><span id="L-5"><a name="L-5"></a> <span class="n">img</span> <span class="o">=</span> <span class="n">urllib2</span><span class="o">.</span><span class="n">urlopen</span><span class="p">(</span><span class="n">url</span><span class="p">)</span> </span><span id="L-6"><a name="L-6"></a> <span class="k">return</span> <span class="n">HttpResponse</span><span class="p">(</span><span class="n">img</span><span class="o">.</span><span class="n">read</span><span class="p">(),</span> <span class="n">mimetype</span><span class="o">=</span><span class="n">img</span><span class="o">.</span><span class="n">info</span><span class="p">()</span><span class="o">.</span><span class="n">type</span><span class="p">)</span> </span><span id="L-7"><a name="L-7"></a> <span class="k">except</span> <span class="n">urllib2</span><span class="o">.</span><span class="n">URLError</span><span class="p">:</span> </span><span id="L-8"><a name="L-8"></a> <span class="k">return</span> <span class="n">HttpResponse</span><span class="p">(</span><span class="s1">&#39;Proxy failed.&#39;</span><span class="p">,</span> <span class="n">status</span><span class="o">=</span><span class="mi">404</span><span class="p">)</span> </span></pre></div> </td></tr></table>
django, proxy, python

Perl

Set up proxy for www::mechanize

1
2
3
4
5
my $site = 'http://site';
$ENV{HTTP_PROXY}  = 'http://proxy:8080';
$ENV{HTTPS_PROXY} = 'http://proxy:8080';
my $m = WWW::Mechanize->new( autocheck => 1, stack_depth => 1 );
$m->proxy( ['https'], '' );
https://snipt.net/embed/25fd84aff9be5cd0f6e74dadd8a767ef/
https://snipt.net/raw/25fd84aff9be5cd0f6e74dadd8a767ef/
25fd84aff9be5cd0f6e74dadd8a767ef
perl
Perl
5
2016-12-02T10:41:15
True
False
False
/api/public/snipt/616/
set-up-proxy-for-wwwmechanize
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="k">my</span> <span class="nv">$site</span> <span class="o">=</span> <span class="s">&#39;http://site&#39;</span><span class="p">;</span> </span><span id="L-2"><a name="L-2"></a><span class="nv">$ENV</span><span class="p">{</span><span class="n">HTTP_PROXY</span><span class="p">}</span> <span class="o">=</span> <span class="s">&#39;http://proxy:8080&#39;</span><span class="p">;</span> </span><span id="L-3"><a name="L-3"></a><span class="nv">$ENV</span><span class="p">{</span><span class="n">HTTPS_PROXY</span><span class="p">}</span> <span class="o">=</span> <span class="s">&#39;http://proxy:8080&#39;</span><span class="p">;</span> </span><span id="L-4"><a name="L-4"></a><span class="k">my</span> <span class="nv">$m</span> <span class="o">=</span> <span class="nn">WWW::</span><span class="n">Mechanize</span><span class="o">-&gt;</span><span class="k">new</span><span class="p">(</span> <span class="n">autocheck</span> <span class="o">=&gt;</span> <span class="mi">1</span><span class="p">,</span> <span class="n">stack_depth</span> <span class="o">=&gt;</span> <span class="mi">1</span> <span class="p">);</span> </span><span id="L-5"><a name="L-5"></a><span class="nv">$m</span><span class="o">-&gt;</span><span class="n">proxy</span><span class="p">(</span> <span class="p">[</span><span class="s">&#39;https&#39;</span><span class="p">],</span> <span class="s">&#39;&#39;</span> <span class="p">);</span> </span></pre></div> </td></tr></table>
mechanize, proxy
Copyrighted, illegal, or inappropriate content? Email [email protected].