MongoDB Cheatsheet

Starting: mongo Connect to database show dbs use local See database tables show collections db.funnytable.find() Regex db.funnytable.find( $or: [ {'name': { $regex: req.params.username, $options: 'i' }}, {'username': { $regex: req.params.username, $options: 'i' }}, {'email': { $regex: req.params.username, $options: 'i' }} ])

October 28, 2014  |  🏷️Mongo

BSD - Fetch and update ports

portsnap fetch update # Upgrade ports to newest version portmaster -ad # ALL ports portmaster -d portname # Specific port # List upgradable ports portmaster -L

Building debian packages

Links Official Manual Example building sudo-1.8.11p1-2 # Download the source files curl -O http://ftp.de.debian.org/debian/pool/main/s/sudo/sudo_1.8.11p1-2.dsc curl -O http://ftp.de.debian.org/debian/pool/main/s/sudo/sudo_1.8.11p1.orig.tar.gz curl -O http://ftp.de.debian.org/debian/pool/main/s/sudo/sudo_1.8.11p1-2.debian.tar.xz # Extract the tarballs: tar xf sudo_1.8.11p1-2.debian.tar.xz # Creates folder sudo-1.8.11p1 tar xf sudo_1.8.11p1.orig.tar.gz # Creates folder debian # Move the debian file to the source mv debian sudo-1.8.11p1 # Cd to the folder cd sudo-1.8.11p1 # Build dpkg-buildpackage -us -uc

October 27, 2014  |  🏷️Curl 🏷️Tar 🏷️Dpkg

LaTeX Template

LaTeX Template: \documentclass[a4paper,11pt]{article} \usepackage[utf8]{inputenc} \author{Author Name} \title{This is the title} \begin{document} \maketitle \section{Section Title} Wow, text \flushleft More Text\\[10pt] Text \end{document}

October 27, 2014  |  🏷️Latex

Android Studio: Install Android Studio on Ubuntu

Download android studio Untar it to /opt/android-studio Symlink /opt/android-studio/bin/studio.sh to /usr/local/bin/android-studio Download oracle’s java Untar it to /opt/oracle-java (Ubuntu) Symlink /opt/oracle-java to /usr/lib/jvm/default-java (Ubuntu) Symlink /opt/oracle-java/bin/java to /usr/bin/java If you have a 64-bit system, you’ll need to install 32-bit libraries: # On ubuntu sudo apt-get install lib32z1 lib32ncurses5 lib32bz2-1.0 lib32stdc++6

September 17, 2014  |  🏷️Apt-Get

Android Studio: Questionmark Instead of Phone Name

If you get questionmarks instead of phone name when trying to run your app, you can fix it with the following code: #! /usr/bin/env bash path="/opt/android-studio" # Path where Android Studio is installed set -e "$path/sdk/platform-tools/adb" kill-server sudo "$path/sdk/platform-tools/adb" start-server "$path/sdk/platform-tools/adb" devices If it doesn’t work the first time, try a few more times

September 17, 2014  | 

Activating SMTP AUTH (PLAIN) through STARTTLS in sendmail (FreeBSD)

N.B. This expects a working sendmail installation with STARTTLS Install cyrus-sasl # install cyrus-sasl2 cd /usr/ports/security/cyrus-sasl2 make install clean echo "pwcheck_method: saslauthd" > /usr/local/lib/sasl2/Sendmail.conf # install cyrus-sasl2-saslauthd cd /usr/ports/security/cyrus-sasl2-saslauthd make install clean echo 'saslauthd_enable="YES"' >> /etc/rc.conf service saslauthd start Set sendmail make flags Set the following flags in /etc/make.conf (create if it doesn’t exist) SENDMAIL_CFLAGS=-I/usr/local/include/sasl -DSASL SENDMAIL_LDFLAGS=-L/usr/local/lib SENDMAIL_LDADD=-lsasl2 Recompile sendmail Did you have the source in /usr/src? Otherwise you will need to run the following command. If you don’t use RELEASE-10, you should change that. ...

Sendmail / Postfix - Testing mailserver

Links qmail.jms1.net BSD Handbook Sendmail.org This expects you to have netcat, perl and openssl installed Hello without TLS nc mail.server.com 25 220 mail.server.com ESMTP Sendmail 8.14.7/8.14.7; Thu, 11 Sep 2014 12:01:22 +0200 (CEST) > ehlo friendly.server.com 250-mail.server.com Hello friendly [1.2.3.4], pleased to meet you 250-ENHANCEDSTATUSCODES 250-PIPELINING 250-8BITMIME 250-SIZE 250-DSN 250-ETRN 250-AUTH DIGEST-MD5 CRAM-MD5 250-STARTTLS 250-DELIVERBY 250 HELP > quit< 221 2.0.0 mail.server.com closing connection Hello with TLS openssl s_client -starttls smtp -crlf -connect mail.server.com:25 # ...Loads of text here... > ehlo friendly.server.com # ... Same as login without TLS (above) ... Test login $ perl -MMIME::Base64 -e 'print encode_base64("\000coolname\@iix.se\000my-password")' AGNvb2xuYW1lQGlpeC5zZQBteS1wYXNzd29yZA== # .. Log in to server with one of the above ... > AUTH PLAIN AGNvb2xuYW1lQGlpeC5zZQBteS1wYXNzd29yZA== 235 2.0.0 OK Authenticated > quit 221 2.0.0 mail.server.com closing connection Sending mail > mail from: <[email protected]> 250 ok > rcpt to: <[email protected]> 250 ok > data 354 go ahead > From: John <[email protected]> > To: Nobody <[email protected]> > Subject: fnord > > hail eris! > . 250 ok 1113954693 qp 29052 > quit

Ubuntu: Fix broken X11 after update

Updated my school ubuntu ws from raring to trust and X11 stopped working. Solution (2014) sudo apt-get remove --purge xserver-xorg sudo apt-get remove --purge nvidia* sudo apt-get autoremove --purge sudo reboot #..rebooting.. sudo apt-get install xserver-xorg sudo dpkg-reconfigure xserver-xorg # NB; nothing will seem to happen sudo reboot #..rebooting.. Now reinstall your favourite graphical environmnet Solution (2021) sudo apt purge nvidia* ubuntu-drivers devices # Manual option (install the one you want, start with "recommended") sudo apt install nvidia-driver-xxx # Automatic option sudo ubuntu-drivers autoinstall sudo reboot

September 5, 2014  | 

MySQL Cheatsheet

Starting mysql # Same username, no password mysql -p # Password protected mysql -u user mysql -h hostname Create user CREATE USER me GRANT ALL PRIVILEGES ON database_name.* TO 'me'@'%'; ALTER USER 'me'@'%' IDENTIFIED BY 'newPass'; Connect to databaes SHOW DATABASES; SHOW DATABASES LIKE 'ok%'; USE mysql; See database tables SHOW TABLES; SHOW TABLES LIKE 'ok%'; SELECT * FROM important_stuffs; Extend tables ALTER TABLE important_stuffs ADD description VARCHAR(100); ALTER TABLE important_stuffs ADD description VARCHAR(100) AFTER severity; ALTER TABLE important_stuffs ADD description VARCHAR(100) FIRST; Delete from tables SELECT * FROM important_stuffs WHERE severity="low"; DELETE FROM important_stuffs WHERE severity="low"; Insert into tables INSERT INTO important_stuffs VALUES("Wow, so important", "high"); INSERT INTO important_stuffs SET description="Wow, so important", severity="high"; Show access rights SHOW GRANTS; Change all email addresses to my (when mailserver is activated) UPDATE users SET email= CONCAT('me+', id, '@iix.se'); General log show variables like 'general_log%'; SET GLOBAL general_log = 'ON'; SET GLOBAL general_log = 'OFF'; Run query without cache SELECT SQL_NO_CACHE * from users where name like 'Ol%'; Indexes SHOW INDEX FROM users; ALTER TABLE users ADD INDEX index_name(firstName); CREATE INDEX index_name ON users(firstName); ALTER TABLE users DROP INDEX users; DROP INDEX index_name ON users; Explain/describe EXPLAIN users; DESCRIBE users; DESC users; DESC SELECT * FROM users; Profiling SET SESSION profiling = 1; SHOW PROFILES; SHOW PROFILE FOR QUERY 3; SHOW STATUS LIKE 'Last_Query_Cost'; Collation show variables like "collation_database"; SELECT SCHEMA_NAME 'database', default_character_set_name 'charset', DEFAULT_COLLATION_NAME 'collation' FROM information_schema.SCHEMATA;