Skip to content

Instantly share code, notes, and snippets.

View MinCha's full-sized avatar

Min Cha MinCha

  • GGtics
  • Gwanggyo
View GitHub Profile
@MinCha
MinCha / gist:7784650
Created December 4, 2013 09:18
Java Byte Code when doing auto-boxing
@Test
public void autoBoxing() {
Long v = 555L;
v = v + 2;
v = v + 3;
System.out.println(v);
}
@Test
public void autoBoxing2() {
@MinCha
MinCha / gist:7781468
Last active December 30, 2015 05:19
Java Byte Code when getting from array
class HashBasedMutexProvider {
private static final int DEFAULT_DISPERSION = 1000;
private List<Object> mutexes = new ArrayList<Object>();
private int dispersion;
HashBasedMutexProvider() {
this(DEFAULT_DISPERSION);
}
HashBasedMutexProvider(int dispersion) {
@MinCha
MinCha / gist:7766438
Last active December 30, 2015 02:59
Java Byte Code when constructing String
public String a() {
String msg = "aaa";
return msg;
}
public String b() {
String msg = new String("aaa");
return msg;
}
@MinCha
MinCha / gist:7700804
Created November 29, 2013 02:29
Java SMTP
public class SMTPTest {
private final String from = "some@sender.com";
@Test
public void shouldSendMail() throws MessagingException {
mailTo("some@receiver.com");
}
private void mailTo(String to) throws MessagingException {
Properties props = new Properties();
@MinCha
MinCha / gist:7262149
Created November 1, 2013 07:57
start ElasticSearch multiple instances
#!/bin/bash
ip="`/sbin/ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'`"
for ((i=0; i<$1; i++)); do
hport=$(expr 21000 + $i)
tport=$(expr 22000 + $i)
name=$ip+$i
../bin/elasticsearch -Des.cluster.name=music-es-dev -Des.multicast.enabled=true -Des.http.port=$hport -Des.transport.tcp.port=$tport -Des.index.number_of_shards=10 -Des.index.number_of_replicas=4 -Des.node.name=$name
done
@MinCha
MinCha / gist:7095749
Last active December 26, 2015 04:49
ElasticSearch Install Script
#!/bin/bash
es="elasticsearch-0.90.11"
ip="`/sbin/ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'`"
http_port=21000
trans_port=21001
wget https://download.elasticsearch.org/elasticsearch/elasticsearch/$es.tar.gz
gzip -d $es.tar.gz
tar -xvf $es.tar
mv ./$es/config/elasticsearch.yml ./$es/config/elasticsearch.yml.old
@MinCha
MinCha / gist:7024405
Created October 17, 2013 12:56
Linux Clear File Cache
alias clear-cache='sync && echo 3 | sudo tee /proc/sys/vm/drop_caches'
@MinCha
MinCha / gist:6681160
Last active December 23, 2015 19:09
Nginx conf as reserve proxy including server-status page
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/
user www;
worker_processes 2;
error_log /home/www/logs/nginx/error.log;
#error_log /var/log/nginx/error.log notice;
#error_log /var/log/nginx/error.log info;
@MinCha
MinCha / gist:6575810
Created September 16, 2013 01:32
Batch Insert by Perl
#!/usr/bin/perl
use DBI;
use Time::HiRes qw(time);
use List::Util qw(shuffle);
my $dbh = DBI->connect("DBI:mysql:database=test;host=localhost;rewriteBatchedStatements=true", "root", "", {'RaiseError' => 1});
#insert_seq(5000000, 'nulltest');
#insert_seq(300000, 'seqtest');
@MinCha
MinCha / gist:5297964
Created April 3, 2013 02:25
JDBC MySQL Cursor Example
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try {
conn = template.getDataSource().getConnection();
stmt = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
stmt.setFetchSize(Integer.MIN_VALUE);
rs = stmt.executeQuery("SELECT * FROM push");
while (rs.next()) {