Skip to content

Instantly share code, notes, and snippets.

View barbagrigia's full-sized avatar

Vlad Trukhin barbagrigia

View GitHub Profile
@barbagrigia
barbagrigia / Problem.md
Created July 11, 2016 14:36 — forked from Centaur/Problem.md
Scala vs Clojure

Treat or Trick

Everyone knows what Halloween is and how children love it. Children in costumes travel from house to house asking for treats with a phrase "Trick or treat". After that, they divide the treats equally among all. This year, they collected tons of candies, and need your help to share everything equally. You know that children receive different number of candies depending on their costume: vampire gets 3 candies from one house, zombie – 4 candies, and witch – 5 candies. That is, three children in three different costumes get 3+4+5=12 candies from one house.

Input sample:

The first argument is a path to a file. Each line includes a test case with number of vampires, zombies, witches, and houses that they visited.

For example:

;; from db
(def coll [{:id 1 :name ""}
{:id 2 :name "item 1" :parent 1}
{:id 3 :name "item 2" :parent 1}
{:id 4 :name "item 3" :parent 2}
{:id 5 :name "item 4" :parent 2}
{:id 6 :name "item 5" :parent 2}
{:id 7 :name "item 6" :parent 4}])
;; требуемый json
@barbagrigia
barbagrigia / app.js
Created November 15, 2016 23:19 — forked from roman01la/app.js
Minimal setup for efficient state management and rendering in React with single atom state
import React from 'react';
import { render } from 'react-dom';
import Root from './components/root.jsx';
import { silentSwap } from './lib/atom';
import { fromJS } from 'immutable';
import './stores/ui';
const initialState = {
ui: {
@barbagrigia
barbagrigia / react-native-stylesheet.cljs
Created November 15, 2016 23:20 — forked from roman01la/react-native-stylesheet.cljs
Access React Native compiled styles map using Clojure's keywords.
(def stylesheet (.-StyleSheet ReactNative))
(defn create-stylesheet [styles]
(->> styles
(clj->js)
(.create stylesheet)
(js->clj)
(clojure.walk/keywordize-keys)))
; usage
import React, { Component } from 'react';
import {
PixelRatio,
View,
TextInput,
Text,
StyleSheet,
PropTypes
} from 'react-native';
@barbagrigia
barbagrigia / core.cljs
Created November 15, 2016 23:21 — forked from roman01la/core.cljs
Reagent + react-motion
;; Reagent component
(defn new-task-input-component [props]
(let [new-task (subscribe [:get-new-task])]
[view
{:style (assoc (:slide-up styles) :transform [{:translateY (- (:y props))}])}
[input {:style (:input styles)
:default-value @new-task
:auto-focus true
:on-change-text #(dispatch [:set-new-task %])
:on-submit-editing #(do
@barbagrigia
barbagrigia / webpack.js
Created November 21, 2016 14:58 — forked from Couto/webpack.js
Fetch polyfill with webpack
var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var path = require('path');
var folders = {
APP: path.resolve(__dirname, '../app'),
BUILD: path.resolve(__dirname, '../build'),
BOWER: path.resolve(__dirname, '../bower_components'),
NPM: path.resolve(__dirname, '../node_modules')
};
angular
.module('PersonMod', [])
.factory('Person', function () {
function Person() {};
Person.create = function (data) {
return new Person(data);
};
return Person;
})
.service('PersonLoader', [function() {
@barbagrigia
barbagrigia / export-syntax.js
Created March 15, 2017 22:59 — forked from caridy/export-syntax.js
ES6 Module Syntax Table
// default exports
export default 42;
export default {};
export default [];
export default foo;
export default function () {}
export default class {}
export default function foo () {}
export default class foo {}