Skip to content

Instantly share code, notes, and snippets.

View salex89's full-sized avatar

Aleksandar Stojadinovic salex89

View GitHub Profile
@salex89
salex89 / show-open-ports.sh
Last active August 16, 2016 12:52
Show open ports and PID's that hold them open.
netstat -tulpn
@salex89
salex89 / sbt-docker.scala
Last active August 15, 2016 11:34
Additional Docker configuration for Play (or any similar SBT project in that matter)
maintainer in Docker := "Aleksandar Stojadinovic (salex89@gmail.com)"
dockerBaseImage := "anapsix/alpine-java:8"
packageName in Docker := "data-web-service"
dockerRepository := Some("example.com/foobar")
dockerUpdateLatest := true
class JHtmlEscapingFlask(Flask):
def select_jinja_autoescape(self, filename):
if filename is None:
return False
if filename.endswith('.jinja2'):
return True
return Flask.select_jinja_autoescape(self, filename)
app = JHtmlEscapingFlask(__name__)
@salex89
salex89 / xubuntu-for-ssd
Last active August 3, 2016 21:55
Configuring xubuntu for SSD
1. Use ext4
2. Add "noatime" to each Linux SSD volume in /etc/fstab like so:
/dev/sda1 / ext4 defaults,noatime 0 1
UUID=xxxxx / ext4 noatime,errors=remount-ro 0 1
3. Set up TRIM
A trim command (known as TRIM in the ATA command set, and UNMAP in the SCSI command set) allows an operating system to inform a solid-state drive (SSD) which blocks of data are no longer considered in use and can be wiped internally.
TRIM can be executed daily, weekly or monthly. To set up when should it be executed, copy /etc/cron.weekly/fstrim to the appropriate /etc/cron.[weekly|daily|monthly] directory. *Note to myself* keep it at weekly, it's fine enough.
@salex89
salex89 / postgres remote access
Last active August 15, 2016 11:34
Enable Postgres to listen to all interfaces
1. Set `listen_addres`s to `*` in `/etc/postgres/<version>/main/
postgresql.conf`, or specify a concrete interface.
2. Add permissions to `/etc/postgres/<version>/main/pg_hba`
@salex89
salex89 / build.scala
Last active August 15, 2016 11:34
Additional akka build.sbt configurations
bashScriptExtraDefines += """addJava "-Dmode=prod""""
bashScriptExtraDefines += "addJava -Dlogdir=$app_home/../logs/"
bashScriptConfigLocation := Some("$app_home/conf/prod.conf")
mainClass in Compile := Some("sample.hello.Main")
mappings in Universal += file("src/main/resources/base.conf") -> "conf/base.conf"
@salex89
salex89 / build.sbt
Last active August 15, 2016 11:34
Additional lines to Play's build.sbt
sources in (Compile, doc) := Seq.empty
publishArtifact in (Compile, packageDoc) := false
//Additional JPA configuration
PlayKeys.externalizeResources := false
mappings in Universal += file("conf/base.conf") -> "conf/base.conf"
mappings in Universal += file("conf/prod.conf") -> "conf/prod.conf"
@salex89
salex89 / ChuckNorris_CodinGame.scala
Last active November 10, 2015 21:26
Chuck Norris puzzle solution in Scala from CodinGame.com
import math._
import scala.util._
object Solution extends App {
def spanAndEncode(message : String) : String =
{
val (same, rest) = message.span(_ == message.head)
val output = new StringBuilder
output ++= ("0" * (2 - same.head.asDigit)) + " " + ("0" * same.length)
@salex89
salex89 / key_and_certificate_conversions.sh
Last active February 19, 2024 12:05
Different private/public key conversions GnuPG, OpenSSH and OpenSSL
# Source: http://www.sysmic.org/dotclear/index.php?post/2010/03/24/Convert-keys-betweens-GnuPG%2C-OpenSsh-and-OpenSSL
# OpenSSH private keys are directly understable by OpenSSL. You can test for example:
openssl rsa -in ~/.ssh/id_rsa -text
openssl dsa -in ~/.ssh/id_dsa -text
# So, you can directly use it to create a certification request:
openssl req -new -key ~/.ssh/id_dsa -out myid.csr
# You can also use your ssh key to create a sef-signed certificate:
# Debian/Ubuntu
sudo apt-add-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer
# CentOS:
sudo wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" \
"http://download.oracle.com/otn-pub/java/jdk/8u25-b17/jdk-8u25-linux-x64.tar.gz"