Skip to content

Instantly share code, notes, and snippets.

@ps
ps / gist:1b5392b3e7c261cca12e
Created November 1, 2014 23:59
Changing default editor Ubuntu
sudo update-alternatives –config editor
@ps
ps / gist:d3e754e38c29a0970f2e
Last active September 24, 2015 01:26
Counting the number of 1 bits in binary representaiton of a number!
So given a number count the number of 1's it has set in it's binary representation. Easy!
Just keep on dividing by two (or bitshift right) and see if the number is odd or even and increment the count based
on this criteria like so:
getNumBitsSet(int val) {
int count=0;
while(val>0) {
if(val % 2 != 0)
count++;
count = count / 2;
@ps
ps / gist:25f50a34c04e95c0a278
Last active September 3, 2015 21:56
Authenticating Mongo
1. mongo
2. use <your-database-name-here>
3. db.addUser('pawel','test')
4. exit
5. vim /etc/mongodb.conf uncomment the line '#auth=true'
6. sudo service mongodb stop
7. sudo service mongodb start
7.5 Run your application as it is now and verify that it fails since it is missing authentication.
8. in your python code add: db.authenticate('pawel','test')
9. sudo service apache2 restart
@ps
ps / gist:6ac0b69609661e3d8d6f
Created January 18, 2015 17:47
Vim Skeleton Java Code
If you get tired of typing public class... and then the main method in vim
then here is your solution.
autocmd BufNewFile *.java
\ exe "normal Opublic class " . expand('%:t:r') . " {\npublic static void main(String [] args) {\n\n}\n}\<Esc>1G"
Just insert it into your '.vimrc' and that's it! The next time you open a brand new Java file you
will see a template.
@ps
ps / gist:97cc54e97e137c43b882
Created April 20, 2015 19:18
Counting the total number of occurrences of a string recursively
grep -c -r 'import' Python-2.5.4/ | \
awk -F : '{total += $2; print $1, $2} END { print "Total:", total }'
Source: http://stackoverflow.com/questions/884591/grep-recursive-and-count
@ps
ps / gist:5810548230ee2e5583c6
Created April 28, 2015 03:11
using objdump
objdump -d -M intel -S test.o
@ps
ps / extract.py
Last active February 20, 2016 00:53
Get x,y coordinates in order of left to right occurance
# Place: "fprintf('[%i, %i],',round((maxr+minr)/2), round((maxc + minc)/2));" in Matlab for image test1.bmp or test2.bmp
# put the output into test1/test2 var as below
# script prints out centers of figures on image in order (left to right then top to bottom)
def gen_data(a,mod):
a_by_rows = []
temp_row = []
i=1
for x,y in a:
temp_row.append([y,x])
@ps
ps / gist:e03fa57249e00ba938136cf765bd04b8
Created April 11, 2016 03:02
add another site to laravel homestead
edit Homestead.yaml and add under sites section
-map: domain.app
to: /path/to/public
on own machine (NOT VM) edit /etc/hosts and add another entry, grab IP from Homestead.yaml and add line:
<ip-from-yaml> domain.app
vagrant reload --provision
DONE!
@ps
ps / gist:7865aae997738344e63927f97402c90e
Last active April 18, 2016 12:45
do droplet errors
Ign http://downloads-distro.mongodb.org dist InRelease
Hit http://downloads-distro.mongodb.org dist Release.gpg
Hit http://downloads-distro.mongodb.org dist Release
Hit http://downloads-distro.mongodb.org dist/10gen amd64 Packages
Ign http://old-releases.ubuntu.com utopic-security InRelease
Hit http://downloads-distro.mongodb.org dist/10gen i386 Packages
Hit http://old-releases.ubuntu.com utopic-security Release.gpg
Ign http://downloads-distro.mongodb.org dist/10gen Translation-en_US
Ign http://downloads-distro.mongodb.
# deb cdrom:[Ubuntu-Server 14.10 _Utopic Unicorn_ - Rlease amd64 / utopic main restricted
#deb cdrom:[Ubuntu-Server 14.10 _Utopic Unicorn_ - Release amd64 / utopic main restricted
# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://mirrors.digitalocean.com/ubuntu-old/ utopic main restricted
deb-src http://mirrors.digitalocean.com/ubuntu-old/ utopic main restricted
## Major bug fix updates produced after the final release of the