This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component | |
public class SimpleCORSFilter implements Filter { | |
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { | |
HttpServletResponse response = (HttpServletResponse) res; | |
response.setHeader("Access-Control-Allow-Origin", "*"); | |
response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE"); | |
response.setHeader("Access-Control-Max-Age", "3600"); | |
response.setHeader("Access-Control-Allow-Headers", "Authorization"); | |
chain.doFilter(req, res); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* | |
* @author loind | |
* | |
*/ | |
@Provider | |
public class JerseyDefaultExceptionMapper implements ExceptionMapper<Throwable> { | |
private static final Logger logger = LoggerFactory.getLogger(DefaultExceptionMapper.class); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Created by loind on 11/25/2015. | |
* tested with application/* . not test with multi-part | |
*/ | |
public class JerseyRawBodyRequestFilter implements ContainerRequestFilter { | |
private static final Logger logger = LoggerFactory.getLogger(RawBodyRequestFilter.class); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//GEOIP | |
// http://maxmind.github.io/GeoIP2-java/ | |
//https://github.com/maxmind/GeoIP2-java | |
//http://dev.maxmind.com/geoip/geoip2/geoip2-csv-databases/ | |
File database = new File("C:/Users/loind/Desktop/GeoIP/GeoLite2-City.mmdb"); | |
// This creates the DatabaseReader object, which should be reused across | |
// lookups. | |
DatabaseReader reader = new DatabaseReader.Builder(database).fileMode(Reader.FileMode.MEMORY_MAPPED).build(); | |
InetAddress ipAddress = InetAddress.getByName("14.162.178.45"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.monitoringvn.utils.rest.filter; | |
import org.slf4j.Logger; | |
import org.slf4j.LoggerFactory; | |
import javax.servlet.http.HttpServletRequest; | |
import javax.ws.rs.container.ContainerRequestContext; | |
import javax.ws.rs.container.ContainerRequestFilter; | |
import javax.ws.rs.container.PreMatching; | |
import javax.ws.rs.core.Context; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Generated by install_server.sh ## | |
# Redis configuration file example. | |
# | |
# Note that in order to read the configuration file, Redis must be | |
# started with the file path as first argument: | |
# | |
# ./redis-server /path/to/redis.conf | |
# Note on units: when memory size is needed, it is possible to specify | |
# it in the usual form of 1k 5GB 4M and so forth: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void captureScreen(String fileName) throws Exception { | |
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); | |
Rectangle screenRectangle = new Rectangle(screenSize); | |
Robot robot = new Robot(); | |
BufferedImage image = robot.createScreenCapture(screenRectangle); | |
ImageIO.write(image, "png", new File(fileName)); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// http://stackoverflow.com/questions/30627583/hibernate-with-sql-server-fail-for-nvarchar-field-with-no-dialect-mapping | |
public class SQLServerUnicodeDialect extends org.hibernate.dialect.SQLServerDialect { | |
public SQLServerUnicodeDialect() { | |
super(); | |
registerColumnType(Types.CHAR, "nchar(1)"); | |
registerColumnType(Types.LONGVARCHAR, "nvarchar(max)" ); | |
registerColumnType(Types.VARCHAR, 4000, "nvarchar($l)"); | |
registerColumnType(Types.VARCHAR, "nvarchar(max)"); | |
registerColumnType(Types.CLOB, "nvarchar(max)" ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT convert(cast(convert(LATIN1_FIELD using latin1) as binary) using utf8) | |
FROM LATIN1_TABLE; | |
-- http://stackoverflow.com/questions/12756877/how-to-convert-latin1-swedish-ci-data-into-utf8-general-ci |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##http://www.hongkiat.com/blog/regex-web-developers/ | |
Regular expressions are a powerful tool that should be in every developer’s tool belt. They can match against a string of characters based on very complex parameters, which can save you a lot of time when building dynamic websites. | |
Web developers face different tasks than software developers but many of the same code fundamentals remain. Regular expressions (or regex) do have a steep initial learning curve, but they can be tremendously powerful when used correctly. | |
The trickiest part is learning the syntax and learning how to write your own regex code from scratch. To save time I’ve organized 30 different regex code snippets that you can incorporate into development projects. And since regex isn’t limited to a single language, you can apply these snippets to anything from JavaScript to PHP or Python. | |
1. Password Strength | |
1 |