Skip to content

Instantly share code, notes, and snippets.

@dkaranja
Last active June 12, 2018 09:37
Show Gist options
  • Save dkaranja/83149ff5342b3f0d6372a261641f9ebb to your computer and use it in GitHub Desktop.
Save dkaranja/83149ff5342b3f0d6372a261641f9ebb to your computer and use it in GitHub Desktop.
Useful Dev hacks

Convert a .cer to .pem file

openssl x509 -inform der -in certificate.cer -out certificate.pem

Compress an entire directory or file

tar -czvf name-of-archive.tar.gz /path/to/directory-or-file
-c: Create an archive.
-z: Compress the archive with gzip.
-v: Verbose mdoe. Show progress
-f: Allows you to specify the filename of the archive.

Extract an archive

tar gz

tar -xzvf archive.tar.gz -C /tmp
-C: Location to Extract archive to

tar bz2

tar jvxf archive.tar.bz2
x - extract
v - verbose output (lists all files as they are extracted)
j - deal with bzipped file
f - read from a file, rather than a tape device

Is the server running on host "localhost" and accepting TCP/IP connections on port 5432? (Mac)

First Try run this

rm /usr/local/var/postgres/postmaster.pid && pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start

if the above fails, then brew rescue your pg!

brew tap gapple/services
brew services start postgresql

Python mysqldb: Library not loaded: libmysqlclient.18.dylib

Create a symbolic link: Linux

sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib

Mac: (Elcapitan Onwards)

sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/local/lib/libmysqlclient.18.dylib

Missing filename. Request should include a Content-Disposition header with a filename parameter.

Ensure REST_FRAMEWORK settings dict has 'rest_framework.parsers.MultiPartParser under DEFAULT_PARSER_CLASSES. Order is very important

REST_FRAMEWORK = {
    'DEFAULT_PARSER_CLASSES': (
        'rest_framework.parsers.FormParser',
        'rest_framework.parsers.MultiPartParser',
        'rest_framework.parsers.FileUploadParser',  # to always come after 'rest_framework.parsers.MultiPartParser' class
    ),
}

404 - File or directory not found. The resource you are looking for might have been removed, had its name changed, or is temporarily unavailable.

This happened when I was trying to access a web service in a Windows Server. I was using a URL that looked like this http://192.168.0.1:9000/Site/Service. Turns out all that Windows server wasn't configured to take URLs with dots and I didn't want to go through so many configs so all i did was replace the IP with the server name to look something like this.http://server_name:9000/Site/Service and It worked like a charm.

On ubuntu, to get server name given IP address just do

nmblookup -A <ip-address>

Auto Remove Old kernels in ubuntu 16.04 >

sudo apt autoremove --purge

See running crons

pstree -ap `pidof cron`

Postgres compressed back up and restore

Dump the db

pg_dump dbname | gzip > filename.gz

Restore the db

gunzip -c filename.gz | psql dbname

Get all Running Cron jobs

ps fauxww | grep -A 1 '[C]RON'

The above gets their PIDs

pstree -as `pidof cron`

The above shows you all the running cron jobs

Remove unused linux kernels

  • RESTART your linux
  • run
uname -r
  • Get all old kernels
dpkg -l linux-{image,headers}-"[0-9]*" | awk '/^ii/{ print $2}' | grep -v -e `uname -r | cut -f1,2 -d"-"` | grep -e '[0-9]'

Make sure your kernell (uname -r) is not part and parcel of the above result

  • Then run:
dpkg -l linux-{image,headers}-"[0-9]*" | awk '/^ii/{ print $2}' | grep -v -e `uname -r | cut -f1,2 -d"-"` | grep -e '[0-9]' | xargs sudo apt-get -y purge
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment