Skip to content

Instantly share code, notes, and snippets.

View AndrejGajdos's full-sized avatar

Andrej Gajdos AndrejGajdos

View GitHub Profile
@AndrejGajdos
AndrejGajdos / Server.java
Created January 16, 2016 21:05
ActiveMQ Broker
package activemq.test;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import org.apache.activemq.api.core.TransportConfiguration;
import org.apache.activemq.core.config.Configuration;
import org.apache.activemq.core.config.impl.ConfigurationImpl;
import org.apache.activemq.core.remoting.impl.netty.NettyAcceptorFactory;
java.naming.factory.initial = org.apache.activemq.jndi.ActiveMQInitialContextFactory
# use the following property to configure the default connector
java.naming.provider.url = tcp://localhost:61616
# register some topics in JNDI using the form
# topic.[jndiName] = [physicalName]
topic.MyTopic = example.MyTopic
import java.text.SimpleDateFormat;
import java.util.Date;
import org.apache.activemq.ActiveMQConnectionFactory;
import javax.jms.Connection;
import javax.jms.DeliveryMode;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
@AndrejGajdos
AndrejGajdos / DataGrid.jsx
Last active January 31, 2016 17:53
Data props diffing in a React component and re-initialize a cell of jQuery object without re-initializing jQuery grid object in the componentDidUpdate method (and without re-rendering the whole React component). Code snippet in blog post http://andrejgajdos.com/how-to-avoid-refactoring-in-your-first-react-application/
let diff = require('immutablediff');
shouldComponentUpdate(nextProps, nextState) {
let propsDiff = diff(this.props.data, nextProps.data);
if (propsDiff.size === 1) {
let operation = propsDiff.get(0).get("op");
let replacedObj = propsDiff.get(0).get("value");
switch (operation) {
case "replace":
if (Immutable.Map.isMap(replacedObj)) {
@AndrejGajdos
AndrejGajdos / webpack.config.js
Last active September 3, 2018 00:40
A sample project to demonstrate bundling ES6, React, SASS and Bootstrap with Webpack (http://andrejgajdos.com/setting-up-webpack-for-es6-react-sass-and-bootstrap/)
var webpack = require('webpack');
var merge = require('webpack-merge');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var NpmInstallPlugin = require('npm-install-webpack-plugin');
var autoprefixer = require('autoprefixer');
const TARGET = process.env.npm_lifecycle_event;
console.log("target event is " + TARGET);
var common = {
@AndrejGajdos
AndrejGajdos / config.json
Created February 27, 2016 20:33
Config file for a gulp task to convert SVG Sprite into PNG images
{
"image": {
"color": "#BFBFBF",
"width": 36,
"height": 36
},
"paths": {
"svg_sprite": "./src/icons.svg"
}
}
@AndrejGajdos
AndrejGajdos / gulpfile.js
Last active February 27, 2016 20:52
First part of gulp tak – converting SVG Sprite to separate files
var fs = require('fs');
var DOMParser = require('xmldom').DOMParser;
var timestamp = require('console-timestamp');
var config = require('./config.json');
// open svg sprite file
fs.readFile(config.paths.svg_sprite, 'utf8', function (err, data) {
if (err) {
return console.log(timestamp('[hh:mm:ss] ') + "Read file " + config.paths.svg_sprite + " error: " + err);
}
@AndrejGajdos
AndrejGajdos / gulpfile.js
Created February 27, 2016 21:23
Second part of gulp tak – converting SVG Sprite to separate files
var gulp = require('gulp');
var config = require('./config.json');
var del = require('del');
var svg2png = require('gulp-svg2png');
var graphicsmagick = require('gulp-gm');
...
gulp.src("./build/svg_files_" + colorName + "/*.svg")
.pipe(svg2png())
.pipe(gulp.dest("./build/png_files_" + colorName))
@AndrejGajdos
AndrejGajdos / flatten.js
Created March 20, 2016 19:34
Function for flattening nested array
/**
* Flatten nested array
* @param {Array} array Nested array
* @return {Array} Flat array
*/
function flatten(array) {
return array.reduce(function (flat, toFlatten) {
// if current item is array flatten it, otherwise concatenate value to processed flat array
return flat.concat(Array.isArray(toFlatten) ? flatten(toFlatten) : toFlatten);
}, []);
@AndrejGajdos
AndrejGajdos / .eslintrc.js
Created August 8, 2017 12:50 — forked from nkbt/.eslintrc.js
Strict ESLint config for React, ES6 (based on Airbnb Code style)
{
"env": {
"browser": true,
"node": true,
"es6": true
},
"plugins": ["react"],
"ecmaFeatures": {