Skip to content

Instantly share code, notes, and snippets.

@alces
alces / ansible_install_centos7.sh
Created July 7, 2017 08:11
Install the lates Ansible on CentOS 7
yum install -y gcc python-devel openssl-devel epel-release
yum install -y python-pip
pip install ansible
@alces
alces / mvn_unique_version.md
Created July 7, 2017 06:11
How to set unique version for each build in Maven

Put in pom.xml a variable version:

<version>${my.artifact.version}</version>

And set this variable in mvn command line:

mvn -Dmy.artifact.version=1.0-$(date +%Y%m%d%H%M%S) deploy
@alces
alces / nip_io.md
Created June 30, 2017 05:30
Pseudo domain names for non-routable IP addresses
10.0.0.1.nip.io maps to 10.0.0.1
app.10.0.0.1.nip.io maps to 10.0.0.1
customer1.app.10.0.0.1.nip.io maps to 10.0.0.1
customer2.app.10.0.0.1.nip.io maps to 10.0.0.1
otherapp.10.0.0.1.nip.io maps to 10.0.0.1
@alces
alces / mvn_download.sh
Created June 22, 2017 08:36
Download an artifact from a Maven repository (such as Maven Central) into a local directory
mvn dependency:copy -Dartifact=org.yaml:snakeyaml:1.18 -DoutputDirectory=. -Dmdep.stripVersion=true
@alces
alces / scheduleDownstreamRun.groovy
Last active June 14, 2017 09:07
Schedule a build of a Jenkins job and print its URL after its start.
import hudson.model.*
// in order to pass environment variables into build, EnvInjectPlugin should be installed
import org.jenkinsci.plugins.envinject.EnvInjectPluginAction
println Hudson.instance.getItem('down_stream_job_name').scheduleBuild2(
5, // quiet period
new ParametersAction( // build parameters
new StringParameterValue('STR_PARAM', 'Its value'), // string parameter
new BooleanParameterValue('BOOL_PARAM', true) // boolean parameter
),
@alces
alces / obscure_string.yml
Created May 30, 2017 10:45
Genereta an idempotent, pretty obscure string (can be used as a database password, etc.)
- connection: local
hosts: localhost
tasks:
- debug:
msg: "{{ ('secretword' | password_hash('sha256', 'salt_string')).split('$')[-1][:16] }}"
@alces
alces / add_user_to_mongo.js
Last active May 30, 2017 09:27
Add user to MongoDB (if no admin user exists, first create it)
var ADMIN_USER = 'root';
var ADMIN_PASS = 'ass4' + ADMIN_USER
var NEW_USER = 'dummy';
var TARGET_DB = 'mydb';
var conn = new Mongo();
var admDb = conn.getDB('admin');
try {
admDb.createUser({user: ADMIN_USER,
pwd: ADMIN_PASS,
@alces
alces / eve_token.py
Created May 30, 2017 06:41
Eve server with token authentication
#!/usr/bin/env python
# to connect it using curl:
# curl -H 'Authorization: Token 9d003d9a-2288-46b8-bfeb-7cec1eb53074' http://my.host.name/api/my_collection/
import eve
class MyTokenAuth(eve.auth.TokenAuth):
def check_auth(self, token, allowed_roles, resource, method):
return token == '9d003d9a-2288-46b8-bfeb-7cec1eb53074'
@alces
alces / settings.py
Created May 29, 2017 08:55
Example of settings.py for Eve with disabled schema-checking and if-match concurrency control
ALLOW_UNKNOWN = True
DOMAIN = {'col01': {'schema': {}}}
IF_MATCH = False
ITEM_METHODS = ['GET', 'PATCH', 'PUT', 'DELETE']
MONGO_DBNAME = 'db01'
RESOURCE_METHODS = ['GET', 'POST', 'DELETE']
URL_PREFIX = 'api'
@alces
alces / readYaml.groovy
Created May 2, 2017 13:04
Reading YAML from Groovy using snakeyaml (its jar file is available on Maven Central, no dependencies)
import org.yaml.snakeyaml.Yaml
new Yaml().load(new FileReader('path/to/your/yaml/file'))
// and do whatenver your want with the returned map