I checked the javacript source and besides SUM, the other functions are:

  • CAT
    • Just says MEOW
  • DOG
    • Just says WOOF
  • ABS
  • =ANY_FUNCTION_YOU_MAKE_UP_IN_THIS_FORMAT()
    • Just spits out random junk
  • REVERSE
    • Actually breaks the spreadsheet functions lol

Also SUM has this conditional that I’m too lazy to figure out how to pass:

if (1 === t.length && 41 == t[0]) return ‘STORMING THROUGH THE PARTY LIKE MY NAME WAS EL NIÑO’;

2

Islands

Entry to the JS1k 2015 coding competition by Philippe Deschaseaux procedurally generates island landscapes using an incredibly small amount of javascript. Running in your browser, the code for it to run looks like this:

for(_=’*(H1,G[p-GxF2,E],Dw/EC0,BCB0DFACy+A-@Math.  abs(S+w> sin(.01H3onkey++q[DL[I]=8|3&t+S||8Hh),c.fillRect(“+o+”,M[2]=1Style=”&&(20 cos( .push(a.widthfunction(),=T[P] random()=tD==a.whickBO5BQ=[eGR=b=N=P=BBB0DX=/EY=a.height/1.5,T=[DsetInterval(){for(m= Rn=Ri=m*k,j=n*k,K=(5- 4*R))/4,l=O/E!bN<0TB(r=8*)* t=44*r*t[4,.1D0(S=!bN%0*T[P])?(P,U,V,M,J):e=#888”o=BY-l,2*X,Y+l)L=[QDI;q=eL[—I];)t=Bpxyshw«p,0==N2==ph>10<.2T240>h?8:3Bx+Gy+G[[G4,55D[4,G100D[8BE90]][0|h/1+(18>DhSf=u=x-U)v=y-Vpf!8]qBBBF+@@Cy-A+Cy-CB0](d= sqrt(u*u+v*v))<SW=(J||+(1- pow(d/S,M[0]))*S*M[1])>h3]=s=?0|+*u/(d+1)/9:16>W?190:80+0|W/304]=W)d=k-(m*x+n*y8]!f)p>2*b+d/900)?(t=x>i^3Hy>jL[I]=8|3&t132]):h>12!Sg=m*y-n*x)<dh-Eo-so=srgb(“+os=X/dX+s*g-(w*=s*KY+s*O-(h=s*-l,w+w+Gh+);e=b},0down=a){b,O+=33-34HO>R+=9-7,k+=40-38},up=){b=0};’;g=/[- @-H]/.exec(_);)with(_.split(g))_=join(shift());eval(_)

Try it out for yourself here

React: primeiras impressões

Ah React. O que falar de você que conheço há tão pouco e já considero pacas? No começo vi a página principal, olhei como era e falei “náh, nunca será”. Mas, ah, que garoto bobo e pre-conceituoso…

Fui levado pela hype da galera do front-end, verdade. Muita gente tem falado sobre React, o quão React é foda, o quão React é performático, o quão React é produtivo. E tive o meu hello world, um registrador de atividades. Bem simples mas deu para ver como funciona a programação com o React, além do uso de outras ferramentas como o browserify e o reactify, para trazer o require para o client-side e usar módulos NPM.

O maior desafio foi configurar o ambiente - que vou escrever um post ainda, sobre -, usando o gulp para automatizar as tarefas, afinal ficar transformando JSX para JS a mão, toda vez, ia ser um saco e pouco produtivo, e depois que tinha tudo rodando foi que comecei a mergulhar na API e no mindset do React!

Ainda não me aprofundei, apenas raspei a superfície. Foi muito fácil escrever os primeiros componentes e, ao alterar os estados, ver a DOM se atualizar sozinha. Gostei do processo e, quando pegar o jeito, tenho certeza que será produtivo. O fato de criar componentes pode torná-los reaproveitáveis dentro do projeto e com outros. Não tive testes de performance, afinal não desenvolvi nada que precisasse de  processamento absurdo.

O que senti é que vale a pena testar e ver o que tu acha. Quero aprofundar mais e escrever outros componentes e entender como o React funciona. Muito me interessou e achei foda usar de muitos conceitos de linguagens funcionais! Ah, React, o que falar de você que conheço há tão pouco e já considero pacas?

Throttle In JavaScript

For event handlers of events that can be triggered many times per second, it is often best to limit the main parts of their functions to be only called a fixed number of times per second. For example, for updating a value corresponding to the amount of a long text box scrolled through, updating it about every 200ms would be good enough. I have used a simulate scroll event as I want to keep this example runnable client or server side:

var proccessScroll = function(percent) {
    console.log('Scrolled:', percent);
};

var throttled = throttle(proccessScroll, 200);

// simulateScrollDown(proccessScroll);
simulateScrollDown(throttled);
// Scrolled: 0 then >200ms later: 
// Scrolled: 10 and so on

Keep in mind the objective of this simple throttle is to ensure a function is called at most every n milliseconds. It may not be exact, so the function could be triggered at 200ms then at 402s, but never 200ms then at 399ms . JavaScript timers across environments vary in how often they can be triggered, so there may be some discrepencies. The throttle function simply prevents the function from running again until the delay has been met:

var throttle = function(callback, delay) {
    return function parent() {
        var args = arguments;

        if (!parent.calling){
            parent.calling = true;
            callback.apply(this, args);

            setTimeout(function() {
                parent.calling = false;
            }, delay);
        }
    };
};

And the simulateScrollDown just triggers the passed in callback every 20ms 100 times:

var simulateScrollDown = function(callback) {
    (function loopedCall(i) {
        if (i > 100) return;

        setTimeout(function() {
            callback(i);
            loopedCall(i + 1);
        }, 20);
    })(0);
};

This post is already long, so I will not go into cancelling throttled events or more configuration. But there are libraries that provide more options, for example.

Github Location: https://github.com/Jacob-Friesen/obscurejs/blob/master/2015/throttle.js

hey roleplayers and developers!

I want to build a web-based messenger service, built specifically to make text-based roleplaying (stuff like this) as streamlined as possible!

Ideally it will be:

  • easy to deploy
  • easy to use
  • open source
  • responsive

nice features might include: (but let’s discuss them!)

  • color highlighting and/or pictures for different character
  • tiny URL’s for each RP, just link your friends to it and get going
  • minimizing OOC text out to the side
  • no registration required, possibly?

if anyone is interested, please talk to me!

Javascript.

Par Les joies du code

Sometimes when I’m writing Javascript I want to throw up my hands and say “this is bullshit!” but I can never remember what “this” refers to

— Ben Halpern (@bhalp1)

20 Mars 2015

Who decided indenting with spaces was a good idea?

I have had various discussions over the years with developers about coding standards and consistency. At the start of a new project a team will/should sit down and hash out a common coding style guideline to follow. I’ve always believed that the consistency of the codebase is more important than my own personal coding preferences, so I never complained much when a decision doesn’t go the way I’d like. 

One decision that I’ve seen many times and have never understood is the use of spaces instead of tabs to indent code. To me it seems that this is something that people have just gotten used to seeing and have very few actual reasons for preferring it. Similar to how many people pronounce words incorrectly and resist correction because the correct way “sounds weird.” So instead of making the same mistake, I’ve decided to list the reasons for using tabs instead of spaces for indentation of code.

  1. tabs are a single character that represents indentation, this makes it the “correct” choice for indentation of code.
  2. when code is indented with tabs, the indentation amount (2 spaces, 4, 8) becomes a developer preference that can be set in the developer’s IDE.
  3. tabs actually use less space on disk as only one character is stored instead of 2, 4 or 8.
  4. indentation mistakes are harder to make and easier to see (like 3 spaces instead of 4)
  5. spaces look funny (OK, that one was a joke)

It seems to me that indenting with spaces is akin to making a new paragraph in html via 2 <br> tabs. Yes it achieves the same visual result, but the <p> tag has a purpose, why would you NOT use it?

Discuss on Hacker News