juan_gandhi: (VP)
Good stuff
https://github.com/lukehoban/es6features

var odds = evens.map(v => v + 1)

GET`http://foo.org/bar?a=${a}&b=${b}
    Content-Type: application/json
    X-Credentials: ${credentials}
    { "foo": ${foo},
      "bar": ${bar}}`(myOnReadyStateChangeHandler)

var [a, , b] = [1,2,3]

function f(x, y=12) { return x + y }
f(3) == 15

function f(x, ...y) { return x * y.length }
f(3, "hello", true) == 6

const x = "dont change me"

var arr = []
for (var i = 10; l--;) {
  let j = i
  result[i] = function() { return j }
}

arr[5]() === 5
arr[6]() === 6

var cat = 'Pavlova'
var dog = 'Charlie'
var pets = {cat, dog}

var s = new Set()
s.add("hello").add("goodbye").add("hello")
s.size === 2
s.has("hello") === true

var squares = [ x*x for (x of [1,2,3,4,5]) if (x % 2 == 1) ]

"abc".repeat(3).contains("cabca")

// tail call
function factorial(n, acc = 1) {
    'use strict';
    if (n <= 1) return acc;
    return factorial(n - 1, n * acc);
}
factorial(100000)

this one says "too much recursion
juan_gandhi: (VP)
Extracting PDF from Mozilla Browser - and Doing it Nicely

That's a detailed account of the thing I already posted a couple of days ago. And what I'm enjoying here is Functional Programming. I don't know why Stroustrup does not know that it works. Worked for me. :p
juan_gandhi: (VP)
	function changeLanguageOrder(){
		if(null!=document.documentElement.lang && null!=document.getElementById('selectedLanguage')){
			if(document.documentElement.lang=="es"){
				document.getElementById('selectedLanguage').options[1].selected=true;
			}
			else if(document.documentElement.lang=="ht"){
				document.getElementById('selectedLanguage').options[2].selected=true;
			}
			else if(document.documentElement.lang=="il"){
				document.getElementById('selectedLanguage').options[3].selected=true;
			}
			else if(document.documentElement.lang=="ko"){
				document.getElementById('selectedLanguage').options[4].selected=true;
			}
			else if(document.documentElement.lang=="tl"){
				document.getElementById('selectedLanguage').options[5].selected=true;
			}
			else if(document.documentElement.lang=="vi"){
				document.getElementById('selectedLanguage').options[6].selected=true;
			}
			else if(document.documentElement.lang=="zh" || document.documentElement.lang=="zt"){
				document.getElementById('selectedLanguage').options[7].selected=true;
			}
			else { 
				document.getElementById('selectedLanguage').options[0].selected=true;
			}
		}


A weird selection of languages, is not it?
juan_gandhi: (VP)
(from [livejournal.com profile] code_wtf)

In JavaScript, calculate the sum of integers in a nested array.

i.toSource().replace(/\[|\]/g, '').split(', ').forEach(function(a){if(a.match(/^\d$/)) s -= -a})

toSource()

Aug. 10th, 2013 09:39 am
juan_gandhi: (VP)
В джаваскрипте есть ценный метод, toSource(); он, правда, только к функциям применяется - но я тут понарисовал для скалы, чтобы вот взял какую-нибудь структуру, и её в лог гонишь в таком формате, что можно потом прямо в юниттест вставлять, удобно ж.


List(List("Claim Number:", "19130723010200", "Date Paid:", "", "Date of Claim:", "07/16/1913", "Total Charges: 1", "1", "£1,350.00", "End Service Date:", "07/16/1913", "Plan Paid: 1", "1", "", "Status:", "IN REVIEW", "You Pay: 1", "1", "", "Member:", "LEOPOLD BLOOM", "", "", "Member ID:", "XXXXXXXXX-01", "", ""))

a prayer

May. 8th, 2013 05:39 pm
juan_gandhi: (VP)
can anybody please please please add val to JavaScript?!!!!!

fun/fuck

Sep. 9th, 2012 11:45 pm
juan_gandhi: (Default)
JavaScript/Scala
Read more... )

new stuff

Aug. 14th, 2012 12:01 pm
juan_gandhi: (Default)
function New(name) { return java.lang.Class.forName(name).newInstance() }

function newList() { return New("java.util.LinkedList") }

scala->js

Aug. 9th, 2012 01:08 pm
juan_gandhi: (Default)
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
function arrayFrom(list) {
  var out = [];
  for (i = 0; i < list.size(); i++) { out[i] = asJS(list.apply(i)) }
  return out;
}

function mapFrom(map) {
  var out = {};

  var i = map.iterator();
  while(i.hasNext()) {
    var e = i.next();
    out[e._1()] = asJS(e._2())
  }
  return out;
}


function isListlike(name) {
  return name.indexOf("List") >= 0 || name.indexOf("Array") >= 0 || name.indexOf("$colon$colon") >= 0
}

function isMapLike(name) {
  return name.indexOf("Map") >= 0
}

function asJS(obj) {
  try {
    var cn = obj.getClass().getSimpleName();
    if (isListlike(cn)) return arrayFrom(obj);
    if (isMapLike(cn))  return mapFrom(obj);
  } catch (x) {}
  return obj;
}


critique?
juan_gandhi: (Default)
Пишу на джавасприпте кусочки, которые через http post бросаю своему серверу, там рино их исполняет, вызывая мои методы на скале, каковые разговаривают с другим сервером и переформатируют варварские данные в простые мапы; что-то тут лишнее, но я пока не понял, что.

Главное, что идея писать эту хрень на моём любименьком джаваскрипте как-то очень медленно вползает в голову.

Только что вот написал функцию на джаваскрипте, которая превращает скальный список в джаваскриптовый массив (ну вы в курсе, в джаваскрипте на самом-то деле массивов нет).

Обожаю этот постмодерновый стиль. Три языка (четыре - там ещё shell). Ещё один - и сгожусь в члены правительства ПМР.
juan_gandhi: (Default)
(just could not sleep had to write it down)
<script language="javascript>
  function reset(f){return {shift:function(g){return g(f)}}}
</script>


idiomatic javascript
(я потом что непонятно объясню)
juan_gandhi: (Default)
here

and you know what? I believe I'm the author, but I'm not 100% sure.

Kind of stupid.

Like that story with Akhmatova's poem.

Profile

juan_gandhi: (Default)
Juan-Carlos Gandhi

August 2025

S M T W T F S
      12
3456789
10 11 12 13141516
171819 20212223
24252627282930
31      

Syndicate

RSS Atom

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Aug. 25th, 2025 02:39 am
Powered by Dreamwidth Studios