Skip to content

Instantly share code, notes, and snippets.

View hsribei's full-sized avatar

Helder S Ribeiro hsribei

View GitHub Profile

Someone in the Elm slack channel threw out this idea of naming Msg in the past tense, and not imperatively. I thought it was an interesting idea and I adopted the practice, just to try it out. I forgot who it was, I wish I could give them credit.

Anyway, the ramifications were more than I expected, and not simply the same Msg with different names. What I started doing is naming Msg as if they were saying "This happened". So where I would say "HandleUsernameField" I might instead say "UsernameFieldChanged" or instead of "Close" I would do "XClicked". What I didnt account for was that Msg and functionality dont map one to one. So for example, if you have a Msg named Navigate, its going to be the one Msg you use whenever you want to navigate. But if you are naming Msg as paste-tense descriptions, then several different things could happen that could cause a navigation. Since many things should cause a navigation, naming Msg in the past tense leads to lots of Msg which do the same thing.

@carlosmaniero
carlosmaniero / Elm.hs
Last active October 30, 2017 13:19
Elm architecture in Haskell: A study case
data Model = Model
{ name :: String
, gender :: String
, loading :: Bool
, homeworld :: String
} deriving (Show)
data PersonResponse = PersonResponse
{ personName :: String
@IronSavior
IronSavior / to-function.js
Created August 7, 2017 22:30
JavaScript named predicate helper (Symbol#to_proc from Ruby)
"use strict";
// Make predicate funtions more convenient.
// Works like Ruby's Symbol#to_proc, which is usually called with the unary & operator and a Symbol literal:
// (ruby) %w[one two three].map(&:upcase) # returns ["ONE", "TWO", "THREE"]
// (js) ['one', 'two', 'three'].map(toFn('toUpperCase')); // returns ["ONE", "TWO", "THREE"]
// (js) ['one', 'two', 'three'].map(toFn`toUpperCase`); // same as above, but called via tagged string literal
// @param name {String} Name of method
// @param ...bound_args Arguments to bind NOTE: Args cannot be bound when calling as a tagged-template
// @return {Function} Function to call named method with bound args on any object given at time of invocation
module.exports = function toFn( name, ...bound_args ){
@derhuerst
derhuerst / offline.md
Last active October 3, 2018 20:30
working offline as JavaScript dev

working offline as JavaScript dev

use npm@5

npm installs large dependency trees a lot faster. this is especially noticable over slow networks.

Running npm while offline will no longer insist on retrying network requests. npm will now immediately fall back to cache if possible, or fail. (npm/npm#15666)

use node_modules/*/readme.md

Lightning Talk proposal for ReactiveConf 2017 http://www.reactiveconf.com #ReactiveConf

Porting Prezi to Elm in 99 lines of code

Elm is a statically-typed functional programming language. Its compiler produces safe JavaScript which is guaranteed to be free of runtime exceptions. Moreover Elm is packed with a bunch of powerful abstractions which let us build visual and reactive Web applications in a few lines of code.

As an example, I show the implementation of a simple framework for building Prezi-like presentations. It's just 99 lines of code!

@yoshuawuyts
yoshuawuyts / ssb.rs
Last active May 16, 2017 16:47
Rough rust translation of the https://github.com/ssbc/secure-scuttlebutt example
extern crate ssb_keys;
extern crate ssb;
extern crate mio;
#[macro_use]
extern crate pull;
const pathToSecret: String = "/tmp/ssb1-secret";
const pathToDB: String = "/tmp/ssb1/";
port module Spelling exposing (..)
import Html exposing (..)
import Html.App as App
import Html.Attributes exposing (..)
import Html.Events exposing (..)
import String
main =
@ivar
ivar / spacemacs global search and replace.md
Last active August 1, 2022 00:04
spacemacs - global search and replace

There's a couple of ways, one way is

  • Get search results
    • Do SPC / and type in your search string
    • or SPC x S and search string - where x is your scope indicator (p for project, d for directory, etc..)
  • Once you have the occurences you want, hit C-c C-e inside the helm buffer to put all your match occurences and puts them into a special buffer called the edit buffer or something like that
  • in that buffer you can use any commands you'd normally use on a buffer
  • the C-c C-c to commit your changes.
@yang-wei
yang-wei / destructuring.md
Last active February 20, 2024 04:40
Elm Destructuring (or Pattern Matching) cheatsheet

Should be work with 0.18

Destructuring(or pattern matching) is a way used to extract data from a data structure(tuple, list, record) that mirros the construction. Compare to other languages, Elm support much less destructuring but let's see what it got !

Tuple

myTuple = ("A", "B", "C")
myNestedTuple = ("A", "B", "C", ("X", "Y", "Z"))
try {
function foo() {
foo();
}
foo();
} catch(e) {
window.location.href="http://stackoverflow.com/search?q=[js]+" + e.message || e;
}