Septian's Notehttp://notes.septianw.web.id/2015-09-23T09:32:00+07:00SSH port forwarding2015-09-23T09:32:00+07:00Septian Wibisonotag:notes.septianw.web.id,2015-09-23:SSH-port-forwarding.html<p>I always forgetting it, and spend alot of time to find the solution in google and browsers history. Now i write it here to simplify my life and speedup the progress.</p>
<h5>To make SSH as socks proxy</h5>
<div class="highlight"><pre><span class="nv">$ </span>ssh -D 5000 -N theservername
</pre></div>
<p>Example :</p>
<div class="highlight"><pre><span class="nv">$ </span>ssh -D 5000 -N 10.1.10.10
</pre></div>
<p>now, configure your global OS proxy or browser proxy to localhost port 5000 and check your public IP from http://ifconfig.me/ip it shall return your ssh machine public IP.</p>
<h5>Only forward some port to your local port</h5>
<div class="highlight"><pre><span class="nv">$ </span>ssh -L 3000:google.com:80 user@proxy
</pre></div>
<p>Example :</p>
<div class="highlight"><pre><span class="nv">$ </span>ssh -L 3000:google.com:80 user@10.1.10.10
</pre></div>
<p>Now, we can reach google.com from localhost:3000. Those command will also logging you in there. Use parameter <code>-N</code> after ssh to only tunneling without logging in.</p>
<p>I got this from <a href="http://security.stackexchange.com/questions/31226/how-can-i-tunnel-through-an-ssh-server-for-https-requests">Security stackexchange</a> and <a href="https://help.ubuntu.com/community/SSH/OpenSSH/PortForwarding">Ubuntu documentation</a></p>nodejs, find first 100 prime number2015-06-06T08:09:00+07:00Septian Wibisonotag:notes.septianw.web.id,2015-06-06:nodejs--find-first-100-prime-number.html<p>Yesterday, when i'm idle and curious, i'm wondering about prime number. Since i'm suck at math, i find it with the suck way. I'm using nodejs because its simple to scripting and cheap on resource. Here is the code :</p>
<div class="highlight"><pre><span class="kd">var</span> <span class="nx">stash</span> <span class="o">=</span> <span class="p">[];</span>
<span class="k">for</span> <span class="p">(</span><span class="kd">var</span> <span class="nx">i</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span> <span class="nx">i</span><span class="o"><</span><span class="mi">100</span><span class="p">;</span> <span class="nx">i</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">tmp</span> <span class="o">=</span> <span class="p">{</span><span class="nx">ke</span><span class="o">:</span> <span class="nx">i</span><span class="p">,</span> <span class="nx">loop</span><span class="o">:</span> <span class="p">[]};</span>
<span class="k">for</span> <span class="p">(</span><span class="kd">var</span> <span class="nx">k</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span> <span class="nx">k</span><span class="o"><</span><span class="mi">100</span><span class="p">;</span> <span class="nx">k</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">((</span><span class="nx">i</span><span class="o">%</span><span class="nx">k</span> <span class="o">==</span> <span class="mi">0</span><span class="p">))</span> <span class="p">{</span>
<span class="nx">tmp</span><span class="p">.</span><span class="nx">loop</span><span class="p">.</span><span class="nx">push</span><span class="p">(</span><span class="nx">k</span><span class="p">);</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="nx">stash</span><span class="p">.</span><span class="nx">push</span><span class="p">(</span><span class="nx">tmp</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">for</span> <span class="p">(</span><span class="kd">var</span> <span class="nx">u</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span> <span class="nx">u</span><span class="o"><</span><span class="nx">stash</span><span class="p">.</span><span class="nx">length</span><span class="p">;</span> <span class="nx">u</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span> <span class="nx">stash</span><span class="p">[</span><span class="nx">u</span><span class="p">].</span><span class="nx">loop</span><span class="p">.</span><span class="nx">length</span> <span class="o">==</span> <span class="mi">2</span> <span class="p">)</span> <span class="p">{</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">stash</span><span class="p">[</span><span class="nx">u</span><span class="p">].</span><span class="nx">ke</span><span class="p">);</span>
<span class="p">}</span>
<span class="p">}</span>
</pre></div>One line tar gz2015-03-16T21:58:00+07:00Septian Wibisonotag:notes.septianw.web.id,2015-03-16:one-line-tar-gz.html<p>tar.gz is de facto standard of file compressing on unix like system. why? powerful and cheap. I got this from <a href="http://www.commandlinefu.com/commands/view/2217/create-a-tar.gz-in-a-single-command">here</a> the command to make it on one line.</p>
<div class="highlight"><pre>tar cvf - foodir | gzip > foo.tar.gz
</pre></div>
<p>Option <code>c</code> stand for <code>-c, --create create a new archive</code> and</p>
<p><code>v</code> stand for <code>-v, --verbose verbosely list files processed</code> and</p>
<p><code>f</code> stand for <code>-f, --file=ARCHIVE use archive file or device ARCHIVE</code></p>
<p>To make better compression use option <code>-9</code> on gzip. Here is my version of one line command to make .tar.gz package.</p>
<div class="highlight"><pre>tar cvf - foodir | gzip -9 > foo.tar.gz
</pre></div>Bash string operator2014-12-18T16:32:00+07:00Septian Wibisonotag:notes.septianw.web.id,2014-12-18:bash-string-operator.html<p>Since i keep forgetting it, i'll write it here</p>
<p>TL;DR</p>
<div class="highlight"><pre><span class="nv">url</span><span class="o">=</span><span class="s2">"http://www.example.com/path/to/dir/file.txt"</span>
<span class="nb">echo</span> <span class="k">${</span><span class="nv">url</span><span class="p">##*/</span><span class="k">}</span>
<span class="c"># file.txt</span>
<span class="nb">echo</span> <span class="k">${</span><span class="nv">url</span><span class="p">#*/</span><span class="k">}</span>
<span class="c"># /www.example.com/path/to/dir/file.txt</span>
<span class="nb">echo</span> <span class="k">${</span><span class="nv">url</span><span class="p">%%.*</span><span class="k">}</span>
<span class="c"># http://www</span>
<span class="nb">echo</span> <span class="k">${</span><span class="nv">url</span><span class="p">%:*</span><span class="k">}</span>
<span class="c"># http</span>
</pre></div>
<p>Explanation</p>
<div class="highlight"><pre><span class="o">$</span><span class="p">{</span>
url <span class="o"><-</span> from variable url
<span class="c1">## <- greedy trim from left or %% from right swapable</span>
<span class="o">*</span> <span class="o"><-</span> match anything swapable
<span class="o">/</span> <span class="o"><-</span> until found <span class="s">"/"</span> character swapable
<span class="p">}</span>
</pre></div>
<p><a href="http://stackoverflow.com/questions/3162385/how-to-split-a-string-in-shell-and-get-the-last-field">Another answer</a> and full explanation <a href="http://www.linuxjournal.com/article/8919">here</a> In case of broken link i'll copy whole article below</p>
<hr />
<p>Variable Mangling in Bash with String Operators</p>
<p>Mar 13, 2006 By Pat Eyler</p>
<p>inLinux Journal</p>
<p>Here's a quick and updated HOWTO for using string operators in bash to manipulate variables.
Editor's Note: This article has been updated by its author. Thank you, Pat.</p>
<p>Have you ever wanted to change the names of many files at once? Or, have you ever needed to use a default value for a variable that has no value? These and many other options are available to you when you use string operators in bash and other Bourne-derived shells.</p>
<p>String operators allow you to manipulate the contents of a variable without having to write your own shell functions to do so. They are provided through "curly brace" syntax. Any variable can be displayed as ${foo} without changing its meaning. This functionality often is used to protect a variable name from surrounding characters.</p>
<div class="highlight"><pre><span class="nv">$ </span><span class="nb">export </span><span class="nv">foo</span><span class="o">=</span>foo
<span class="nv">$ </span><span class="nb">echo</span> <span class="k">${</span><span class="nv">foo</span><span class="k">}</span>bar <span class="c"># foo exists so this works as expected</span>
foobar
<span class="nv">$ </span><span class="nb">echo</span> <span class="nv">$foobar</span> <span class="c"># foobar doesn't exist, so this doesn't</span>
</pre></div>
<p>By the end of this article, you'll be able to use it for a whole lot more.</p>
<p>Three kinds of variable substitution are available for use: pattern matching, substitution and command substitution. I talk about the first two variables here and leave command substitution for another time.</p>
<p>Pattern Matching
In pattern matching, you can match from the left or from the right. The operators, along with their functions and examples, are shown below:</p>
<p>Operator: ${foo#t*is}</p>
<p>Function: deletes the shortest possible match from the left</p>
<p>Example:</p>
<div class="highlight"><pre><span class="nv">$ </span><span class="nb">export </span><span class="nv">foo</span><span class="o">=</span><span class="s2">"this is a test"</span>
<span class="nv">$ </span><span class="nb">echo</span> <span class="k">${</span><span class="nv">foo</span><span class="p">#t*is</span><span class="k">}</span>
is a <span class="nb">test</span>
<span class="err">$</span>
</pre></div>
<p>Operator: ${foo##t*is}</p>
<p>Function: deletes the longest possible match from the left</p>
<p>Example:</p>
<div class="highlight"><pre><span class="nv">$ </span><span class="nb">export </span><span class="nv">foo</span><span class="o">=</span><span class="s2">"this is a test"</span>
<span class="nv">$ </span><span class="nb">echo</span> <span class="k">${</span><span class="nv">foo</span><span class="p">##t*is</span><span class="k">}</span>
a <span class="nb">test</span>
<span class="err">$</span>
</pre></div>
<p>Operator: ${foo%t*st}</p>
<p>Function: deletes the shortest possible match from the right</p>
<p>Example:</p>
<div class="highlight"><pre><span class="nv">$ </span><span class="nb">export </span><span class="nv">foo</span><span class="o">=</span><span class="s2">"this is a test"</span>
<span class="nv">$ </span><span class="nb">echo</span> <span class="k">${</span><span class="nv">foo</span><span class="p">%t*st</span><span class="k">}</span>
this is a
<span class="err">$</span>
</pre></div>
<p>Operator: ${foo%%t*st}</p>
<p>Function: deletes the longest possible match from the right</p>
<p>Example:</p>
<div class="highlight"><pre><span class="nv">$ </span><span class="nb">export </span><span class="nv">foo</span><span class="o">=</span><span class="s2">"this is a test"</span>
<span class="nv">$ </span><span class="nb">echo</span> <span class="k">${</span><span class="nv">foo</span><span class="p">%%t*st</span><span class="k">}</span>
<span class="err">$</span>
</pre></div>
<p>Although the # and % identifiers may not seem obvious, they have a convenient mnemonic. The # key is on the left side of the $ key and operates from the left. The % key is on the right of the $ key and operates from the right. (This is true, at least, for US qwerty keyboards.)</p>
<p>The operators listed above can be used to do a variety of things. For example, the following script changes the extension of all .html files so they now are .htm files.</p>
<div class="highlight"><pre><span class="c">#!/bin/bash </span>
<span class="c"># quickly convert html filenames for use on a dossy system</span>
<span class="c"># only handles file extensions, not file names</span>
<span class="k">for </span>i in *.html; <span class="k">do</span>
<span class="k"> if</span> <span class="o">[</span> -f <span class="k">${</span><span class="nv">i</span><span class="p">%l</span><span class="k">}</span> <span class="o">]</span>; <span class="k">then </span>
<span class="k"> </span><span class="nb">echo</span> <span class="s2">"${i%l} already exists"</span>
<span class="k">else </span>
<span class="k"> </span>mv <span class="nv">$i</span> <span class="k">${</span><span class="nv">i</span><span class="p">%l</span><span class="k">}</span>
<span class="k">fi </span>
<span class="k">done</span>
</pre></div>
<p>Substitution
Another kind of variable mangling you might want to employ is substitution. Four substitution operators are used in Bash, and they are shown below:</p>
<p>Operator: ${foo:-bar}</p>
<p>Function: If $foo exists and is not null, return $foo. If it doesn't exist or is null, return bar.</p>
<p>Example:</p>
<div class="highlight"><pre><span class="nv">$ </span><span class="nb">export </span><span class="nv">foo</span><span class="o">=</span><span class="s2">""</span>
<span class="nv">$ </span><span class="nb">echo</span> <span class="k">${</span><span class="nv">foo</span><span class="k">:-</span><span class="nv">one</span><span class="k">}</span>
one
<span class="nv">$ </span><span class="nb">echo</span> <span class="nv">$foo</span>
<span class="err">$</span>
</pre></div>
<p>Operator: ${foo:=bar}</p>
<p>Function: If $foo exists and is not null, return $foo. If it doesn't exist or is null, set $foo to bar and return bar.</p>
<p>Example:</p>
<div class="highlight"><pre><span class="nv">$ </span><span class="nb">export </span><span class="nv">foo</span><span class="o">=</span><span class="s2">""</span>
<span class="nv">$ </span><span class="nb">echo</span> <span class="k">${</span><span class="nv">foo</span><span class="p">:=one</span><span class="k">}</span>
one
<span class="nv">$ </span><span class="nb">echo</span> <span class="nv">$foo</span>
one
<span class="err">$</span>
</pre></div>
<p>Operator: ${foo:+bar}</p>
<p>Function: If $foo exists and is not null, return bar. If it doesn't exist or is null, return a null.</p>
<p>Example:</p>
<div class="highlight"><pre><span class="nv">$ </span><span class="nb">export </span><span class="nv">foo</span><span class="o">=</span><span class="s2">"this is a test"</span>
<span class="nv">$ </span><span class="nb">echo</span> <span class="k">${</span><span class="nv">foo</span><span class="p">:+bar</span><span class="k">}</span>
bar
<span class="err">$</span>
</pre></div>
<p>Operator: ${foo:?"error message"}</p>
<p>Function: If $foo exists and isn't null, return its value. If it doesn't exist or is null, print the error message. If no error message is given, it prints parameter null or not set. In a non-interactive shell, this aborts the current script. In an interactive shell, this simply prints the error message.</p>
<p>Example:</p>
<div class="highlight"><pre><span class="nv">$ </span><span class="nb">export </span><span class="nv">foo</span><span class="o">=</span><span class="s2">"one"</span>
<span class="nv">$ </span><span class="k">for </span>i in foo bar baz; <span class="k">do</span>
> <span class="nb">eval echo</span> <span class="se">\$</span><span class="o">{</span><span class="nv">$i</span>:?<span class="o">}</span>
> <span class="k">done</span>
one
bash: bar: parameter null or not <span class="nb">set</span>
bash: baz: parameter null or not <span class="nb">set</span>
<span class="err">$</span>
</pre></div>
<p>The : in the above operators can be omitted. Doing so changes the behavior of the operator so that it simply tests for the existence of the variable. This, in turn, causes the creation of a variable, for example:</p>
<div class="highlight"><pre><span class="nv">$ </span><span class="nb">export </span><span class="nv">foo</span><span class="o">=</span><span class="s2">"this is a test"</span>
<span class="nv">$ </span><span class="nb">echo</span> <span class="nv">$bar</span>
<span class="nv">$ </span><span class="nb">echo</span> <span class="k">${</span><span class="nv">foo</span><span class="p">=bar</span><span class="k">}</span>
this is a <span class="nb">test</span>
<span class="nv">$ </span><span class="nb">echo</span> <span class="k">${</span><span class="nv">bar</span><span class="p">=bar</span><span class="k">}</span>
bar
<span class="nv">$ </span><span class="nb">echo</span> <span class="nv">$bar</span>
bar
<span class="err">$</span>
</pre></div>
<p>These operators can be used in a variety of ways. A good example would be, in the case when no arguments are given, to give a default value to a variable normally read from command-line arguments. This example is demonstrated in the following script:</p>
<div class="highlight"><pre><span class="c">#!/bin/bash </span>
<span class="nb">export </span><span class="nv">INFILE</span><span class="o">=</span><span class="k">${</span><span class="nv">1</span><span class="p">-</span><span class="s2">"infile"</span><span class="k">}</span>
<span class="nb">export </span><span class="nv">OUTFILE</span><span class="o">=</span><span class="k">${</span><span class="nv">2</span><span class="p">-</span><span class="s2">"outfile"</span><span class="k">}</span>
cat <span class="nv">$INFILE</span> > <span class="nv">$OUTFILE</span>
</pre></div>
<p>Copyright (c) 2005, 2000 by Pat Eyler. Originally published in Linux Gazette issue 57. Copyright (c) 2000, Specialized Systems Consultants, Inc. The material in this article may be distributed only subject to the terms and conditions set forth in the Open Publication License, v1.0 or later.</p>
<hr />
<p>-- -pate http://on-ruby.blogspot.com</p>calculating disk usage per mysql database scheme2014-12-18T16:32:00+07:00Septian Wibisonotag:notes.septianw.web.id,2014-12-18:calculating-disk-usage-per-mysql-database-scheme.html<p>Before you migrating your website, you need to count how many MB you need for the database. To count it you need this command in mysql. Run it as user that have access to information_schema database;</p>
<div class="highlight"><pre><span class="k">select</span> <span class="n">table_schema</span><span class="p">,</span> <span class="k">sum</span><span class="p">((</span><span class="n">data_length</span><span class="o">+</span><span class="n">index_length</span><span class="p">)</span><span class="o">/</span><span class="mi">1024</span><span class="o">/</span><span class="mi">1024</span><span class="p">)</span> <span class="k">AS</span> <span class="n">MB</span> <span class="k">from</span> <span class="n">information_schema</span><span class="p">.</span><span class="n">tables</span> <span class="k">group</span> <span class="k">by</span> <span class="mi">1</span><span class="p">;</span>
</pre></div>
<p>I take this from <a href="http://dba.stackexchange.com/questions/14337/calculating-disk-space-usage-per-mysql-db">Aaron Brown's answer here</a></p>give user right to some root command with sudo2014-12-18T16:32:00+07:00Septian Wibisonotag:notes.septianw.web.id,2014-12-18:give-user-right-to-some-root-command-with-sudo.html<p><img alt="xkcd lustration of sudo command" src="http://imgs.xkcd.com/comics/sandwich.png" /></p>
<p>Sudo is command to alter user privilege, sudo shall given to trusted user only. In ubuntu first user have this right. To use sudo user need to insert their password. All the sudo rule written on sudoers file. Here is the default content of ubuntu sudoers file.</p>
<div class="highlight"><pre><span class="c">#</span>
<span class="c"># This file MUST be edited with the 'visudo' command as root.</span>
<span class="c">#</span>
<span class="c"># Please consider adding local content in /etc/sudoers.d/ instead of</span>
<span class="c"># directly modifying this file.</span>
<span class="c">#</span>
<span class="c"># See the man page for details on how to write a sudoers file.</span>
<span class="c">#</span>
Defaults env_reset
Defaults mail_badpass
Defaults <span class="nv">secure_path</span><span class="o">=</span><span class="s2">"/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"</span>
<span class="c"># Host alias specification</span>
<span class="c"># User alias specification</span>
<span class="c"># Cmnd alias specification</span>
<span class="c"># User privilege specification</span>
root <span class="nv">ALL</span><span class="o">=(</span>ALL:ALL<span class="o">)</span> ALL
<span class="c"># Members of the admin group may gain root privileges</span>
%admin <span class="nv">ALL</span><span class="o">=(</span>ALL<span class="o">)</span> ALL
<span class="c"># Allow members of group sudo to execute any command</span>
%sudo <span class="nv">ALL</span><span class="o">=(</span>ALL:ALL<span class="o">)</span> ALL
<span class="c"># See sudoers(5) for more information on "#include" directives:</span>
<span class="c">#includedir /etc/sudoers.d</span>
</pre></div>
<p>There is 3 similar lines there :</p>
<div class="highlight"><pre>root <span class="nv">ALL</span><span class="o">=(</span>ALL:ALL<span class="o">)</span> ALL
%admin <span class="nv">ALL</span><span class="o">=(</span>ALL<span class="o">)</span> ALL
%sudo <span class="nv">ALL</span><span class="o">=(</span>ALL:ALL<span class="o">)</span> ALL
</pre></div>
<p>3 of it have the same pattern, here is the full pattern</p>
<p>[user|group] host=([altered to user:group])NOPASSWD:[comma separated commands or alias]</p>
<p>NOPASSWD mean user doesn't need any password to call specified command. Here is customized sudoers file for illustration.</p>
<div class="highlight"><pre><span class="c"># /etc/sudoers</span>
<span class="c"># This file MUST be edited with the 'visudo' command as root.</span>
<span class="c"># See the man page for details on how to write a sudoers file.</span>
<span class="c"># Defaults</span>
Defaults !lecture,tty_tickets,!fqdn
<span class="c"># Uncomment to allow members of group sudo to not need a password</span>
<span class="c"># %sudo ALL=NOPASSWD: ALL</span>
<span class="c"># Host alias specification</span>
<span class="c"># User alias specification</span>
<span class="c"># Cmnd alias specification</span>
Cmnd_Alias <span class="nv">USERS</span> <span class="o">=</span> /usr/sbin/useradd,/usr/sbin/userdel,/usr/sbin/usermod,/usr/bin/users
Cmnd_Alias <span class="nv">CH</span> <span class="o">=</span> /bin/chown,/bin/chmod
Cmnd_Alias <span class="nv">USM</span> <span class="o">=</span> USERS,CH
<span class="c"># User privilege specification</span>
root <span class="nv">ALL</span><span class="o">=(</span>ALL<span class="o">)</span> ALL
<span class="c"># Members of the admin group may gain root privileges</span>
%admin <span class="nv">ALL</span><span class="o">=(</span>ALL<span class="o">)</span> ALL
usm <span class="nv">localhost</span><span class="o">=(</span>root<span class="o">)</span>NOPASSWD:USM
</pre></div>
<p>Fom the example above, user usm have access to USM alias command as a root user without password.</p>
<p>I still find the source. i got this from somewhere forgotten place.</p>Setup git server with git-shell interactive in ubuntu2014-08-28T10:35:00+07:00Septian Wibisonotag:notes.septianw.web.id,2014-08-28:setup-git-server-with-git-shell-interactive-in-ubuntu.html<p>Git is popular DVCS (Distributed Version Control System) that become DeFacto standard VCS in the world. There is another DVCS like git out there, it's mercurial, but i prefer git for their community support. Git is flexible, it can act as a server and a client.</p>
<p>To setup git as a server you just need to initialize yout repository with option --bare and your repository will become server side repository. i won't write about setup user in this post, it's on another post, so here we go setting up git server with git-shell interactive.</p>
<p>I assume your git user is git, if your current git user using bash as shell, loginto it and create git-shell-command folder</p>
<div class="highlight"><pre><span class="gp">$</span> mkdir git-shell-command
</pre></div>
<p>Every shell script inside those folder will be available via git-shell interactive</p>
<div class="highlight"><pre><span class="gp">$</span> <span class="nb">cd </span>git-shell-command
<span class="gp">$</span> vim greeting
</pre></div>
<p>Here is content of greeting file</p>
<div class="highlight"><pre><span class="c">#!/bin/bash</span>
<span class="c"># this file reside in ~/git-shell-command/</span>
<span class="c"># if name of this file is greting so the full path will be ~/git-shell-command/greeting</span>
<span class="nb">echo</span> <span class="s2">"Hai stranger"</span>;
</pre></div>
<p>Save this file with :wq command in vim and set it as execute and read only. if you want to edit it change 500 with 700</p>
<div class="highlight"><pre><span class="gp">$</span> chmod 500 ~/git-shell-command/greeting
</pre></div>
<p>now, as a root, change git user shell to git-shell</p>
<div class="highlight"><pre><span class="gp">#</span> usermod -s <span class="k">$(</span>which git-shell<span class="k">)</span> git
</pre></div>
<p>From this point if your git user was set, you can login to ssh and test it with :</p>
<div class="highlight"><pre><span class="gp">$</span> ssh git@server
<span class="go">git> greeting</span>
<span class="go">Hai stranger</span>
<span class="go">git></span>
</pre></div>
<p><a href="http://git-scm.com/docs/git-shell.html">git-scm.com explain</a> detail part of git-shell, and <a href="http://planzero.org/blog/2012/10/24/hosting_an_admin-friendly_git_server_with_git-shell">this post explain</a> more detail step. <a href="https://gist.githubusercontent.com/ckalima/1364886/raw/1868f002ecf165739606ddeea28991b9880f7ee2/remgit.sh">this gist</a> may also inspire you to create another command.</p>Remove all unused kernel from /boot partition2014-07-18T14:16:00+07:00Septian Wibisonotag:notes.septianw.web.id,2014-07-18:remove-all-unused-kernel-from-boot-partition.html<p>Everytime we update the kernel, ubuntu does not remove the old kernel. If you always update your kernel you'll have a bunch of unused kernel in boot loader. It's not only make your boot loader looks dirty but also waste a disk space, especially if you have separate /boot partition.</p>
<p>/boot partition is needed when you have LVM or raid partition as a part of system. As i read it from <a href="http://ubuntugenius.wordpress.com/2011/01/08/ubuntu-cleanup-how-to-remove-all-unused-linux-kernel-headers-images-and-modules/">ubuntugenius</a> there is a one line command to clean up your old kernel. Here it is.</p>
<div class="highlight"><pre><span class="nv">$ </span>dpkg -l <span class="s1">'linux-*'</span> | sed <span class="s1">'/^ii/!d;/'</span><span class="s2">"$(uname -r | sed "</span>s/<span class="se">\(</span>.*<span class="se">\)</span>-<span class="se">\(</span><span class="o">[</span>^0-9<span class="o">]</span><span class="se">\+\)</span>/<span class="se">\1</span>/<span class="s2">")"</span><span class="s1">'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d'</span> | xargs sudo apt-get -y purge
</pre></div>nodejs module.exports behavior2014-07-15T05:44:00+07:00Septian Wibisonotag:notes.septianw.web.id,2014-07-15:nodejs-module.exports-behavior.html<p>For more than a month, i've been working with project that involving nodejs. For someone who does not have javascript background like me, it was very tiring. I will tell another story in another post, but now i'll post about module.exports behavior.</p>
<p>Let's check following code</p>
<p>Ther first code</p>
<div class="highlight"><pre><span class="nx">module</span><span class="p">.</span><span class="nx">exports</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">db</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">schema</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">'../../config/schema.js'</span><span class="p">).</span><span class="nx">user</span><span class="p">(</span><span class="nx">db</span><span class="p">.</span><span class="nx">Schema</span><span class="p">);</span>
<span class="k">return</span> <span class="nx">db</span><span class="p">.</span><span class="nx">model</span><span class="p">(</span><span class="s1">'User'</span><span class="p">,</span> <span class="nx">schema</span><span class="p">);</span>
<span class="p">}</span>
</pre></div>
<p>The second code</p>
<div class="highlight"><pre><span class="nx">module</span><span class="p">.</span><span class="nx">exports</span> <span class="o">=</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">db</span> <span class="o">=</span> <span class="nx">global</span><span class="p">.</span><span class="nx">db</span><span class="p">;</span>
<span class="kd">var</span> <span class="nx">schema</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">'../../config/schema.js'</span><span class="p">).</span><span class="nx">user</span><span class="p">(</span><span class="nx">db</span><span class="p">.</span><span class="nx">Schema</span><span class="p">);</span>
<span class="k">return</span> <span class="nx">db</span><span class="p">.</span><span class="nx">model</span><span class="p">(</span><span class="s1">'User'</span><span class="p">,</span> <span class="nx">schema</span><span class="p">);</span>
<span class="p">}</span>
</pre></div>
<p>both code have different behavior, the first code will return the model object, the second code will return the function.</p>
<p>Have a nice time.</p>Inspecting file permission in nodejs2014-06-19T22:58:00+07:00Septian Wibisonotag:notes.septianw.web.id,2014-06-19:inspecting-file-permission-in-nodejs.html<p>There's function to show file stat in nodejs, but to access file permission is a bit tricky. Keep this trick here would save my time someday.</p>
<p>I took hours to find this trick, yep my bad. <code>fs.Stats</code> object contain this information</p>
<div class="highlight"><pre> <span class="p">{</span>
<span class="nx">dev</span><span class="o">:</span> <span class="mi">2114</span><span class="p">,</span>
<span class="nx">ino</span><span class="o">:</span> <span class="mi">48064969</span><span class="p">,</span>
<span class="nx">mode</span><span class="o">:</span> <span class="mi">33188</span><span class="p">,</span>
<span class="nx">nlink</span><span class="o">:</span> <span class="mi">1</span><span class="p">,</span>
<span class="nx">uid</span><span class="o">:</span> <span class="mi">85</span><span class="p">,</span>
<span class="nx">gid</span><span class="o">:</span> <span class="mi">100</span><span class="p">,</span>
<span class="nx">rdev</span><span class="o">:</span> <span class="mi">0</span><span class="p">,</span>
<span class="nx">size</span><span class="o">:</span> <span class="mi">527</span><span class="p">,</span>
<span class="nx">blksize</span><span class="o">:</span> <span class="mi">4096</span><span class="p">,</span>
<span class="nx">blocks</span><span class="o">:</span> <span class="mi">8</span><span class="p">,</span>
<span class="nx">atime</span><span class="o">:</span> <span class="nx">Mon</span><span class="p">,</span> <span class="mi">10</span> <span class="nx">Oct</span> <span class="mi">2011</span> <span class="mi">23</span><span class="o">:</span><span class="mi">24</span><span class="o">:</span><span class="mi">11</span> <span class="nx">GMT</span><span class="p">,</span>
<span class="nx">mtime</span><span class="o">:</span> <span class="nx">Mon</span><span class="p">,</span> <span class="mi">10</span> <span class="nx">Oct</span> <span class="mi">2011</span> <span class="mi">23</span><span class="o">:</span><span class="mi">24</span><span class="o">:</span><span class="mi">11</span> <span class="nx">GMT</span><span class="p">,</span>
<span class="nx">ctime</span><span class="o">:</span> <span class="nx">Mon</span><span class="p">,</span> <span class="mi">10</span> <span class="nx">Oct</span> <span class="mi">2011</span> <span class="mi">23</span><span class="o">:</span><span class="mi">24</span><span class="o">:</span><span class="mi">11</span> <span class="nx">GMT</span>
<span class="p">}</span>
</pre></div>
<p>There's permission information in line 3 <code>mode: 33188</code> it's different with unix permission information. Unix file system information use octal number instead of decimal as <code>fs.Stats.mode</code> did . Thank's <a href="http://stackoverflow.com/users/1305696/daniel">daniel</a> for this, i won't know it if he don't say <a href="http://stackoverflow.com/a/16258627">that</a>.</p>
<p>Later than i found <a href="http://stackoverflow.com/q/11775884">this question and answer</a> by <a href="http://stackoverflow.com/users/1260020/simo">simo</a> that help me a lot. Here is the detail.</p>
<div class="highlight"><pre> <span class="kd">var</span> <span class="nx">stat</span> <span class="o">=</span> <span class="nx">fs</span><span class="p">.</span><span class="nx">statSync</span><span class="p">(</span><span class="s1">'file.txt'</span><span class="p">);</span>
<span class="kd">var</span> <span class="nx">permission</span> <span class="o">=</span> <span class="nb">parseInt</span><span class="p">(</span><span class="nx">stat</span><span class="p">.</span><span class="nx">mode</span><span class="p">.</span><span class="nx">toString</span><span class="p">(</span><span class="mi">8</span><span class="p">),</span> <span class="mi">10</span><span class="p">);</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">permission</span><span class="p">);</span> <span class="c1">// 100664</span>
</pre></div>
<p>From the code above, we can use <code>parseInt</code> and <code>toString</code> function to convert decimal number to octal.</p>Benchmark application with time in linux2014-04-23T13:54:00+07:00Septian Wibisonotag:notes.septianw.web.id,2014-04-23:benchmark-application-with-time-in-linux.html<p>Sometime we face different application with same functionality, the we ask which is better, benchmark it to find it better. In linux environment we can use time apllication to find which is better.</p>
<p>From <a href="http://stackoverflow.com/questions/560089/unix-command-for-benchmarking-code-running-k-times">stackoverflow</a> i found this trick.</p>
<div class="highlight"><pre><span class="nv">$ </span><span class="nb">time</span> <span class="o">(</span><span class="k">for </span>i in <span class="k">$(</span>seq 10000<span class="k">)</span>; <span class="k">do</span> ./mycode; <span class="k">done</span><span class="o">)</span>
</pre></div>
<p>In my opinion, <a href="http://stackoverflow.com/users/13430/evan-teran">Evan Teran</a> approach is more reasonable.</p>Optimize fragmented tables in mysql2014-04-02T15:55:00+07:00Septian Wibisonotag:notes.septianw.web.id,2014-04-02:optimize-fragmented-tables-mysql.html<p>If you feel your mysql slow, maybe your table is fragmented. Table fragmentation more often occurs in Innodb than Myisam. Here's the script to check fragmented table and fix it.</p>
<p>Defragmenting table will lock the table for write. Here is script i got from <a href="http://meinit.nl/optimize-only-fragmented-tables-mysql">meinit.nl</a> that check the fragmented table and fix it.</p>
<div class="highlight"><pre><span class="c">#!/bin/sh</span>
<span class="nb">echo</span> -n <span class="s2">"MySQL username: "</span> ; <span class="nb">read </span>username
<span class="nb">echo</span> -n <span class="s2">"MySQL password: "</span> ; stty -echo ; <span class="nb">read </span>password ; stty <span class="nb">echo</span> ; <span class="nb">echo</span>
mysql -u <span class="nv">$username</span> -p<span class="s2">"$password"</span> -NBe <span class="s2">"SHOW DATABASES;"</span> | grep -v <span class="s1">'lost+found'</span> | <span class="k">while </span><span class="nb">read </span>database ; <span class="k">do</span>
mysql -u <span class="nv">$username</span> -p<span class="s2">"$password"</span> -NBe <span class="s2">"SHOW TABLE STATUS;"</span> <span class="nv">$database</span> | <span class="k">while </span><span class="nb">read </span>name engine version rowformat rows avgrowlength datalength maxdatalength indexlength datafree autoincrement createtime updatetime checktime collation checksum createoptions comment ; <span class="k">do</span>
<span class="k"> if</span> <span class="o">[</span> <span class="s2">"$datafree"</span> -gt 0 <span class="o">]</span> ; <span class="k">then</span>
<span class="k"> </span><span class="nv">fragmentation</span><span class="o">=</span><span class="k">$((</span><span class="nv">$datafree</span> <span class="o">*</span> <span class="m">100</span> <span class="o">/</span> <span class="nv">$datalength</span><span class="k">))</span>
<span class="nb">echo</span> <span class="s2">"$database.$name is $fragmentation% fragmented."</span>
mysql -u <span class="s2">"$username"</span> -p<span class="s2">"$password"</span> -NBe <span class="s2">"OPTIMIZE TABLE $name;"</span> <span class="s2">"$database"</span>
<span class="k">fi</span>
<span class="k">done</span>
<span class="k">done</span>
</pre></div>fixing rsyslog running 100% CPU2014-04-01T13:41:00+07:00Septian Wibisonotag:notes.septianw.web.id,2014-04-01:fixing-rsyslog-running-100-CPU.html<p>By default rsyslogd will run in kernel mode, when we have system that run in virtualization that does not support them, it will burden it's CPU.</p>
<p>I have system that run on virtuozzo virtualization system, since i install it until i found the solution of it, My CPU always run on 100%. I found the solution <a href="https://clientarea.ramnode.com/knowledgebase.php?action=displayarticle&id=81">here</a> it was changing the configuration. Here's the step :</p>
<div class="highlight"><pre><span class="nv">$ </span>service rsyslog stop
<span class="nv">$ </span>sed -i -e <span class="s1">'s/^\$ModLoad imklog/#\$ModLoad imklog/g'</span> /etc/rsyslog.conf
<span class="nv">$ </span>service rsyslog start
</pre></div>Make drupal slideshow full width2014-03-21T15:17:00+07:00Septian Wibisonotag:notes.septianw.web.id,2014-03-21:make-drupal-slideshow-full-width.html<p>Drupal have nice module to create slideshow of image, but unfortunately it's a bit tricky to match it with design. here's how to set slideshow width to full width</p>
<p>all come from Kristen Pol in <a href="https://drupal.org/comment/6075772#comment-6075772">this</a> thread. Full width slideshow is just CSS matter, here is Kristen Pol's CSS that working with my case:</p>
<div class="highlight"><pre> <span class="nc">.views_slideshow_cycle_main</span> <span class="p">{</span>
<span class="k">width</span><span class="o">:</span> <span class="m">100</span><span class="o">%</span><span class="p">;</span>
<span class="k">float</span><span class="o">:</span> <span class="k">left</span><span class="p">;</span>
<span class="p">}</span>
<span class="nc">.views_slideshow_cycle_main</span> <span class="nc">.views-slideshow-cycle-main-frame</span> <span class="p">{</span>
<span class="k">width</span><span class="o">:</span> <span class="m">100</span><span class="o">%</span> <span class="cp">!important</span><span class="p">;</span>
<span class="k">height</span><span class="o">:</span> <span class="k">auto</span><span class="p">;</span>
<span class="p">}</span>
<span class="nc">.views_slideshow_cycle_main</span> <span class="nc">.views-slideshow-cycle-main-frame-row</span> <span class="p">{</span>
<span class="k">width</span><span class="o">:</span> <span class="m">100</span><span class="o">%</span> <span class="cp">!important</span><span class="p">;</span>
<span class="k">height</span><span class="o">:</span> <span class="k">auto</span><span class="p">;</span>
<span class="p">}</span>
<span class="nc">.views_slideshow_cycle_main</span> <span class="nc">.field-content</span> <span class="p">{</span>
<span class="k">max-width</span><span class="o">:</span> <span class="m">100</span><span class="o">%</span><span class="p">;</span>
<span class="k">width</span><span class="o">:</span> <span class="m">100</span><span class="o">%</span><span class="p">;</span>
<span class="p">}</span>
<span class="nc">.views_slideshow_cycle_main</span> <span class="nc">.field-content</span> <span class="nt">img</span> <span class="p">{</span>
<span class="k">max-width</span><span class="o">:</span> <span class="m">100</span><span class="o">%</span><span class="p">;</span>
<span class="k">width</span><span class="o">:</span> <span class="m">100</span><span class="o">%</span><span class="p">;</span>
<span class="k">height</span><span class="o">:</span> <span class="k">auto</span><span class="p">;</span>
<span class="k">margin</span><span class="o">:</span> <span class="m">0</span><span class="p">;</span>
<span class="k">padding</span><span class="o">:</span> <span class="m">0</span><span class="p">;</span>
<span class="p">}</span>
</pre></div>Install xdebug on ubuntu2014-03-11T13:43:00+07:00Septian Wibisonotag:notes.septianw.web.id,2014-03-11:install-xdebug-on-ubuntu.html<p>Debugging with scripting language is different with programming language. You need special tool to debugging in scripting language. In PHP we can use xdebug to increase verbosities of PHP.</p>
<p>I assume apache2 and php5 is installed and working well, and here's how we install xdebug in ubuntu thanks <a href="http://ubuntuforums.org/showthread.php?t=525257">martin_lindhe</a> and <a href="http://stackoverflow.com/questions/5504152/is-it-possible-to-use-xdebug-on-ubuntu">Jarrod Nettles</a></p>
<h3><a href="http://stackoverflow.com/questions/5504152/is-it-possible-to-use-xdebug-on-ubuntu">Jarrod Nettles</a> version</h3>
<h4>Step 1</h4>
<p>Install xdebug with apt-get</p>
<div class="highlight"><pre>sudo apt-get install php5-xdebug
</pre></div>
<h4>Step 2</h4>
<p>In my ubuntu (Saucy Salamander 13.10) file xdebug.so placed in <code>/usr/lib/php5/20110331/xdebug.so</code> so you need to add this line to the end of this <code>/etc/php5/apache2/php.ini</code></p>
<div class="highlight"><pre><span class="na">zend_extension</span><span class="o">=</span><span class="s">"/usr/lib/php5/20110331/xdebug.so"</span>
</pre></div>
<p>Make sure that html_error is on. Find this line in <code>/etc/php5/apache2/php.ini</code></p>
<div class="highlight"><pre><span class="na">html_errors</span> <span class="o">=</span> <span class="s">On</span>
</pre></div>
<h4>Step 3</h4>
<p>Restart apache with this command</p>
<div class="highlight"><pre>sudo service apache2 restart
</pre></div>
<p>or </p>
<div class="highlight"><pre>sudo /etc/init.d/apache2 restart
</pre></div>
<h3><a href="http://ubuntuforums.org/showthread.php?t=525257">martin_lindhe</a> version</h3>
<p><a href="http://ubuntuforums.org/showthread.php?t=525257">martin_lindhe</a> use pecl approach.</p>
<h4>Step 1</h4>
<p>Install php5-dev and php5-pear via apt-get</p>
<div class="highlight"><pre>sudo apt-get install php5-dev php-pear
</pre></div>
<h4>Step 2</h4>
<p>then install xdebug via pecl</p>
<div class="highlight"><pre>sudo pecl install xdebug
</pre></div>
<h4>Step 3</h4>
<p>Find xdebug.log location and add it into end of file <code>/etc/php/apache2/php.ini</code> file</p>
<div class="highlight"><pre>asep@thinkblack:/<span class="nv">$ </span>find / -name <span class="s1">'xdebug.so'</span> 2> /dev/null
/usr/lib/php5/20121212/xdebug.so
</pre></div>
<h4>Step 4</h4>
<p>Restart apache with this command</p>
<div class="highlight"><pre>sudo service apache2 restart
</pre></div>
<p>or </p>
<div class="highlight"><pre>sudo /etc/init.d/apache2 restart
</pre></div>jquery stick menu when scrolled2014-03-11T07:28:00+07:00Septian Wibisonotag:notes.septianw.web.id,2014-03-11:jquery-stick-menu-when-scrolled.html<p>if page scrolled, menu disappear to the top. keep it stick on the top with this.</p>
<p>found it <a href="http://www.hongkiat.com/blog/css-sticky-position/">here</a> and fiddled it <a href="http://jsfiddle.net/septianw/2xsSQ/">here</a></p>
<p>Here is the code</p>
<div class="highlight"><pre><span class="nx">$</span><span class="p">(</span><span class="nb">document</span><span class="p">).</span><span class="nx">ready</span><span class="p">(</span><span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">stickyNavTop</span> <span class="o">=</span> <span class="nx">$</span><span class="p">(</span><span class="s1">'.nav'</span><span class="p">).</span><span class="nx">offset</span><span class="p">().</span><span class="nx">top</span><span class="p">;</span>
<span class="kd">var</span> <span class="nx">stickyNav</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">scrollTop</span> <span class="o">=</span> <span class="nx">$</span><span class="p">(</span><span class="nb">window</span><span class="p">).</span><span class="nx">scrollTop</span><span class="p">();</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">scrollTop</span> <span class="o">></span> <span class="nx">stickyNavTop</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">$</span><span class="p">(</span><span class="s1">'.nav'</span><span class="p">).</span><span class="nx">addClass</span><span class="p">(</span><span class="s1">'sticky'</span><span class="p">);</span>
<span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
<span class="nx">$</span><span class="p">(</span><span class="s1">'.nav'</span><span class="p">).</span><span class="nx">removeClass</span><span class="p">(</span><span class="s1">'sticky'</span><span class="p">);</span>
<span class="p">}</span>
<span class="p">};</span>
<span class="nx">stickyNav</span><span class="p">();</span>
<span class="nx">$</span><span class="p">(</span><span class="nb">window</span><span class="p">).</span><span class="nx">scroll</span><span class="p">(</span><span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
<span class="nx">stickyNav</span><span class="p">();</span>
<span class="p">});</span>
<span class="p">});</span>
</pre></div>Generate date format in bash2014-03-11T07:09:00+07:00Septian Wibisonotag:notes.septianw.web.id,2014-03-11:generate-date-format-in-bash.html<p>Bash is powerful shell to do almost anything, here is one of it's function</p>
<p>Generate date with format</p>
<div class="highlight"><pre><span class="nv">$ </span>date +%Y-%m-%d<span class="se">\ </span>%H:%M
2014-03-11 07:09
</pre></div>
<p>full help of date</p>
<div class="highlight"><pre><span class="nv">$ </span>date --help
Usage: date <span class="o">[</span>OPTION<span class="o">]</span>... <span class="o">[</span>+FORMAT<span class="o">]</span>
or: date <span class="o">[</span>-u|--utc|--universal<span class="o">]</span> <span class="o">[</span>MMDDhhmm<span class="o">[[</span>CC<span class="o">]</span>YY<span class="o">][</span>.ss<span class="o">]]</span>
Display the current <span class="nb">time </span>in the given FORMAT, or <span class="nb">set </span>the system date.
-d, --date<span class="o">=</span>STRING display <span class="nb">time </span>described by STRING, not <span class="sb">`</span>now<span class="s1">'</span>
<span class="s1">-f, --file=DATEFILE like --date once for each line of DATEFILE</span>
<span class="s1">-r, --reference=FILE display the last modification time of FILE</span>
<span class="s1">-R, --rfc-2822 output date and time in RFC 2822 format.</span>
<span class="s1"> Example: Mon, 07 Aug 2006 12:34:56 -0600</span>
<span class="s1"> --rfc-3339=TIMESPEC output date and time in RFC 3339 format.</span>
<span class="s1"> TIMESPEC=`date'</span>, <span class="sb">`</span>seconds<span class="s1">', or `ns'</span> <span class="k">for</span>
<span class="k"> </span>date and <span class="nb">time </span>to the indicated precision.
Date and <span class="nb">time </span>components are separated by
a single space: 2006-08-07 12:34:56-06:00
-s, --set<span class="o">=</span>STRING <span class="nb">set time </span>described by STRING
-u, --utc, --universal print or <span class="nb">set </span>Coordinated Universal Time
--help display this <span class="nb">help </span>and <span class="nb">exit</span>
--version output version information and <span class="nb">exit</span>
FORMAT controls the output. Interpreted sequences are:
%% a literal %
%a locale<span class="s1">'s abbreviated weekday name (e.g., Sun)</span>
<span class="s1">%A locale'</span>s full weekday name <span class="o">(</span>e.g., Sunday<span class="o">)</span>
%b locale<span class="s1">'s abbreviated month name (e.g., Jan)</span>
<span class="s1">%B locale'</span>s full month name <span class="o">(</span>e.g., January<span class="o">)</span>
%c locale<span class="s1">'s date and time (e.g., Thu Mar 3 23:05:25 2005)</span>
<span class="s1">%C century; like %Y, except omit last two digits (e.g., 20)</span>
<span class="s1">%d day of month (e.g., 01)</span>
<span class="s1">%D date; same as %m/%d/%y</span>
<span class="s1">%e day of month, space padded; same as %_d</span>
<span class="s1">%F full date; same as %Y-%m-%d</span>
<span class="s1">%g last two digits of year of ISO week number (see %G)</span>
<span class="s1">%G year of ISO week number (see %V); normally useful only with %V</span>
<span class="s1">%h same as %b</span>
<span class="s1">%H hour (00..23)</span>
<span class="s1">%I hour (01..12)</span>
<span class="s1">%j day of year (001..366)</span>
<span class="s1">%k hour, space padded ( 0..23); same as %_H</span>
<span class="s1">%l hour, space padded ( 1..12); same as %_I</span>
<span class="s1">%m month (01..12)</span>
<span class="s1">%M minute (00..59)</span>
<span class="s1">%n a newline</span>
<span class="s1">%N nanoseconds (000000000..999999999)</span>
<span class="s1">%p locale'</span>s equivalent of either AM or PM; blank <span class="k">if </span>not known
%P like %p, but lower <span class="k">case</span>
%r locale<span class="s1">'s 12-hour clock time (e.g., 11:11:04 PM)</span>
<span class="s1">%R 24-hour hour and minute; same as %H:%M</span>
<span class="s1">%s seconds since 1970-01-01 00:00:00 UTC</span>
<span class="s1">%S second (00..60)</span>
<span class="s1">%t a tab</span>
<span class="s1">%T time; same as %H:%M:%S</span>
<span class="s1">%u day of week (1..7); 1 is Monday</span>
<span class="s1">%U week number of year, with Sunday as first day of week (00..53)</span>
<span class="s1">%V ISO week number, with Monday as first day of week (01..53)</span>
<span class="s1">%w day of week (0..6); 0 is Sunday</span>
<span class="s1">%W week number of year, with Monday as first day of week (00..53)</span>
<span class="s1">%x locale'</span>s date representation <span class="o">(</span>e.g., 12/31/99<span class="o">)</span>
%X locale<span class="s1">'s time representation (e.g., 23:13:48)</span>
<span class="s1">%y last two digits of year (00..99)</span>
<span class="s1">%Y year</span>
<span class="s1">%z +hhmm numeric time zone (e.g., -0400)</span>
<span class="s1">%:z +hh:mm numeric time zone (e.g., -04:00)</span>
<span class="s1">%::z +hh:mm:ss numeric time zone (e.g., -04:00:00)</span>
<span class="s1">%:::z numeric time zone with : to necessary precision (e.g., -04, +05:30)</span>
<span class="s1">%Z alphabetic time zone abbreviation (e.g., EDT)</span>
<span class="s1">By default, date pads numeric fields with zeroes.</span>
<span class="s1">The following optional flags may follow `%'</span>:
- <span class="o">(</span>hyphen<span class="o">)</span> <span class="k">do </span>not pad the field
_ <span class="o">(</span>underscore<span class="o">)</span> pad with spaces
0 <span class="o">(</span>zero<span class="o">)</span> pad with zeros
^ use upper <span class="k">case if </span>possible
<span class="c"># use opposite case if possible</span>
After any flags comes an optional field width, as a decimal number;
<span class="k">then </span>an optional modifier, which is either
E to use the locale<span class="s1">'s alternate representations if available, or</span>
<span class="s1">O to use the locale'</span>s alternate numeric symbols <span class="k">if </span>available.
Examples:
Convert seconds since the epoch <span class="o">(</span>1970-01-01 UTC<span class="o">)</span> to a date
<span class="nv">$ </span>date --date<span class="o">=</span><span class="s1">'@2147483647'</span>
Show the <span class="nb">time </span>on the west coast of the US <span class="o">(</span>use tzselect<span class="o">(</span>1<span class="o">)</span> to find TZ<span class="o">)</span>
<span class="nv">$ TZ</span><span class="o">=</span><span class="s1">'America/Los_Angeles'</span> date
Show the <span class="nb">local time </span><span class="k">for </span>9AM next Friday on the west coast of the US
<span class="nv">$ </span>date --date<span class="o">=</span><span class="s1">'TZ="America/Los_Angeles" 09:00 next Fri'</span>
</pre></div>
<p>Report date bugs to bug-coreutils@gnu.org
GNU coreutils home page: <a href="http://www.gnu.org/software/coreutils/">http://www.gnu.org/software/coreutils/</a>
General help using GNU software: <a href="http://www.gnu.org/gethelp/">http://www.gnu.org/gethelp/</a>
Report date translation bugs to <a href="http://translationproject.org/team/">http://translationproject.org/team/</a>
For complete documentation, run: info coreutils 'date invocation'</p>jquery scroll to div animation2014-03-10T18:55:00+07:00Septian Wibisonotag:notes.septianw.web.id,2014-03-10:jquery-scroll-to-div-animation.html<p>Sometime we see simple one page site with multiple menu point to different div compartment and scroll when clicked.</p>
<p>Here's how <a href="http://stackoverflow.com/questions/19498517/javascript-scroll-to-div-with-animation">someone ask in stackoverflow</a> and here's <a href="http://jsfiddle.net/dtR34/4/">the test</a></p>
<p>here is the javascript source</p>
<div class="highlight"><pre><span class="nx">$</span><span class="p">(</span><span class="s1">'.click'</span><span class="p">).</span><span class="nx">click</span><span class="p">(</span><span class="kd">function</span><span class="p">(</span><span class="nx">e</span><span class="p">){</span>
<span class="c1">// prevent default action</span>
<span class="nx">e</span><span class="p">.</span><span class="nx">preventDefault</span><span class="p">();</span>
<span class="c1">// get id of target div (placed in href attribute of anchor element)</span>
<span class="c1">// and pass it to the scrollToElement function</span>
<span class="c1">// also, use 2000 as an argument for the scroll speed (2 seconds, 2000 milliseconds)</span>
<span class="nx">scrollToElement</span><span class="p">(</span> <span class="nx">$</span><span class="p">(</span><span class="k">this</span><span class="p">).</span><span class="nx">attr</span><span class="p">(</span><span class="s1">'href'</span><span class="p">),</span> <span class="mi">2000</span> <span class="p">);</span>
<span class="p">});</span>
<span class="kd">var</span> <span class="nx">scrollToElement</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">el</span><span class="p">,</span> <span class="nx">ms</span><span class="p">){</span>
<span class="kd">var</span> <span class="nx">speed</span> <span class="o">=</span> <span class="p">(</span><span class="nx">ms</span><span class="p">)</span> <span class="o">?</span> <span class="nx">ms</span> <span class="o">:</span> <span class="mi">600</span><span class="p">;</span>
<span class="nx">$</span><span class="p">(</span><span class="s1">'html,body'</span><span class="p">).</span><span class="nx">animate</span><span class="p">({</span>
<span class="nx">scrollTop</span><span class="o">:</span> <span class="nx">$</span><span class="p">(</span><span class="nx">el</span><span class="p">).</span><span class="nx">offset</span><span class="p">().</span><span class="nx">top</span>
<span class="p">},</span> <span class="nx">speed</span><span class="p">);</span>
<span class="p">}</span>
</pre></div>Uh Hai2014-03-10T07:51:00+07:00Septian Wibisonotag:notes.septianw.web.id,2014-03-10:hai.html<p>Ini blog baru perpindahan dari www.septianw.web.id disini tempatnya catatan pemrograman saya. </p>