Snipt.net is closing on December 31st, 2016

For more information, please visit this blog post.

snipt

Ctrl+h for KB shortcuts

C#

Get MD5 Hash

1
2
3
4
5
6
7
public static string GetHash(string str)
{
    using (var md5 = MD5.Create())
    {
        return BitConverter.ToString(md5.ComputeHash(Encoding.UTF8.GetBytes(str))).Replace("-", "").ToLower();
    }
}
https://snipt.net/embed/d0fb91df388e6d9e725fe69d6e1278aa/
https://snipt.net/raw/d0fb91df388e6d9e725fe69d6e1278aa/
d0fb91df388e6d9e725fe69d6e1278aa
csharp
C#
7
2016-12-07T22:46:44
True
False
False
Apr 07, 2016 at 01:06 PM
/api/public/snipt/145244/
get-md5-hash
<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">public</span> <span class="k">static</span> <span class="kt">string</span> <span class="nf">GetHash</span><span class="p">(</span><span class="kt">string</span> <span class="n">str</span><span class="p">)</span> </span><span id="L-2"><a name="L-2"></a><span class="p">{</span> </span><span id="L-3"><a name="L-3"></a> <span class="k">using</span> <span class="p">(</span><span class="kt">var</span> <span class="n">md5</span> <span class="p">=</span> <span class="n">MD5</span><span class="p">.</span><span class="n">Create</span><span class="p">())</span> </span><span id="L-4"><a name="L-4"></a> <span class="p">{</span> </span><span id="L-5"><a name="L-5"></a> <span class="k">return</span> <span class="n">BitConverter</span><span class="p">.</span><span class="n">ToString</span><span class="p">(</span><span class="n">md5</span><span class="p">.</span><span class="n">ComputeHash</span><span class="p">(</span><span class="n">Encoding</span><span class="p">.</span><span class="n">UTF8</span><span class="p">.</span><span class="n">GetBytes</span><span class="p">(</span><span class="n">str</span><span class="p">))).</span><span class="n">Replace</span><span class="p">(</span><span class="s">&quot;-&quot;</span><span class="p">,</span> <span class="s">&quot;&quot;</span><span class="p">).</span><span class="n">ToLower</span><span class="p">();</span> </span><span id="L-6"><a name="L-6"></a> <span class="p">}</span> </span><span id="L-7"><a name="L-7"></a><span class="p">}</span> </span></pre></div> </td></tr></table>
hash, md5

Bash

get file MD5

file="/path/to/some/file"
md5=$(md5sum "$file" 2>/dev/null | awk '{print $1}')
https://snipt.net/embed/7502b80883172beaabff83951c07909a/
https://snipt.net/raw/7502b80883172beaabff83951c07909a/
7502b80883172beaabff83951c07909a
bash
Bash
2
2016-12-10T07:48:19
True
False
False
Oct 01, 2015 at 05:07 AM
/api/public/snipt/141374/
get-file-md5
<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="nv">file</span><span class="o">=</span><span class="s2">&quot;/path/to/some/file&quot;</span> </span><span id="L-2"><a name="L-2"></a><span class="nv">md5</span><span class="o">=</span><span class="k">$(</span>md5sum <span class="s2">&quot;</span><span class="nv">$file</span><span class="s2">&quot;</span> 2&gt;/dev/null <span class="p">|</span> awk <span class="s1">&#39;{print $1}&#39;</span><span class="k">)</span> </span></pre></div> </td></tr></table>
hash, linux, md5

Bash

show short hash of current git head commit

git log --pretty=format:'%h' -n 1
https://snipt.net/embed/acbe195ff011d55cb5d38849171fca2d/
https://snipt.net/raw/acbe195ff011d55cb5d38849171fca2d/
acbe195ff011d55cb5d38849171fca2d
bash
Bash
1
2016-12-10T06:48:42
True
False
False
May 29, 2014 at 02:55 PM
/api/public/snipt/135195/
show-short-hash-of-current-git-head-commit-c244cd54
<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>git log --pretty<span class="o">=</span>format:<span class="s1">&#39;%h&#39;</span> -n 1 </span></pre></div> </td></tr></table>
git, hash, sha

Python

Hash string to SHA1 in Python

1
2
3
4
import hashlib
m = hashlib.sha1()
m.update("hash me!")
m.hexdigest()
https://snipt.net/embed/fccd6ec779c5779a1f48f3123dab2d81/
https://snipt.net/raw/fccd6ec779c5779a1f48f3123dab2d81/
fccd6ec779c5779a1f48f3123dab2d81
python
Python
4
2016-12-10T05:29:21
True
False
False
/api/public/snipt/41843/
hash-string-to-sha1-in-python
<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="kn">import</span> <span class="nn">hashlib</span> </span><span id="L-2"><a name="L-2"></a><span class="n">m</span> <span class="o">=</span> <span class="n">hashlib</span><span class="o">.</span><span class="n">sha1</span><span class="p">()</span> </span><span id="L-3"><a name="L-3"></a><span class="n">m</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="s2">&quot;hash me!&quot;</span><span class="p">)</span> </span><span id="L-4"><a name="L-4"></a><span class="n">m</span><span class="o">.</span><span class="n">hexdigest</span><span class="p">()</span> </span></pre></div> </td></tr></table>
hash, password, sha1

S

r hash demo

1
2
3
4
5
6
7
8
library("hash")
h <- hash()
h <- hash(1,1)
has.key("2",h)
.set(h,keys=2,values=3)
for (i in keys(h)){show(as.numeric(i)+2)}

if (has.key("3",h)){show("yeah")}else{cat("no")}
https://snipt.net/embed/2c89b21c29704d3a168761fbe001d702/
https://snipt.net/raw/2c89b21c29704d3a168761fbe001d702/
2c89b21c29704d3a168761fbe001d702
splus
S
8
2016-12-10T04:15:56
True
False
False
/api/public/snipt/23186/
r-hash-demo
<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="kn">library</span><span class="p">(</span><span class="s">&quot;hash&quot;</span><span class="p">)</span> </span><span id="L-2"><a name="L-2"></a>h <span class="o">&lt;-</span> hash<span class="p">()</span> </span><span id="L-3"><a name="L-3"></a>h <span class="o">&lt;-</span> hash<span class="p">(</span><span class="m">1</span><span class="p">,</span><span class="m">1</span><span class="p">)</span> </span><span id="L-4"><a name="L-4"></a>has.key<span class="p">(</span><span class="s">&quot;2&quot;</span><span class="p">,</span>h<span class="p">)</span> </span><span id="L-5"><a name="L-5"></a><span class="m">.</span>set<span class="p">(</span>h<span class="p">,</span>keys<span class="o">=</span><span class="m">2</span><span class="p">,</span>values<span class="o">=</span><span class="m">3</span><span class="p">)</span> </span><span id="L-6"><a name="L-6"></a><span class="kr">for</span> <span class="p">(</span>i <span class="kr">in</span> keys<span class="p">(</span>h<span class="p">)){</span>show<span class="p">(</span><span class="kp">as.numeric</span><span class="p">(</span>i<span class="p">)</span><span class="m">+2</span><span class="p">)}</span> </span><span id="L-7"><a name="L-7"></a> </span><span id="L-8"><a name="L-8"></a><span class="kr">if</span> <span class="p">(</span>has.key<span class="p">(</span><span class="s">&quot;3&quot;</span><span class="p">,</span>h<span class="p">)){</span>show<span class="p">(</span><span class="s">&quot;yeah&quot;</span><span class="p">)}</span><span class="kp">else</span><span class="p">{</span><span class="kp">cat</span><span class="p">(</span><span class="s">&quot;no&quot;</span><span class="p">)}</span> </span></pre></div> </td></tr></table>
hash, r
Copyrighted, illegal, or inappropriate content? Email [email protected].