snipt

Ctrl+h for KB shortcuts

Python

Regex for vi, remove all leading whitespace for a file.

%s/^\s\s*//g
https://snipt.net/embed/c012155e366d6d0fb0fbc71939b1a192/
/raw/c012155e366d6d0fb0fbc71939b1a192/
c012155e366d6d0fb0fbc71939b1a192
python
Python
1
2019-06-13T00:25:59
True
False
False
/api/public/snipt/23650/
regex-for-vi-remove-all-leading-whitespace-for-a-file
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="o">%</span><span class="n">s</span><span class="o">/^</span>\<span class="n">s</span>\<span class="n">s</span><span class="o">*//</span><span class="n">g</span> </span></pre></div> </td></tr></table>
regex, vi

Python

Sloppily convert all UTF values in a list to ASCII.

ascii_vals_list = map(str, list)
https://snipt.net/embed/3fe9b0aff696f6fa1d6198c39800fa52/
/raw/3fe9b0aff696f6fa1d6198c39800fa52/
3fe9b0aff696f6fa1d6198c39800fa52
python
Python
1
2019-06-10T06:22:04
True
False
False
/api/public/snipt/22069/
sloppily-convert-all-utf-values-in-a-list-to-ascii
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="n">ascii_vals_list</span> <span class="o">=</span> <span class="nb">map</span><span class="p">(</span><span class="nb">str</span><span class="p">,</span> <span class="nb">list</span><span class="p">)</span> </span></pre></div> </td></tr></table>
ascii, map, python

Batchfile

List all computer objects in all domains in a forest with their name and last modified date and time attribute.

dsquery * forestroot -filter "(&(objectCategory=Computer)(objectClass=Computer))" -attr name whenChanged -limit 0
https://snipt.net/embed/205f7e20de7286d22abfba9489c0ef8f/
/raw/205f7e20de7286d22abfba9489c0ef8f/
205f7e20de7286d22abfba9489c0ef8f
bat
Batchfile
2
2019-06-12T16:20:42
True
False
False
/api/public/snipt/21666/
list-all-computer-objects-in-all-domains-in-a-forest-with-their-name-and-last-modified-date-and-time-attribute
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>dsquery * forestroot -filter <span class="s2">&quot;(&amp;(objectCategory=Computer)(objectClass=Computer))&quot;</span> -attr name whenChanged -limit 0 </span></pre></div> </td></tr></table>
ad, computer, lastmod, ldap, windows

Batchfile

List all computer objects in the domain with their name and last modified date and time attributed.

dsquery * domainroot -filter "(&(objectCategory=Computer)(objectClass=Computer))" -attr name whenChanged -limit 0
https://snipt.net/embed/93ec9d1a4ecb971deffc76f117e81f8a/
/raw/93ec9d1a4ecb971deffc76f117e81f8a/
93ec9d1a4ecb971deffc76f117e81f8a
bat
Batchfile
1
2019-06-14T13:39:08
True
False
False
/api/public/snipt/21665/
list-all-computer-objects-in-the-domain-with-their-name-and-last-modified-date-and-time-attributed
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>dsquery * domainroot -filter <span class="s2">&quot;(&amp;(objectCategory=Computer)(objectClass=Computer))&quot;</span> -attr name whenChanged -limit 0 </span></pre></div> </td></tr></table>
ad, computer, lastmod, ldap, windows

Batchfile

Get user group membership info, search all domains in a forest.

dsquery user forestroot -name “username” | dsget user -memberof
https://snipt.net/embed/924332e78f9242eb0140d7bd97d12772/
/raw/924332e78f9242eb0140d7bd97d12772/
924332e78f9242eb0140d7bd97d12772
bat
Batchfile
2
2019-06-13T09:39:22
True
False
False
/api/public/snipt/21649/
get-user-group-membership-info-search-all-domains-in-a-forest
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>dsquery user forestroot -name “username” <span class="p">|</span> dsget user -memberof </span></pre></div> </td></tr></table>
ad, ldap, user-membership, windows

Batchfile

Enumerate users in Windows AD group.

dsquery group -name “Group Name Here” | dsget group -members -expand
https://snipt.net/embed/9e86f4043196017b27be3ca8a55a6d77/
/raw/9e86f4043196017b27be3ca8a55a6d77/
9e86f4043196017b27be3ca8a55a6d77
bat
Batchfile
1
2019-06-15T12:02:25
True
False
False
/api/public/snipt/21647/
enumerate-users-in-windows-ad-group
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>dsquery group -name “Group Name Here” <span class="p">|</span> dsget group -members -expand </span></pre></div> </td></tr></table>
ad, ldap, windows

Python

Check files for location of indentation error.

python -m tabnanny scriptname.py
https://snipt.net/embed/56e287cdc0a98ce1cb5e87b773e4d280/
/raw/56e287cdc0a98ce1cb5e87b773e4d280/
56e287cdc0a98ce1cb5e87b773e4d280
python
Python
1
2019-06-15T03:10:16
True
False
False
/api/public/snipt/21222/
check-files-for-location-of-indentation-error
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="n">python</span> <span class="o">-</span><span class="n">m</span> <span class="n">tabnanny</span> <span class="n">scriptname</span><span class="o">.</span><span class="n">py</span> </span></pre></div> </td></tr></table>
formatting, python, standards, tab

Python

Check object type of var.

1
2
3
4
if isinstance(varname, float):
    # Do this
else:
    # Do that
https://snipt.net/embed/5ba94b57d7fb23ae7409d7a0eb6314c4/
/raw/5ba94b57d7fb23ae7409d7a0eb6314c4/
5ba94b57d7fb23ae7409d7a0eb6314c4
python
Python
5
2019-06-15T12:02:43
True
False
False
/api/public/snipt/21182/
check-object-type-of-var
<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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">varname</span><span class="p">,</span> <span class="nb">float</span><span class="p">):</span> </span><span id="L-2"><a name="L-2"></a> <span class="c1"># Do this</span> </span><span id="L-3"><a name="L-3"></a><span class="k">else</span><span class="p">:</span> </span><span id="L-4"><a name="L-4"></a> <span class="c1"># Do that</span> </span></pre></div> </td></tr></table>
object, python, type

Python

Short generator example.

g = (x**2 for x in range(10))
print g.next()
https://snipt.net/embed/009b8073d5dca4ad358b31d9346b8768/
/raw/009b8073d5dca4ad358b31d9346b8768/
009b8073d5dca4ad358b31d9346b8768
python
Python
3
2019-06-11T15:35:24
True
False
False
/api/public/snipt/20976/
short-generator-example
<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="n">g</span> <span class="o">=</span> <span class="p">(</span><span class="n">x</span><span class="o">**</span><span class="mi">2</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">10</span><span class="p">))</span> </span><span id="L-2"><a name="L-2"></a><span class="k">print</span> <span class="n">g</span><span class="o">.</span><span class="n">next</span><span class="p">()</span> </span></pre></div> </td></tr></table>
generator, python

Python

Generate random 5 digit number string in Python.

'%05i'%random.randint(0,99999) 
https://snipt.net/embed/ebef66be35714ef72f6b8cbc1e7e9fa3/
/raw/ebef66be35714ef72f6b8cbc1e7e9fa3/
ebef66be35714ef72f6b8cbc1e7e9fa3
python
Python
1
2019-06-16T04:11:59
True
False
False
/api/public/snipt/20951/
generate-random-5-digit-number-string-in-python
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="s1">&#39;</span><span class="si">%05i</span><span class="s1">&#39;</span><span class="o">%</span><span class="n">random</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">99999</span><span class="p">)</span> </span></pre></div> </td></tr></table>
python, string