El Noguer

Joaquim Perez i Noguer

A Better Query Language than SQL

Filed under: Ciència i tecnologia — Joaquim Perez Noguer at 8:46 am on Dimecres, maig 3, 2017

SQL és un llenguatge declaratiu per manipular dades en una base de dades.

En l’article  A Better Query Language than SQL proposen eliminar algunes absurditats de la sintaxis SQL.

Us heu preguntat mai perquè la sintaxi és  SELECT … FROM … WHERE  quan potser seria més interessant tenir-ho en format  FROM … WHERE … SELECT … ?

FROM table
WHERE predicate
GROUPBY columns
SELECT columns
I per què quan es fan joins cal indicar com s’ha de fer la unió de les taules quan el model de dades ja declara quines són les PrimaryKey i les ForeignKey?
from post
key join user
key join comment
select *
I per què no simplificar la sintaxis de les vistes també ?
from dbo.users
with projection as (
  firstName, lastName, phoneNumber, email
)
select projection.*

Xtend – Java millorat

Filed under: Ciència i tecnologia — Joaquim Perez Noguer at 8:35 am on Dimecres, maig 3, 2017

Eclipse proposa una millora del Java: Xtend

La sintaxi de Java és massa explícita:

  • si ja saps que la majoria de classes i mètodes són públics, perquè per defecte no són públics ?
  • si tens tens una llista de Strings per què cal indicar   for (String nom :  llista)  i no simplement  for (nom: llista)

i així moltes altres absurditats del llenguatge java…

[vimeo]http://www.vimeo.com/31248257[/vimeo]

Antivirus ?

Filed under: Seguretat — Joaquim Perez Noguer at 1:23 pm on Divendres, gener 27, 2017

Com a usuari de Linux des de fa vint anys, l’antivirus no el veig necessari ara per ara. El SO és prou robust i el nombre de virus per a Linux és molt més baix que per a altres SO.

Però alerta, que aquesta opinió de Robert O’Callahan diu que fins i tot pels usuaris de Windows seria millor que no fessin servir antivirus (excepte els que proporcionen Microsoft). I no és perquè en Robert treballi a Microsoft precisament. El motiu no és per temes de rendiment de l’Antivirus, sinó per com fa la funció d’Antivirus. Es queixa per exemple que alguns antivirus interfereixen en les mesures de seguretat dels productes, en aquest cas el Firefox, i els fan més vulnerables que sense antivirus.

En el meu cas, en la meva feina, també puc dir que alguns antivirus interferien  en les mesures de seguretat i anti-phishing que vam desenvolupar en una web segura. I la resposta del fabricant de antivirus va ser de negativa total i supèrbia.

La veritat és que no es pot generalitzar i si fos usuari de Windows ara mateix tampoc seria gaire partidari de treure l’antivirus. Però és una opinió que cal tenir en compte.

Origen: Eyes Above The Waves: Disable Your Antivirus Software (Except Microsoft’s)

three.js – Javascript 3D library

Filed under: General — Joaquim Perez Noguer at 9:43 am on Dijous, gener 19, 2017

Vegeu three.js – Javascript 3D library  un mòdul javascript per a fer impressionants animacions 3D com aquest simulador de cotxes 3D (feu anar els cursors i les tecles W, A, S, D )

Motion .js Graphics For The Web

Filed under: Web — Joaquim Perez Noguer at 9:33 am on Dijous, gener 19, 2017

Vegeu  mojs.io – Motion Graphics For The Web un altre mòdul javascript per a fer animacions en les vostres pàgines web.

 

 

CSS Features queries + Grid layout + Native variables

Filed under: Web — Joaquim Perez Noguer at 8:59 am on Dijous, gener 19, 2017

Origen: 3 New CSS Features to Learn in 2017

Aquest 2017 es pot dir que el CSS per fi ho té tot!

1. Feature Queries

Fins ara es mirava si el navegador era Firefox, IE o Chrome, mòbil i es feia un CSS especialitzat per a cada tipus de navegador. Amb Feature Queries només caldrà un sol CSS, en el qual podrem preguntar al navegador si sap o no sap fer una cosa.

@supports ( display: flexbox ) 
          and 
          ( not ( display: flex ) ) {
  .foo { display: flexbox; }
}

2. Grid Layout + flexible lengths + gutters

Per definir les parts de la pantalla vam utilitzar TABLE, DIV amb float:left i moltes coses més. Però ara per fi tenim una forma decent i fàcil de definir-ho.

.hg__header { grid-area: header; }
.hg__footer { grid-area: footer; }
.hg__main { grid-area: main; }
.hg__left { grid-area: navigation; }
.hg__right { grid-area: ads; }

.hg {
    display: grid;
    grid-template-areas: "header header header"
                         "navigation main ads"
                         "footer footer footer";
    grid-template-columns: 150px 1fr 150px;
    grid-template-rows: 100px 
                        1fr
                        30px;
    min-height: 100vh;
}

@media screen and (max-width: 600px) {
    .hg {
        grid-template-areas: "header"
                             "navigation"
                             "main"
                             "ads"
                             "footer";
        grid-template-columns: 100%;
        grid-template-rows: 100px 
                            50px 
                            1fr
                            50px 
                            30px;
    }
}

3. Native Variables

Què és un llenguatge sense variables ? Doncs això CSS després de tants anys per fi permet definir variables.

:root {
  --theme-colour: cornflowerblue;
}

h1 { color: var(--theme-colour); }  
a { color: var(--theme-colour); }  
strong { color: var(--theme-colour); }  

….

const rootEl = document.documentElement;  
rootEl.style.setProperty('--theme-colour', 'plum');  

String.intern

Filed under: Ciència i tecnologia — Joaquim Perez Noguer at 4:28 pm on Dijous, gener 12, 2017

Java ofereix un sistema intern per optimitzar la memòria utilitzada quan llegeixes grans quantitats de texts i té molts repetits: String.intern, però cal anar amb compte.

Vegeu les recomanacions String.intern in Java 6, 7 and 8 – string pooling  – Java Performance Tuning Guide

  • Stay away from String.intern() method on Java 6 due to a fixed size memory area (PermGen) used for JVM string pool storage.
  • Java 7 and 8 implement the string pool in the heap memory. It means that you are limited by the whole application memory for string pooling in Java 7 and 8.
  • Use -XX:StringTableSize JVM parameter in Java 7 and 8 to set the string pool map size. It is fixed, because it is implemented as a hash map with lists in the buckets. Approximate the number of distinct strings in your application (which you intend to intern) and set the pool size equal to some prime number close to this value multiplied by 2 (to reduce the likelihood of collisions). It will allow String.intern to run in the constant time and requires a rather small memory consumption per interned string (explicitly used Java WeakHashMap will consume 4-5 times more memory for the same task).
  • The default value of -XX:StringTableSize parameter is 1009 in Java 6 and Java 7 until Java7u40. It was increased to 60013 in Java 7u40 (same value is used in Java 8 as well).
  • If you are not sure about the string pool usage, try -XX:+PrintStringTableStatistics JVM argument. It will print you the string pool usage when your program terminates.

 

Anatomia d’un objecte Java

Filed under: Ciència i tecnologia — Joaquim Perez Noguer at 4:21 pm on Dijous, gener 12, 2017

Com guarda el Java els objectes en memòria? T’ho explica  From Java code to Java heap

When your Java code uses the new operator to create an instance of a Java object, much more data is allocated than you might expect.

For example, it might surprise you to know that the size ratio of an int value to an Integer object — the smallest object that can hold an int value — is typically 1:4. The additional overhead is metadata that the JVM uses to describe the Java object, in this case an Integer.

The amount of object metadata varies by JVM version and vendor, but it typically consists of:

Class : A pointer to the class information, which describes the object type. In the case of a java.lang.Integer object, for example, this is a pointer to the java.lang.Integer class.

Flags : A collection of flags that describe the state of the object, including the hash code for the object if it has one, and the shape of the object (that is, whether or not the object is an array).

Lock : The synchronization information for the object — that is, whether the object is currently synchronized.

The object metadata is then followed by the object data itself, consisting of the fields stored in the object instance. In the case of a java.lang.Integer object, this is a single int.So, when you create an instance of a java.lang.Integer object when running a 32-bit JVM, the layout of the object might look like Figure 2:Figure 2. Example layout of a java.lang.Integer object for a 32-bit Java processExample layout of a java.lang.Integer object for a 32-bit Java processAs Figure 2 shows, 128 bits of data are used to store the 32 bits of data in the int value, because the object metadata uses the rest of those 128 bits.

 

Trucs amb el Java

Filed under: Ciència i tecnologia — Joaquim Perez Noguer at 11:13 am on Dimecres, desembre 14, 2016

Mirant  What are some cool Java tricks? – Quora

He trobat algunes curiositats interessants amb el Java:

Double bracing Lists allows you to declare and initialize without Arrays.asList()
List<String> places = new ArrayList<String>() {
{ add(«x»); add(«y»); }
};

Joint-union in generic type params
public class Baz<T extends Foo & Bar> {}

Define, instantiate, and call all at once
new Object() {
void hi(String in) {
System.out.println(in);
}
}.hi(«weird»);

Detect deadlocks
public static class DeadLockDetector extends Thread {
@Override
public void run() {
while(true) {
ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
long[] ids = threadMXBean.findDeadlockedThreads();
if (ids != null) {
System.exit(127);
}
try {
Thread.sleep(1000);
} catch (InterruptedException e) { }
}
}
}

Unsafe… (it’s like Super User mode for Java… dangerous but powerful). Understanding sun.misc.Unsafe
public void testObjectCreation() throws Exception {
ClassWithExpensiveConstructor instance =    (ClassWithExpensiveConstructor)
unsafe.allocateInstance(ClassWithExpensiveConstructor.class);
assertEquals(0, instance.getValue());
}

Però el que el millor sense cap dubte és el que es pot fer amb Reflection:

    import java.lang.reflect.Field;

public class MutableString {

public static void main(String[] args) throws Exception {
String someString = «IMMUTABLE»;
Field field = Class.forName(«java.lang.String»).getDeclaredField(«value»);
field.setAccessible(true);
char[] value = (char []) field.get(someString);
String anotherString = «NOTREALLY»;
for (int i=0; i<value.length; i++){
char c = anotherString.toCharArray()[i];
value[i]=c;
}

System.out.println(someString); // prints NOTREALLY
System.out.println(«IMMUTABLE»); // WTF !!! prints NOTREALLY
}
}

 

 

KaiRo: I Want an Internet of Humans

Filed under: Seguretat — Joaquim Perez Noguer at 5:55 pm on Dilluns, desembre 12, 2016

On the Internet, not so much. We interact with and through a machine, see an «account» on the other end, remove all the context of what was said before and after, of the tone of voice and body language, of what surroundings others are in, we reduce to a few words that are convenient to type or what the communication system limits us to – and we go for whatever gives us the most attention. Because we don’t actually feel like we interact with other real humans, it’s mostly about what we get out of it. A lot of likes, reshares, replies, interactions. It helps that the services we use maximize whatever their KPI are and not optimize for what people actually want – after all, they want to earn money and that means having a lot of activity, and making people happy is not an actual goal, at best a wishful side effect.

We need to change that. We need to make social media actually social again (this talk by Chris Heilmann is really worth watching).We need to spread love («make Trek, not Wars» in a tounge-in-cheek kind of way, no meaning negativity towards any franchise, but thinking about meanings and how we can make things better for our neighbors, our community, our world), not even hate the fear or fear the hate (which leads back into the circle), but analyze it, take it seriously and break it down. If we understand it, know how to deal with it, but not let it overcome us, fear can even be healthy – as another great screenwriter put it «Fear only exists for one purpose: To be conquered». That is where we need to get ourselves, and need to help those other humans end up that spread hate and unreflected fear – or act out of that. Not by hating them back, but by trying to understand and help them.

We need to see the people, the humans, behind what we read on the Internet (I deeply recommend for you to watch this very recent talk by Erika Baker as well). I don’t see it as a «Crusade against Internet hate» as mentioned in the end of that talk, but more as a «Rally for Internet love» (unfortunately, some people would ridicule that wording but I see it as the love of humanity, the love for the human being inside each and everyone of us). I’m always finding it mind-blowing that every single person I see around me, that reads this, that uses some software I helped with, and every single other person on this planet (or in its orbit, there are none out further at this time as far as I know), is a fully, thinking, feeling, caring human being. Every one of those is different, every one of those has their own thoughts and fears that need to be addressed and that we need to address. And every one of those wants to be loved. And they should be. No matter who they voted for. No matter if they are a president elect or a losing candidate. We don’t need to agree with everything they are saying. But their fears should be addressed and conquered. And yes, they should be loved. Their differences should be celebrated and their commonalities embraced at the same time. Yes, that’s possible, think about it. Again, see the philosophy of infinite diversity in infinite combinations.

I want an Internet that connects those humans, brings them closer together, makes them understand each other more, makes them love each other’s humanity. I don’t care how many «things» we connect to the Internet, I care that the needs and feelings of humans and their individual and shared lives improve. I care that their devices and gadgets are their own, help their individuality, and help them embrace other humans (not treat them as accounts and heaps to data to be analyzed and sold stuff to). I want everyone to see that everyone else is (just) human, and spread love to or at least embrace them as humans. Then the world, the humans in it, and myself, can make it out of the difficult times and live long and prosper in the future.

I want an Internet of humans.

Origen: Home of KaiRo: I Want an Internet of Humans

« Previous Page — Next Page »