Skip to content

Instantly share code, notes, and snippets.

View salex89's full-sized avatar

Aleksandar Stojadinovic salex89

View GitHub Profile
# 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"
@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 / 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.
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 / 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
@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 / 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 / rancher-upgrade-example
Created August 31, 2016 08:34
Rancher compose call for pulling and upgrading a stack
rancher-compose --url <rancher_compose_url> --access-key <key> --secret-key <secret_ky> -f docker-compose.yaml -p <stack_name> up --pull --force-upgrade --confirm-upgrade -d