Skip to content

Commit

Permalink
[+] demos
Browse files Browse the repository at this point in the history
  • Loading branch information
denvash committed Feb 18, 2019
1 parent c7b4f36 commit fca51c7
Show file tree
Hide file tree
Showing 40 changed files with 17,968 additions and 6 deletions.
54 changes: 54 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# NPM #
##########
# Ignore all directories called node_modules in current folder and any subfolders.
node_modules/
/node_modules/

# Packages #
############
*.7z
*.dmg
*.gz
*.bz2
*.iso
*.jar
*.rar
*.tar
*.zip
*.tgz
*.map

# Logs and databases #
######################
*.log
*.sql
*.env

# OS generated files #
######################
**.DS_Store*
ehthumbs.db
Icon?
Thumbs.db
._*

# Vim generated files #
######################
*.un~

# SASS #
##########
**/.sass-cache
**/.sass-cache/*
**/.map

# Composer #
##########
!assets/js/vendor/
wpcs/
/vendor/


# Project related
#################
images/inspire.png
11 changes: 11 additions & 0 deletions .markdownlint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"default": true,
"MD041": false,
"MD010": false,
"MD002": false,
"MD001": false,
"MD022": false,
"MD024": false,
"MD013": false,
"MD033": false
}
75 changes: 75 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# NPM #
##########
# Ignore all directories called node_modules in current folder and any subfolders.
node_modules/
/node_modules/

# Packages #
############
*.7z
*.dmg
*.gz
*.bz2
*.iso
*.jar
*.rar
*.tar
*.zip
*.tgz
*.map

# Logs and databases #
######################
*.log
*.sql
*.env

# OS generated files #
######################
**.DS_Store*
ehthumbs.db
Icon?
Thumbs.db
._*

# Vim generated files #
######################
*.un~

# SASS #
##########
**/.sass-cache
**/.sass-cache/*
**/.map

# Composer #
##########
!assets/js/vendor/
wpcs/
/vendor/

# Bower #
##########
assets/bower_components/*

# Codekit #
##########
/codekit-config.json
*.codekit
**.codekit-cache/*

# Compiled Files and Build Dirs #
##########
/README.html

# PhpStrom Project Files #
.idea/
library/vendors/composer
assets/img/.DS_Store

# NPM Ignore.
/imgages
/demo
/.vscode
images/shades-of-purple.gif
images/shades-of-purple.jpg
30 changes: 30 additions & 0 deletions .release-it.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"dry-run": false,
"verbose": false,
"force": true,
"non-interactive": true,
"increment": "minor",
"beforeChangelogCommand": "auto-changelog",
"safeBump": false,
"src": {
"commitMessage": "🍧 Release %s",
"tagAnnotation": "🍧 Release %s"
},
"npm": {
"publish": true
},
"github": {
"release": true,
"releaseName": "🍧 %s"
},
"prompt": {
"src": {
"status": true,
"commit": true,
"tag": true,
"push": true,
"release": true,
"publish": true
}
}
}
14 changes: 14 additions & 0 deletions demo/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# http://editorconfig.org
root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
max_line_length = off
trim_trailing_whitespace = false
3 changes: 3 additions & 0 deletions demo/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"python.linting.enabled": false
}
60 changes: 60 additions & 0 deletions demo/Cryptarithm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// https://www.codingame.com/training/hard/cryptarithm

/**
* Generates all permutations of a set.
* @param {Array|String} arr - The set of elements.
* @param {Number} size - Number of elements to choose from the set.
*/
function* permutation(arr, size = arr.length) {
const data = [];
const indicesUsed = [];
yield* permutationUtil(0);

/**
* @param {Number} index of permutation
* @return {Generator}
*/
function* permutationUtil(index) {
if (index === size) {
return yield this.clones ? data.slice() : data;
}
for (let i = 0; i < arr.length; i++) {
if (!indicesUsed[i]) {
indicesUsed[i] = true;
data[index] = arr[i];
yield* permutationUtil(index + 1);
indicesUsed[i] = false;
}
}
}
}

// We generate a permutation and checking if the sum is valid
const r = () => readline().split('');
const words = [...Array(+readline())].map(() => r());
const wordsTotal = r();

const dictionary = [...new Set([...words, wordsTotal].flat())].sort();

const permutationGenerator =
permutation([...Array(10).keys()], dictionary.length);

for (let permutation of permutationGenerator) {
const keyValueArray = dictionary.map((v, i) => [v, permutation[i]]);
const cryptMap = new Map(keyValueArray);
if (cryptMap.get(wordsTotal[0]) === 0) continue;

const wordToNumber =
(arr) => +arr.map((char) => cryptMap.get(char)).join('');

const sumWords =
words.map((word) => wordToNumber(word))
.reduce((sum, curr) => sum+=curr);

const sumTotal = wordToNumber(wordsTotal);

if (sumWords === sumTotal) {
cryptMap.forEach((value, key) => console.log(key, value));
break;
}
}
22 changes: 22 additions & 0 deletions demo/checkbox_with_label.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React from 'react'
import ReactDOM from 'react-dom'
import * as TestUtils from 'react-dom/test-utils'
import CheckboxWithLabel from '../CheckboxWithLabel'

it('CheckboxWithLabel changes the text after click', () => {
// Render a checkbox with label in the document
const checkbox = TestUtils.renderIntoDocument(
<CheckboxWithLabel labelOn="On" labelOff="Off" />
)

const checkboxNode = ReactDOM.findDOMNode(checkbox)

// Verify that it's Off by default
expect(checkboxNode.textContent).toEqual('Off')

// Simulate a click and verify that it is now On
TestUtils.Simulate.change(
TestUtils.findRenderedDOMComponentWithTag(checkbox, 'input')
)
expect(checkboxNode.textContent).toEqual('On')
})
26 changes: 26 additions & 0 deletions demo/clojure.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
(ns hello.world.clojure)

(defn sum [& numbers]
(if (empty? numbers)
0
(reduce + 0 numbers)))

(defn print-name [{:keys [first last age]}]
(println (str "Your name is " first " " last " and you are " age " years old.")))

(defn set-age [person new-age]
(assoc person :age new-age))

(defn hello-world []
(let [john {:first "John" :last "Smith" :age 65}
jack {:first "Jack" :last "Road" :age 76}
george {:first "George" :last "Way" :age 23}
george-junior (assoc george :age 6)
all-persons [john jack george george-junior]]

(doseq [person all-persons]
(print-name person))

(println (str "Total age is: " (apply sum (map :age all-persons))))))

(hello-world)
21 changes: 21 additions & 0 deletions demo/clojurescript.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
(ns hello.world.clojurescript
(:require [reagent.core :as r])

(def counter (r/atom 0))
(def text-component-style {:background-color :grey
:border "1px solid black"
:padding "5px"})

(defn counter-clicked []
(.log js/console "You clicked the counter component.")
(swap! counter inc))

(defn text-counter [text]
[:div {:on-click counter-clicked
:style text-component-style})
(str text @counter])

(defn main-component []
[:div
[:p {:style {:color :red}} "Hello world! Click the element below:"]
[text-counter "Clicked: "]])
Loading

0 comments on commit fca51c7

Please sign in to comment.