Skip to content

Instantly share code, notes, and snippets.

@bekce
bekce / Solution.java
Created January 3, 2017 11:39
[scratchpad] some problem solutions
import java.io.*;
import java.util.*;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.RecursiveAction;
import java.util.concurrent.RecursiveTask;
/**
* Created by seb on 11/9/2016.
*/
public class Solution {
@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
@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
#!/bin/sh
if [ $# -ne 4 ]
then
echo "Usage: <new-db-name> <new-user> <new-pass> <root-pass>"
exit 1
fi
dbname=$1
newuser=$2
newpass=$3
rootpass=$4
@bekce
bekce / install_ruby.sh
Created July 29, 2016 07:54
Install Ruby 2.x with rbenv
# Install ruby on a clean ubuntu 14.04 machine (tested)
cd
apt-get install -y curl git gcc make libssl-dev libreadline-dev zlib1g-dev
git clone git://github.com/sstephenson/rbenv.git .rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
. ~/.bashrc
CONFIGURE_OPTS="--disable-install-rdoc" rbenv install 2.3.1
rbenv local 2.3.1
@bekce
bekce / upgrade_mongodb.sh
Last active February 22, 2017 13:14
Upgrade MongoDB from 2.x to 3.4.x directly
sudo -s # shell out to root
cd
mongodump --out dump
service mongodb stop
# check if stopped and kill process if not
ps faux|grep mongod # then kill softly
ps faux|grep mongod|awk '{print $2}'|head -n 1|xargs kill
rm /var/lib/mongodb/mongod.lock
# backup data folder and configurations for extra protection
tar -cvzf data.tgz /var/lib/mongodb
@bekce
bekce / gist:9551f3f9c95ea4614c562ea34f9f5bbb
Last active June 8, 2016 13:46
Get new AccuWeather apiKey. This bash script retrieves the latest temporary apiKey for https://apidev.accuweather.com for your testing purposes.
wget -q -O - https://apidev.accuweather.com/developers/samples | grep "var apiKey" | cut -d'"' -f 2
@bekce
bekce / automated-building-deployment-docker-microservices
Last active April 21, 2016 15:03
Automated Building and Deployment of Docker Microservices
[http://sebworks.com](http://sebworks.com)
@bekce
bekce / SSLTest.java
Last active April 4, 2016 13:27
Test SSL connection to specified host and port. Sends given first message and prints the results. I've used it to test my SSL certificate on my SMTP server.
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;
public class SSLTest {
@bekce
bekce / JPA.md
Last active October 17, 2015 16:20
JPA concise examples

JPA concise examples

One to one

class Customer
  @OneToOne(fetch=FetchType.LAZY)
  @JoinColumn(name="address_fk",nullable=false)
  Address address;