Skip to content

Instantly share code, notes, and snippets.

View volyx's full-sized avatar

Dmitrii Volykhin volyx

View GitHub Profile
public void test() {
ScheduledExecutorService ex = Executors.newSingleThreadScheduledExecutor();
ex.scheduleAtFixedRate(new Runnable(){
@Override
public void run() {
scanDirectory(new File("."));
}}, 1, 1, TimeUnit.SECONDS);
}
private void scanDirectory(File directory) {
@volyx
volyx / angular medium editor
Created November 19, 2014 15:41
angular medium editor
<!DOCTYPE html>
<html ng-app="demo">
<head>
<meta charset="UTF-8">
<title>angularjs medium editor | demo</title>
<link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" href="css/demo.css">
<link rel="stylesheet" href="../../..bower_components/medium-editor/dist/css/medium-editor.css">
<link rel="stylesheet" href="../../..bower_components/medium-editor/dist/css/themes/default.css">
<style>
@volyx
volyx / Nginx tomcat
Last active August 29, 2015 14:13
Nginx tomcat
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
public class PlainEchoServer {
public void serve(int port) throws IOException {
final ServerSocket socket = new ServerSocket(port); // #1
@volyx
volyx / ByteBuffer.java
Last active August 29, 2015 14:15
ByteBuffer.java
Channel inChannel = ....;
ByteBuffer buf = ByteBuffer.allocate(48);
int bytesRead = -1;
do {
bytesRead = inChannel.read(buf); #1
if (bytesRead != -1) {
buf.flip(); #2
while(buf.hasRemaining()){
System.out.print((char) buf.get()); #3
}
@volyx
volyx / PlainNioEchoServer.java
Created February 10, 2015 16:49
PlainNioEchoServer.java
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.nio.ByteBuffer;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
import java.util.Iterator;
import java.util.Set;
@volyx
volyx / PlainNio2EchoServer.java
Created February 11, 2015 12:27
PlainNio2EchoServer.java
import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.AsynchronousServerSocketChannel;
import java.nio.channels.AsynchronousSocketChannel;
import java.nio.channels.CompletionHandler;
import java.util.concurrent.CountDownLatch;
public class PlainNio2EchoServer {
def a = [1,5,7,8,45,7,45,34,45,78,9]
k = 10
k0 = 0
void printArr(a) {
a.each{i ->
print i + ', '
@volyx
volyx / Gruntfile.js
Created April 9, 2015 17:30
Gruntfile.js Angularjs
module.exports = function (grunt) {
grunt.loadNpmTasks('grunt-karma');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-jsdoc');
grunt.initConfig({
'pkg': grunt.file.readJSON('package.json'),
http.
csrf().disable().
sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).
and().
authorizeRequests().
// antMatchers(HttpMethod.OPTIONS, "/**").permitAll().
antMatchers(actuatorEndpoints()).hasRole(backendAdminRole).
antMatchers(ApiController.AUTHENTICATE_URL).permitAll().
antMatchers(HttpMethod.GET, ApiController.API_TRIPS).permitAll().