Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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
@bekce
bekce / ntfs_fix.md
Last active October 22, 2021 10:32
NTFS filename fix

If you happen to write to NTFS partitions using non-windows operating systems (such as with ntfs-3g, see this thread for more info), some of your files may have got written containing invalid characters in their names. When such a thing happen, the fix of chkdsk is just to delete them but clearly no one would ever want to have their files deleted to 'fix'!

This little script that I wrote aims to fix the invalid NTFS characters in batch and automatically by renaming the files with invalid characters to valid ones. It only fixes the characters in this set: <>:"\|?* which is pretty enough for most of the problems, but for advanced cases (like reserved names 'com', 'lpt') you must fix manually. Always double check the batch mv commands before running.

Fallacies:

  • Does not fix reserved names in Windows (like CON, PRN, AUX, NUL, COM1, COM2, etc).
  • Does not fix other illegal combination of characters like 'directory name cannot end with
@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 = "#,###.";
@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 / simjoin.spark
Last active June 20, 2018 06:30
Similarity Join
//Spark Similarity Join Algorithm
//Author: Selim Eren Bekçe
//Date: 2015-12-22
var lines = sc.textFile("tweets10K.tsv",8).map(s => s.split("\t"))
lines = lines.filter( t => t.length == 2 )
var pairs = lines.flatMap( s => {
val rid = s(0) // record id
val text = s(1) // text to be tokenized
val tokens = text.split("[^\\p{L}\\p{Nd}/:]") // split on non-alphanumeric chars
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 / 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.
*/