Skip to content

Instantly share code, notes, and snippets.

@jpralves
jpralves / prepare-raspbian.sh
Last active May 19, 2016 13:01
Reduce raspbian Jessie image
cat <<EOF
if [ $(id -u) -ne 0 ]; then
printf "Script must be run as root\n"
exit 1
fi
EOF
### Packages:
@jpralves
jpralves / pushing_exceptions.py
Last active August 25, 2017 14:00
Using python exceptions in a strange way
from random import randint
print("Number ", end="")
i = randint(0, 9)
print(i, "is ", end="")
try:
j = 1/(i % 2) + 'a'
except TypeError:
print("odd")
except ZeroDivisionError:
@jpralves
jpralves / index.md
Last active September 29, 2017 14:21
Instructions - If pay then Play

If pay then Play

Project 27

To add credits to the machine you should transfer EXPOSURE from your digital wallet to an account.

Each EXPOSURE gives 1 credit in the machine.

How?

package main
import (
"crypto/cipher"
"crypto/des"
"fmt"
"bytes"
"encoding/base64"
"crypto/md5"
"errors"
package testencrypt;
import java.security.Key;
import java.security.SecureRandom;
import java.util.Arrays;
import javax.crypto.*;
import javax.crypto.spec.*;
import java.util.Base64;
/**
@jpralves
jpralves / clean-vm.sh
Last active January 30, 2019 23:23
Clean VM for compacting
#!/bin/bash
if [[ $EUID -ne 0 ]]; then
echo "Please run as root or sudo"
exit 1
fi
set -e
if [ -f /etc/os-release ]; then
@jpralves
jpralves / nvm-in-Dockerfile
Created March 19, 2019 15:50
snippet to use nvm in docker
# nvm environment variables
ENV NVM_DIR=/usr/local/nvm
ENV NVM_VERSION=0.33.11
ENV NODE_VERSION=8.10.0
# install nvm
# https://github.com/creationix/nvm#install-script
RUN [ -d $NVM_DIR ] || mkdir -p $NVM_DIR
RUN curl --silent -o- https://raw.githubusercontent.com/creationix/nvm/v${NVM_VERSION}/install.sh | bash
@jpralves
jpralves / bash_with_python.sh
Created May 14, 2019 22:53
Sample bash script with embedded python script
#!/bin/bash
python_code_in_bash() {
python3 <(cat <<EOF
import sys
lines = sys.stdin.readlines()
print("Read {} lines from STDIN.".format(len(lines)))
@jpralves
jpralves / checkCertificates.sh
Created July 18, 2019 13:49
check expiration of certificates of Java KeyStore
#!/bin/sh
########################################################
#
# Check certificates inside a java keystore
#
########################################################
KEYTOOL="keytool"
THRESHOLD_IN_DAYS="30"
KEYSTORE=""
@jpralves
jpralves / puppeteer-json.js
Last active September 20, 2019 15:02
simple node script to get headers and data from a webpage. Uses puppeteer.
'use strict'
const puppeteer = require('puppeteer');
const fs = require('fs');
var args = process.argv.slice(2);
if (!(Array.isArray(args) && args.length)) {
console.log('puppeteer-json.js url [fileprefix]');
process.exit(1);
}