Count:
3 | 4 | 5 | 18 | -------------------------------------------------------------------------------- /figma-plugin-image-filler/webpack.config.js: -------------------------------------------------------------------------------- 1 | const path = require('path') 2 | const VueLoaderPlugin = require('vue-loader/lib/plugin') 3 | const HtmlWebpackPlugin = require('html-webpack-plugin') 4 | const HtmlWebpackInlineSourcePlugin = require('html-webpack-inline-source-plugin') 5 | 6 | module.exports = (env, argv) => ({ 7 | // This is necessary because Figma's 'eval' works differently than normal eval 8 | devtool: argv.mode === 'production' ? false : 'inline-source-map', 9 | 10 | entry: { 11 | ui: './src/ui.js', 12 | main: './src/code.ts', 13 | }, 14 | 15 | resolveLoader: { 16 | modules: [path.join(__dirname, 'node_modules')] 17 | }, 18 | 19 | module: { 20 | rules: [ 21 | // Converts Vue code to JavaScript 22 | { test: /\.vue$/, loader: 'vue-loader', exclude: /node_modules/ }, 23 | 24 | // Converts TypeScript code to JavaScript 25 | { test: /\.tsx?$/, use: 'ts-loader', exclude: /node_modules/ }, 26 | 27 | // Enables including CSS by doing "import './file.css'" in your TypeScript code 28 | { test: /\.css$/, loader: [{ loader: 'style-loader' }, { loader: 'css-loader' }] }, 29 | 30 | // Allows you to use "<%= require('./file.svg') %>" in your HTML code to get a data URI 31 | { test: /\.(png|jpg|gif|webp|svg)$/, loader: [{ loader: 'url-loader' }] }, 32 | ], 33 | }, 34 | 35 | resolve: { 36 | // Webpack tries these extensions for you if you omit the extension like "import './file'" 37 | extensions: ['.tsx', '.ts', '.jsx', '.js', '.vue', '.json'], 38 | alias: { 39 | 'vue$': 'vue/dist/vue.esm.js' 40 | } 41 | }, 42 | 43 | output: { 44 | filename: '[name].js', 45 | path: path.resolve(__dirname, 'build'), 46 | }, 47 | 48 | plugins: [ 49 | new HtmlWebpackPlugin({ 50 | template: './src/ui.html', 51 | filename: 'ui.html', 52 | inlineSource: '.(js)$', 53 | chunks: ['ui'], 54 | }), 55 | new HtmlWebpackInlineSourcePlugin(), 56 | new VueLoaderPlugin() 57 | ], 58 | 59 | node: { 60 | // prevent webpack from injecting useless setImmediate polyfill because Vue 61 | // source contains it (although only uses it if it's native). 62 | setImmediate: false, 63 | // prevent webpack from injecting mocks to Node native modules 64 | // that does not make sense for the client 65 | dgram: 'empty', 66 | fs: 'empty', 67 | net: 'empty', 68 | tls: 'empty', 69 | child_process: 'empty' 70 | } 71 | }); 72 | 73 | 74 | -------------------------------------------------------------------------------- /flask-kafka/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM python:3.7 2 | COPY index.html /app/ 3 | COPY requirements.txt /app/ 4 | COPY app.py /app/ 5 | WORKDIR /app 6 | RUN pip install -r requirements.txt 7 | CMD python -u app.py 8 | -------------------------------------------------------------------------------- /flask-kafka/app.py: -------------------------------------------------------------------------------- 1 | from flask import Flask, send_from_directory 2 | from flask_cors import CORS, cross_origin 3 | from flask_socketio import SocketIO, emit 4 | from kafka import KafkaProducer, KafkaConsumer, TopicPartition 5 | import uuid 6 | 7 | app = Flask(__name__) 8 | socketio = SocketIO(app, cors_allowed_origins="*") 9 | cors = CORS(app) 10 | app.config['CORS_HEADERS'] = 'Content-Type' 11 | 12 | BOOTSTRAP_SERVERS = 'kafka:9092' 13 | TOPIC_NAME = 'stackbox' 14 | 15 | 16 | @app.route('/') 17 | @cross_origin() 18 | def home(): 19 | return send_from_directory('/app', "index.html") 20 | 21 | """ Kafka endpoints """ 22 | 23 | 24 | @socketio.on('connect', namespace='/kafka') 25 | def test_connect(): 26 | emit('logs', {'data': 'Connection established'}) 27 | 28 | 29 | @socketio.on('kafkaconsumer', namespace="/kafka") 30 | def kafkaconsumer(message): 31 | consumer = KafkaConsumer(group_id='consumer-1', 32 | bootstrap_servers=BOOTSTRAP_SERVERS) 33 | tp = TopicPartition(TOPIC_NAME, 0) 34 | # register to the topic 35 | consumer.assign([tp]) 36 | 37 | # obtain the last offset value 38 | consumer.seek_to_end(tp) 39 | lastOffset = consumer.position(tp) 40 | consumer.seek_to_beginning(tp) 41 | emit('kafkaconsumer1', {'data': ''}) 42 | for message in consumer: 43 | emit('kafkaconsumer', {'data': message.value.decode('utf-8')}) 44 | if message.offset == lastOffset - 1: 45 | break 46 | consumer.close() 47 | 48 | 49 | @socketio.on('kafkaproducer', namespace="/kafka") 50 | def kafkaproducer(message): 51 | print(TOPIC_NAME) 52 | print(BOOTSTRAP_SERVERS) 53 | producer = KafkaProducer(bootstrap_servers=BOOTSTRAP_SERVERS) 54 | producer.send(TOPIC_NAME, value=bytes(str(message), encoding='utf-8'), key=bytes(str(uuid.uuid4()), encoding='utf-8')) 55 | emit('logs', {'data': 'Added ' + message + ' to topic'}) 56 | emit('kafkaproducer', {'data': message}) 57 | producer.close() 58 | kafkaconsumer(message) 59 | 60 | 61 | if __name__ == '__main__': 62 | socketio.run(app, host='0.0.0.0', port=80) 63 | -------------------------------------------------------------------------------- /flask-kafka/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | 3 | services: 4 | kafka: 5 | environment: 6 | HOSTNAME_COMMAND: "route -n | awk '/UG[ \t]/{print $$2}'" 7 | KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181 8 | image: wurstmeister/kafka 9 | ports: 10 | - "9092" 11 | volumes: 12 | - /var/run/docker.sock:/var/run/docker.sock 13 | depends_on: 14 | - zookeeper 15 | restart: always 16 | 17 | zookeeper: 18 | image: wurstmeister/zookeeper 19 | restart: always 20 | 21 | app: 22 | build: . 23 | ports: 24 | - "80:80" 25 | depends_on: 26 | - kafka 27 | restart: always 28 | -------------------------------------------------------------------------------- /flask-kafka/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 30 | 31 | 32 | 36 |