snipt

Ctrl+h for KB shortcuts

NumPy

Dump Numpy array in a csv text file

savetxt("foo.csv", dataArray, delimiter="\t")
https://snipt.net/embed/4a1202477b401ee4905348097869871a/
/raw/4a1202477b401ee4905348097869871a/
4a1202477b401ee4905348097869871a
numpy
NumPy
1
2019-08-15T04:52:00
True
False
False
Dec 14, 2012 at 09:26 AM
/api/public/snipt/51845/
dump-numpy-array-in-a-csv-text-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="kp">savetxt</span><span class="p">(</span><span class="s2">&quot;foo.csv&quot;</span><span class="p">,</span> <span class="n">dataArray</span><span class="p">,</span> <span class="n">delimiter</span><span class="o">=</span><span class="s2">&quot;</span><span class="se">\t</span><span class="s2">&quot;</span><span class="p">)</span> </span></pre></div> </td></tr></table>
Numpy, array, csv, save, text

Java

java creating and saving a screenshot

1
2
3
4
5
6
      Robot robot = new Robot();
      BufferedImage screen = robot.createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit()
          .getScreenSize()));
      ImageIO.write(screen, "jpeg", new File("d:/screen.jpeg"));
      ImageIO.write(screen, "bmp", new File("d:/screen.bmp"));
      ImageIO.write(screen, "png", new File("d:/screen.png"));
https://snipt.net/embed/2ed6797b22560abf6d9f941ee0c83676/
/raw/2ed6797b22560abf6d9f941ee0c83676/
2ed6797b22560abf6d9f941ee0c83676
java
Java
6
2019-08-18T13:37:26
True
False
False
/api/public/snipt/27465/
java-creating-and-saving-a-screenshot
<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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a> <span class="n">Robot</span> <span class="n">robot</span> <span class="o">=</span> <span class="k">new</span> <span class="n">Robot</span><span class="o">();</span> </span><span id="L-2"><a name="L-2"></a> <span class="n">BufferedImage</span> <span class="n">screen</span> <span class="o">=</span> <span class="n">robot</span><span class="o">.</span><span class="na">createScreenCapture</span><span class="o">(</span><span class="k">new</span> <span class="n">Rectangle</span><span class="o">(</span><span class="n">Toolkit</span><span class="o">.</span><span class="na">getDefaultToolkit</span><span class="o">()</span> </span><span id="L-3"><a name="L-3"></a> <span class="o">.</span><span class="na">getScreenSize</span><span class="o">()));</span> </span><span id="L-4"><a name="L-4"></a> <span class="n">ImageIO</span><span class="o">.</span><span class="na">write</span><span class="o">(</span><span class="n">screen</span><span class="o">,</span> <span class="s">&quot;jpeg&quot;</span><span class="o">,</span> <span class="k">new</span> <span class="n">File</span><span class="o">(</span><span class="s">&quot;d:/screen.jpeg&quot;</span><span class="o">));</span> </span><span id="L-5"><a name="L-5"></a> <span class="n">ImageIO</span><span class="o">.</span><span class="na">write</span><span class="o">(</span><span class="n">screen</span><span class="o">,</span> <span class="s">&quot;bmp&quot;</span><span class="o">,</span> <span class="k">new</span> <span class="n">File</span><span class="o">(</span><span class="s">&quot;d:/screen.bmp&quot;</span><span class="o">));</span> </span><span id="L-6"><a name="L-6"></a> <span class="n">ImageIO</span><span class="o">.</span><span class="na">write</span><span class="o">(</span><span class="n">screen</span><span class="o">,</span> <span class="s">&quot;png&quot;</span><span class="o">,</span> <span class="k">new</span> <span class="n">File</span><span class="o">(</span><span class="s">&quot;d:/screen.png&quot;</span><span class="o">));</span> </span></pre></div> </td></tr></table>
awt, file, image, java, robot, save, screenshot, toolkit

Python

Assign user to model field before save in django admin

1
2
3
4
5
6
7
class AccountAdmin(admin.ModelAdmin):
    ...
    
    def save_model(self, request, model, form, change):
        """Autosave the user and other data""" 
        model.created_by = request.user
        super(AccountAdmin, self).save_model(request, model, form, change)
https://snipt.net/embed/b2d565a28fa9a2cc11abbf71f72d7fc4/
/raw/b2d565a28fa9a2cc11abbf71f72d7fc4/
b2d565a28fa9a2cc11abbf71f72d7fc4
python
Python
7
2019-08-15T17:40:53
True
False
False
/api/public/snipt/25664/
assign-user-to-model-field-before-save-in-django-admin
<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">class</span> <span class="nc">AccountAdmin</span><span class="p">(</span><span class="n">admin</span><span class="o">.</span><span class="n">ModelAdmin</span><span class="p">):</span> </span><span id="L-2"><a name="L-2"></a> <span class="o">...</span> </span><span id="L-3"><a name="L-3"></a> </span><span id="L-4"><a name="L-4"></a> <span class="k">def</span> <span class="nf">save_model</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">request</span><span class="p">,</span> <span class="n">model</span><span class="p">,</span> <span class="n">form</span><span class="p">,</span> <span class="n">change</span><span class="p">):</span> </span><span id="L-5"><a name="L-5"></a> <span class="sd">&quot;&quot;&quot;Autosave the user and other data&quot;&quot;&quot;</span> </span><span id="L-6"><a name="L-6"></a> <span class="n">model</span><span class="o">.</span><span class="n">created_by</span> <span class="o">=</span> <span class="n">request</span><span class="o">.</span><span class="n">user</span> </span><span id="L-7"><a name="L-7"></a> <span class="nb">super</span><span class="p">(</span><span class="n">AccountAdmin</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="n">save_model</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="n">model</span><span class="p">,</span> <span class="n">form</span><span class="p">,</span> <span class="n">change</span><span class="p">)</span> </span></pre></div> </td></tr></table>
django, modeladmin, python, save, user

JavaScript

Save YouTube Video

javascript:if(document.location.href.match(/http:\/\/[a-zA-Z\.]*youtube\.com\/watch/)){document.location.href='http://www.youtube.com/get_video?fmt=18&video_id='+swfArgs['video_id']+'&t='+swfArgs['t']}
https://snipt.net/embed/a2896701e19056292ae62506c6424978/
/raw/a2896701e19056292ae62506c6424978/
a2896701e19056292ae62506c6424978
js
JavaScript
1
2019-08-14T16:16:45
True
False
False
/api/public/snipt/1147/
save-youtube-video
<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="nx">javascript</span><span class="o">:</span><span class="k">if</span><span class="p">(</span><span class="nb">document</span><span class="p">.</span><span class="nx">location</span><span class="p">.</span><span class="nx">href</span><span class="p">.</span><span class="nx">match</span><span class="p">(</span><span class="sr">/http:\/\/[a-zA-Z\.]*youtube\.com\/watch/</span><span class="p">)){</span><span class="nb">document</span><span class="p">.</span><span class="nx">location</span><span class="p">.</span><span class="nx">href</span><span class="o">=</span><span class="s1">&#39;http://www.youtube.com/get_video?fmt=18&amp;video_id=&#39;</span><span class="o">+</span><span class="nx">swfArgs</span><span class="p">[</span><span class="s1">&#39;video_id&#39;</span><span class="p">]</span><span class="o">+</span><span class="s1">&#39;&amp;t=&#39;</span><span class="o">+</span><span class="nx">swfArgs</span><span class="p">[</span><span class="s1">&#39;t&#39;</span><span class="p">]}</span> </span></pre></div> </td></tr></table>
javascript, save, video, youtube