Skip to content

Instantly share code, notes, and snippets.

View manwar's full-sized avatar
✌️
Undercover Contributor

Mohammad Sajid Anwar manwar

✌️
Undercover Contributor
View GitHub Profile
@manwar
manwar / git-helper
Last active October 27, 2017 14:19
Git command helper
- Rename / Delete Tag
$ git tag new_tag_name old_tag_name
$ git tag -d old_tag_name
- Tag a git commit
$ git checkout <commit id>
$ git tag <tag name>
$ git push origin <tag name>
@manwar
manwar / tmux-helper
Last active August 29, 2015 14:06
Tmux command helper
- Detach tmux session
Ctrl + B then press D
- Attach tmux session
tmux attach
- Find the tmux version installed
@manwar
manwar / perl-tricks
Last active August 29, 2015 14:06
Perl Tricks
- Magic of '/r' as shown below:
my @new = map { s/foo/bar/r } @old;
Compared with the old way:
my @new = map { (my $tmp = $_) =~ s/foo/bar/; $tmp } @old;
- To find the full path of the installed module (Modern Perl 2014, page 148)
@manwar
manwar / random-thoughts.txt
Created November 3, 2014 11:04
Random Thoughts
- Simple regex to validate UK postcode
/[A-Z]{1,2}[0-9][0-9A-Z]?\s?[0-9][A-Z]{2}/gi
@manwar
manwar / unweighted-graph.txt
Last active August 29, 2015 14:08
Shortest Path Algorithm for Unweighted Graphs
Source: http://courseweb.sp.cs.cmu.edu/~cs200/lecture22/lecture22.html
One common use of graphs is to find the shortest path from one place to another. You may have
at some point used an online program to find driving directions, and you likely had to specify
if you wanted the shortest route/fastest route. This involves finding the shortest path in a
weighted graph, but we will make it simpler for now by sticking to an unweighted graph.
In an unweighted graph, finding the shortest path involves something you already know about -
breadth-first search. To find the shortest path from a starting vertex s to a vertex v, we see
if we can get from s to v in one step. If we can, we've found the shortest path from s to v.If
@manwar
manwar / weighted-graph.txt
Last active August 29, 2015 14:08
Shortest Path Algorithm for Weighted Graphs
Source: http://courseweb.sp.cs.cmu.edu/~cs200/lecture22/lecture22.html
If the graph is weighted, the problem is a bit more complex, but we can still use the ideas we learned
from the shortest path algorithm for unweighted graphs.
We keep all of the same information as before. So each vertex is marked as either known or unknown. We
keep the tentative distance Length for each vertex as in the unweighted case. We again record Path, which
is the last vertex to cause a change to Length.
The general algorithm to solve the shortest path problem is known as Dijkstra's Algorithm. Dijkstra's
@manwar
manwar / postgresql-help
Last active January 4, 2018 13:07
PostgreSQL Help
PostgreSQL HELP
---------------
1. Conditional constraint
CREATE UNIQUE INDEX <name> ON <table>(<col 1>,<col 2>,...) WHERE <col 3> IS TRUE;
2. Check time overlaps
SELECT <col 1>, <col 2>, ...
@manwar
manwar / how-to-install-git-on-rpi
Created March 10, 2015 12:16
How to install git on Raspberry Pi
$ sudo apt-get install gettext
$ wget https://www.kernel.org/pub/software/scm/git/git-2.3.0.tar.xz
$ tar -xvf git-2.3.0.tar.xz
$ cd git-2.3.0/
$ ./configure --prefix=/usr --with-gitconfig=/etc/gitconfig
@manwar
manwar / magic-square.pl
Created March 30, 2015 14:16
Generate Magic Square
#!/usr/bin/perl
use strict; use warnings;
my $n = $ARGV[0];
die "Sorry, must be a positive odd integer.\n"
unless ((defined $n) && ($n % 2 == 1) && ($n > 0));
for(my $i=0; $i<$n; $i++) {
for(my $j=0; $j<$n; $j++) {
@manwar
manwar / MooTips
Last active August 29, 2015 14:18
Moo tips
- Adding 'predicate => 1' to an attribute, will create a method has_<attr_name> which
would return 0 or 1 depending on whether the attribute has any value. In case the
attribute starts with '_' then it would create _has_<attr_name>. In case we want
completely different name then we can do so by 'predicate => "my_new_val_check"'.
- Adding 'clearer => 1' to an attribute, will create a method clear_<attr_name> which
would clear attribute value including any default assigned. Even if an attribute is
marked as 'required', it can remove its value, because 'default' and 'required' only
applies to the constructor.