Skip to content

Instantly share code, notes, and snippets.

@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:1b5392b3e7c261cca12e
Created November 1, 2014 23:59
Changing default editor Ubuntu
sudo update-alternatives –config editor
@ps
ps / gist:4a17de017ccf350f4c67
Created November 1, 2014 23:51
Dealing with existing SSH keys
I already had git ssh keys set up and now wanted to use the same one for logging into my Digital Ocean droplet. To copy over ssh keys to the remote droplet just do:
ssh-copy-id user@address
@ps
ps / gist:76318790771e2ae5b7fb
Created October 6, 2014 16:10
Unnecessary double title bar on Ubuntu
To get rid of them run:
gconftool-2 -s -t string '/apps/compiz-1/plugins/decor/screen0/options/decoration_match' '!(state=maxvert & state=maxhorz)'
@ps
ps / gist:10908532
Last active August 29, 2015 13:59
Mounting Remove Drives with SSHFS
So there are times when you need to connect to a remote server and do some sort of work on the files.
One alternative is to use an FTP client such as FileZilla and constantly upload to view changes.
Scratch that, just use SSHFS! It mounts the remote drive/directory on your local machine and you can
work/save files and the changes will be automatically uploaded.
First install sshfs, on Ubuntu: sudo apt-get install sshfs
In order to mount a drive use your usual ssh account and specify a directory on which you would like the mount
to occur like so:
@ps
ps / gist:9799328
Last active August 29, 2015 13:57
Installing MySQL and phpMyAdmin
First we need to install MySQL with the following:
sudo apt-get install mysql-server
Note: You will be prompted for the root password in the middle of the installation.
Now this is optional (for uses with MySQL workbench):
sudo apt-get install mysql-client
Now to test it out try: mysql -uroot -p
@ps
ps / gist:9798701
Last active August 29, 2015 13:57
Installing Apache2 and PHP on Ubuntu 12.04
The only simple command you need is:
sudo apt-get install apache2
Navigate to: http://localhost and you shall see the magical 'It works!' file!
Now to get PHP working:
sudo apt-get install php5
sudo apt-get install libapache2-mod-php5
@ps
ps / gist:9755379
Created March 25, 2014 04:41
Going back to a previous kernel of Ubuntu
Fire up the terminal and run this command:
dpkg -l | awk '/linux-[^ ]+-[0-9]/ {print $2}'
It should print all of the available kernel versions.
Check which version of kernel you are currently running by typing in: uname -a
Once you know which new version of the kernel you want to remove type:
sudo apt-get purge linux-headers-3.8......
@ps
ps / gist:9671636
Created March 20, 2014 19:16
Firefox userChrome.css
This is the setting placed in ~/.mozilla/firefox/<default-user-profile>/chrome/userChrome.css:
/*******
START
********/
/*Do not remove the @namespace line -- it's required for correct functioning*/
@namespace url("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul");
/*Toolbar & menu font size*/
@ps
ps / gist:9454764
Last active September 10, 2022 11:32
Ubuntu 12.10/12.04 Realtek rtl8188ce Wireless Adapter Issues
Recently my dorm wireless network has been working fine on all devices except my Ubuntu 12.10 laptop.
So I did some research and some simple fixes that have seemed to work for now are:
-change router security to WPA2 only
-change router channel from automatic to either 1 or 11
-if router is b/g/n, attempt to change to b/g (was not able to do this with my router)
-sudo vim /etc/modprobe.d/rtl8192ce.conf and insert the following line:
'options rtl8192ce ips=0 fwlps=0 swenc=1 debug=2'
Switched to Ubuntu 12.04 and entered the following to see if wireless works better: