Skip to content

Instantly share code, notes, and snippets.

@bekce
bekce / setup.sh
Last active February 20, 2019 13:45
My usual list of commands to be applied to a new centos 7 vps
set -e
yum -y update
# Install Java
cd /opt/
wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" \
"https://download.oracle.com/otn-pub/java/jdk/8u201-b09/42970487e3af4f5aa5bca3f542482c60/jdk-8u201-linux-x64.tar.gz"
tar xzf jdk-8u201-linux-x64.tar.gz
cd jdk1.8.0_201/
@bekce
bekce / CustomDecimalFormat.java
Last active October 7, 2020 06:29
Custom Decimal formatting in Java with custom decimal separator and thousand separator, forced fraction and decimal places options, regardless of locale.
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.text.NumberFormat;
import java.util.Currency;
import java.util.Locale;
public class CustomDecimalFormat {
public static DecimalFormat prepareFormat(char decimalSeparator, char thousandSeparator, boolean forceFraction, byte decimalPlaces){
String pattern = "#,###.";
import logging
import logging.handlers
logging.basicConfig(level=logging.INFO, format='%(asctime)s %(levelname)-10s %(message)s' )
smtp_handler = logging.handlers.SMTPHandler(mailhost=("localhost", 25),
fromaddr="from@example.com",
toaddrs=["admin@example.com"],
subject=u"stuff failed")
mail_logger = logging.getLogger("mail")
mail_logger.addHandler(smtp_handler)
@bekce
bekce / SSLUtilities.java
Created February 7, 2018 11:16
Ignore SSL/TLS trust/certificate errors in Java. Call SSLUtilities.trustAllHttpsCertificates() at init
package utils;
import java.security.GeneralSecurityException;
import java.security.SecureRandom;
import java.security.cert.X509Certificate;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
@bekce
bekce / PartitioningTest.scala
Last active June 7, 2017 14:24
Spark partitioning test with multiple RDDs
import java.lang.management.ManagementFactory
import java.net.InetAddress
import org.apache.spark.rdd.RDD
import org.apache.spark.{Partitioner, SparkContext}
import scala.runtime.ScalaRunTime
/**
* Note: Package as a jar and run with spark-submit against a running cluster.
* Created by bekce on 6/5/17.
*/
git filter-branch --env-filter '
OLD_EMAIL="old.email@example.com"
CORRECT_NAME="bekce"
CORRECT_EMAIL="new.email@example.com"
if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]
then
export GIT_COMMITTER_NAME="$CORRECT_NAME"
export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL"
fi
if [ "$GIT_AUTHOR_EMAIL" = "$OLD_EMAIL" ]
public static BigInteger fibonacci(long n) {
if (n < 1) throw new IllegalArgumentException("n>=1 must hold");
BigInteger cur = BigInteger.ONE, t1 = BigInteger.ONE, t2 = BigInteger.ONE;
for (long i = 2; i < n; i++) {
cur = t1.add(t2);
t1 = t2;
t2 = cur;
}
return cur;
}
@bekce
bekce / README.md
Created February 21, 2017 13:36
ldap server with mysql backend

I wanted to build an LDAP server that queries a MySQL server to fetch users and check their passwords. It is mainly used for old software that does not work with custom OAuth2 providers. Redmine is an example of this.

Instructions:

  1. Create the database and table with insert.sql
@bekce
bekce / README.md
Created February 13, 2017 11:46
Node.js IMAP client with parsing

This example connects to an imap server and retrieves emails

npm install imap mailparser

@bekce
bekce / bash_history.sh
Last active November 10, 2021 21:26
OpenVZ setup (legacy)
yum update
yum -y update
yum -y install openssh-clients openssh-servers nano
yum -y install openssh-clients openssh-server nano
ifconfig
chkconfig sshd on
service sshd start
shutdown -h now
ifconfig
wget -P /etc/yum.repos.d/ http://ftp.openvz.org/openvz.repo