Skip to content

Instantly share code, notes, and snippets.

View halfzebra's full-sized avatar

Eduard Kyvenko halfzebra

View GitHub Profile
@halfzebra
halfzebra / UpdateDict.elm
Created May 5, 2016 21:41
Generalized function to handle updates of the Dictionary
import Graphics.Element exposing (show)
import Dict exposing (Dict)
type alias Model = Dict String Int
initModel : Model
initModel =
Dict.fromList
@halfzebra
halfzebra / TestMaybe.elm
Last active April 15, 2016 19:08
Maybe.withDefault crashes every time, because it evaluates both branches first
import Graphics.Element exposing (show)
import Debug
import Maybe exposing (..)
main =
-- Maybe.withDefault crashes every time, because it evaluates both branches first, before passing them to case
-- https://github.com/elm-lang/core/blob/4.0.0/src/Maybe.elm#L51
show (withDefault (Debug.crash "Test") (Just 1))
@halfzebra
halfzebra / Actions.elm
Created April 5, 2016 22:31
Exposing union type in Elm
-- module Actions (Action(NoOp, UpdateModel))
module Actions (Action(..))
where
type Action
= NoOp
| UpdateModel Int
@halfzebra
halfzebra / Ports.js
Created April 4, 2016 15:27 — forked from evancz/Ports.js
Example usage of Elm "ports" that uses signals, non-signals, records, and tuples. Build the Elm code with "elm --only-js Shanghai.elm" and include all of the JS in the HTML document.
// initialize the Shanghai component which keeps track of
// shipping data in and out of the Port of Shanghai.
var shanghai = Elm.worker(Elm.Shanghai, {
coordinates:[0,0],
incomingShip: { name:"", capacity:0 },
outgoingShip: ""
});
function logger(x) { console.log(x) }
{
// http://eslint.org/docs/rules/
"ecmaFeatures": {
"arrowFunctions": false, // enable arrow functions
"binaryLiterals": false, // enable binary literals
"blockBindings": false, // enable let and const (aka block bindings)
"classes": false, // enable classes
"defaultParams": false, // enable default function parameters
"destructuring": false, // enable destructuring
@halfzebra
halfzebra / ripple.css
Created October 15, 2015 07:16
JS Button Ripple Effect
.button {
background: #000000;
color: #ffffff;
line-height: 32px;
font-size: 16px;
max-width: 100px;
width: 100%;
text-align: center;
cursor: pointer;
position: relative;
@halfzebra
halfzebra / SassMeister-input.scss
Last active October 14, 2015 13:33
Generated by SassMeister.com.
// ----
// libsass (v3.2.5)
// ----
li {
@for $i from 1 through 8 {
&:nth-of-type(#{$i}) {
transition-delay: 0.1s * $i;
}
}
@halfzebra
halfzebra / SassMeister-input-HTML.html
Created July 20, 2015 08:13
Generated by SassMeister.com.
<div class="block block-1-1">
<img src="//placehold.it/50x50">
</div>
<div class="block block-1-2">
<img src="//placehold.it/50x50">
</div>
<div class="block block-1-3">
<img src="//placehold.it/50x50">
</div>
<div class="block block-2-1">
@halfzebra
halfzebra / SassMeister-input.scss
Created July 17, 2015 18:04
Generated by SassMeister.com.
// ----
// libsass (v3.2.5)
// ----
@for $i from 1 through 6 {
&.front:nth-child(#{$i}), &.back:nth-child(#{$i}) {
$brick-bg: '../image/brick' + random(6) + '.jpg';
background-image: url($brick-bg);
background-size: 100% 100%;
}
@halfzebra
halfzebra / gist:3f836902997aa0493fd1
Created July 16, 2015 10:29
An example of incapsulation with constructors in JavaScript
(function () {
'use strict';
function hasOwnProperty(obj, prop) {
var proto = obj.__proto__ || obj.constructor.prototype;
return (prop in obj) && (!(prop in proto) || proto[prop] !== obj[prop]);
}
var Button = function (settings) {