Skip to content

Instantly share code, notes, and snippets.

View roman01la's full-sized avatar
🇺🇦

Roman Liutikov roman01la

🇺🇦
View GitHub Profile
@roman01la
roman01la / api-proxy.js
Created December 22, 2014 12:03
Calling REST API with ES6 Proxies
var EndPoint = function (baseUrl) {
var request = function (type, url) {
return new Promise(function (resolve, reject) {
var xhr = new XMLHttpRequest();
xhr.open(type, url);
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.responseType = 'json';
module.exports = {
watch: true,
entry: [
__dirname + '/src/app'
],
module: {
loaders: [
{ test: /\.js$/, exclude: /node_modules/, loaders: ['6to5-loader?optional=coreAliasing'] }
]
@roman01la
roman01la / main.jsx
Created January 26, 2015 01:39
Reactive React components using Most
import React from 'react';
import most from 'most';
let push = ({source: {sink}}, event) => {
try {
sink.event(event.type, event);
} catch (err) {
sink.error(event.type, err);
}
@roman01la
roman01la / react-flux-store.jsx
Created January 26, 2015 12:14
How to avoid storing application data within controller-view.
import React from 'react';
import AppActions from './actions';
import ItemsStore from './items-store';
let List = React.createClass({
componentDidMount() {
ItemsStore.addChangeListener(this.forceUpdate.bind(this));
},
@roman01la
roman01la / button.jsx
Created January 26, 2015 14:06
Mixin for handling DOM events via React assignment style using Most
import React from 'react';
import ReactDOMMostify from 'react-dom-mostify';
let Button = React.createClass({
mixins: [ReactDOMMostify],
componentWillMount() {
@roman01la
roman01la / main.es6
Created February 18, 2015 00:41
Property with a custom getter to get merged Set objects as a single Set
let obj = {
a: new Set([1,2,3]),
b: new Set([4,2,6,7]),
c: new Set([6,2,1,0])
};
Object.defineProperties(obj, {
all: {
@roman01la
roman01la / compose.js
Created April 1, 2015 17:04
compose.js
var compose = function() {
var funcs = arguments;
return function() {
var args = arguments;
for (var i = funcs.length; i --> 0;) {
args = [funcs[i].apply(this, args)];
}
return args[0];
};
};
@roman01la
roman01la / Server.c
Created April 1, 2015 21:40
Server.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <winsock2.h>
#pragma comment(lib,"ws2_32.lib")
#define PORTNUM 1738
#define BUFMAX 1024
@roman01la
roman01la / test.js
Created April 8, 2015 12:46
Simple JS testing with zero deps
import MyModule from 'my-module'; // module to test
let test = 'test'; // mock data
let testMsg = 'Should return message: ' + test; // test message
MyModule({ test }, data => {
if (data.res !== test) {
@roman01la
roman01la / sample.hs
Created April 10, 2015 14:48
sample.hs
get :: String -> IO String
get url = getResponseBody =<< simpleHTTP (getRequest url)
get :: String -> IO String
get url = getResponseBody =<< simpleHTTP $ getRequest url
get :: String -> IO String
get url = getResponseBody . simpleHTTP $ getRequest url