Posted
Filed under C#

[원문]
http://stackoverflow.com/questions/4161873/reduce-image-size-c-sharp

public static void SaveJpeg(string path, Image img, int quality)
        {
            if (quality < 0 || quality > 100)
                throw new ArgumentOutOfRangeException("quality must be between 0 and 100.");

            // Encoder parameter for image quality
            EncoderParameter qualityParam = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, quality);
            // JPEG image codec
            ImageCodecInfo jpegCodec = GetEncoderInfo("image/jpeg");
            EncoderParameters encoderParams = new EncoderParameters(1);
            encoderParams.Param[0] = qualityParam;
            img.Save(path, jpegCodec, encoderParams);
        }

        /// <summary>
        /// Returns the image codec with the given mime type
        /// </summary>
        private static ImageCodecInfo GetEncoderInfo(string mimeType)
        {
            // Get image codecs for all image formats
            ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders();

            // Find the correct image codec
            for (int i = 0; i < codecs.Length; i++)
                if (codecs[i].MimeType == mimeType)
                    return codecs[i];

            return null;
        }

2016/03/04 10:58 2016/03/04 10:58
Posted
Filed under nginx
다음과 같은 오류가 발생한다면, 버퍼 사이즈를 nginx에 설정 해줘야한다.

20xx/xx/xx xx:xx:xx [warn] ….an upstream response is buffered to a temporary file /var/cache/nginx/proxy_temp/xxxx while readi
ng upstream, client: xxx.xxx.xxx.xxx, server: aaa.aaaa.aaa.com, request: “GET /font/NanumGothic-Regular.woff HTTP/1.1”, upstream: “http:
//127.0.0.1:111/font/NanumGothic-ExtraBold.eot”,

http, location , server 중 아무데나 아래 값 추가 할 수 있음.
location에 추가함 .

proxy_buffering   on;
proxy_buffer_size    1024k;
proxy_buffers        1024   1024k;
client_body_buffer_size1024k;
proxy_busy_buffers_size1024k;
2016/02/24 09:54 2016/02/24 09:54
Posted
Filed under C#

[refference]http://stackoverflow.com/questions/3395381/c-sharp-converting-a-string-containing-a-floating-point-to-an-integer

var
a =(int)Convert.ToDouble("1.2");

Note if you're using comma as a number separator in your operating system, you have to use IFormatProvider:

var a =(int)Convert.ToDouble("1.2",CultureInfo.InvariantCulture.NumberFormat);

Another way to accomplish this task:

var a =int.Parse("1.2".Split('.')[0]);

2016/02/12 18:38 2016/02/12 18:38
Posted
Filed under C#
I found this solution to work for me when trying to access a file share on another computer.  It basically simulates doing a NET USE command where you can specify the credentials to use on the remote end.  The nice part is that you do not have to impersonate the user and it works across domains and workgroup computers.

First, declare these functions and types in your class.

using System.Reflection;
using System.Runtime.InteropServices;
using System.ComponentModel;

public class YourClass {
[DllImport("mpr.dll")]
private static extern int WNetAddConnection2A(ref NetResource pstNetRes, string psPassword, string psUsername, int piFlags);
[DllImport("mpr.dll")]
private static extern int WNetCancelConnection2A(string psName, int piFlags, int pfForce);

[StructLayout(LayoutKind.Sequential)]
private struct NetResource {
    public int iScope;
    public int iType;
    public int iDisplayType;
    public int iUsage;
    public string sLocalName;
    public string sRemoteName;
    public string sComment;
    public string sProvider;
}

private const int RESOURCETYPE_DISK = 0x1;

Then, add these two methods.
   
    private void LoginToShare(string serverName, string shareName, string user, string password) {
        string destinationDirectory = string.Format(@"\\{0}\{1}", serverName, shareName);

        NetResource nr = new NetResource();
        nr.iScope = 2;
        nr.iType = RESOURCETYPE_DISK;
        nr.iDisplayType = 3;
        nr.iUsage = 1;
        nr.sRemoteName = destinationDirectory;
        nr.sLocalName = null;

        int flags = 0;
        int rc = WNetAddConnection2A(ref nr, password, user, flags);

        if (rc != 0) throw new Win32Exception(rc);
    }

    private void LogoutFromShare(string serverName, string shareName) {
        string destinationDirectory = string.Format(@"\\{0}\{1}", serverName, shareName);
        int flags = 0;
        int rc = WNetCancelConnection2A(destinationDirectory, flags, Convert.ToInt32(false));
    }


In your code, call the LoginToShare with the server, share, user, and password needed.  Then simply use the standard \\server\share\path conventions for accessing files on remote computers.  Call the LogoutFromShare when you're done.

http://www.nullskull.com/q/10116970/accessing-shared-folder-on-a-network-using-c-code.aspx

2016/01/26 10:05 2016/01/26 10:05
Posted
Filed under spring framework
[출처] :http://stackoverflow.com/questions/16712462/many-commandname-for-one-form-in-spring-mvc
public
classCombinedCommand(){Activity activity;Etabl etabl;//Getter and setter}

jsp:

<form:form
  action="${pageContext.request.contextPath}/ajouter_activite"
  method="post" commandName="combinedCommand"">...<form:input type="text"path="activity.x"/>...<form:input type="text"path="etabl.y"/>...</form:form>
2015/12/14 11:24 2015/12/14 11:24
Posted
Filed under JSP, JAVA
[원문]http://sexy.pe.kr/tc/764


자바 Math 클래스에서 실수값 반올림이나 올림, 버림, 절대값을 구해주는 메서드가 있다.

반올림
static long Math.round(double a)
static int Math.round(float a)
예) System.out.println(Math.round(100.56)); //결과: 101


올림
static double ceil(double a)

예) System.out.println(Math.ceil(100.56)); //결과: 101.0


버림
static double floor(double a)

예) System.out.println(Math.floor(100.56)); //결과: 100.0


절대값
static double abs(double a)
static float abs(float a)
static int abs(int a)
static long abs(long a)

예) System.out.println(Math.abs(-100.56)); //결과: 100.56


참고로 소수 둘째자리에서 반올림을 하고 싶다고 하면 아래와 같이 응용한다.

double a = 100.22516;
double b = Math.round(a*100d) / 100d;
System.out.println(b); //결과: 100.23

원리는 차근차근 따라해 보면 쉽다.
일반 round() 메서드는 소수첫째자리에서 반올림 되기때문에 내가 반올림 하고자하는 자리수가 첫번째 소수점자리가 되도록 10 제곱을 곱해준다.
즉, 소수 2번째 자리까지 구하기 때문에 a에 10^2 하게되면 10022.516이 된다.
여기에서 반올림 한후 다시 나눈만큼 곱해주면 원래 소수 자리로 복원되게 된다.

다른 방법으로는 서식출력이 가능한 표준출력 메서드를 이용한 방법이다.
double a = 100.22516;
System.out.printf("%.2f",a); //결과 100.23

소수 둘째자리 실수로 반올림하여 출력하는 메서드이다.


간단한 내용이면서도 자주 활용되는 메서드에 대해 정리해보았습니다.
2015/12/03 16:14 2015/12/03 16:14
Posted
Filed under JSP, JAVA
[원문]http://hellogk.tistory.com/85

/**
 * Pathvariable example
 * @return
 */
@RequestMapping("/page/{var}")
public String page(@PathVariable String var){
    String returnUrl = "";
    if(var.equals("one")) {
        returnUrl = "page1";
    } else if(var.equals("two")) {
        returnUrl = "page2";
    }
    return returnUrl;
}
2015/11/18 17:46 2015/11/18 17:46
Posted
Filed under Linux
스프링의 web.xml에 utf-8 filter 를 추가 해주고도  한글이 께진다면 
tomcat 서버의 다음과 같이 설정을 해주면 한글 깨짐을 방지 할 수 있다.

/usr/local/tomcat/conf/server.xml

 <Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" URIEncoding="UTF-8"  />

2015/11/10 10:03 2015/11/10 10:03
Posted
Filed under PHP
foreach($_REQUEST as $key => $value ){
  ${"$key"} = $value;
}
2015/11/04 18:01 2015/11/04 18:01
Posted
Filed under centos7

If you receive an error while restarting IPtables on your virtual machine that includes : raw nat mangle filter [FAILED] or similar, this is a known error with CentOS 5 / CentOS 6 on virtual architectures. You simply need to modify the : /etc/init.d/iptables file.

===참고
https://www.hostvirtual.com/kb/6383/IPtables-returns-an-error--security-raw-nat-mangle-filter-FAILED.html
===

Next, locate the below text, you can search for 'setting chains' Next add the lines labeled with + to the file, after the line with: case "$i"

vi /etc/init.d/iptables

echo -n $"${IPTABLES}: Setting chains to policy $policy: "
    ret=0
    for i in $tables; do
        echo -n "$i "
        case "$i" in

<!-- 추가된 부분 -->
+           security)

+               $IPTABLES -t filter -P INPUT $policy \
+                   && $IPTABLES -t filter -P OUTPUT $policy \
+                   && $IPTABLES -t filter -P FORWARD $policy \
+                   || let ret+=1
+               ;;


            raw)
                $IPTABLES -t raw -P PREROUTING $policy \
                    && $IPTABLES -t raw -P OUTPUT $policy \
                    || let ret+=1
                ;;

2015/11/02 16:33 2015/11/02 16:33