profile
viewpoint
Job van der Zwan JobLeonard IxD/supporting programmer at Linnarsson Lab Malmö

started1j01/simple-console

started time in 11 days

PR opened dsalaj/awesome-quirks

Added animated emoji URL article
+1 -0

0 comment

1 changed file

pr created time in a month

push eventJobLeonard/awesome-quirks

Job van der Zwan

commit sha f965fef023a6fae5234a438ee0b3d0b032e0b837

Added animated emoji URL article

view details

push time in a month

startedcarykh/jumpcutter

started time in a month

issue commentpieroxy/lz-string

lz-string for Haxe

Well, since these are constants it could have done further strength reduction to:

    var dictionary_h = { };
    /* ... */
    dictionary_h[0] = "0";
    dictionary_h[1] = "1";
    dictionary_h[2] = "2";

And since the full context of that bit of code is:

    var dictionary_h = { };
    /* ... */
    dictionary_h[0] = "" + 0;
    dictionary_h[1] = "" + 1;
    dictionary_h[2] = "" + 2;

Theoretically it could even have reduced it further to:

    var dictionary_h = { 0: 0, 1: 1, 2: 2 };

The last optimization would probably be a difficult pattern for the average compiler to detect, but the first one seems pretty straightforward.

markknol

comment created time in a month

issue commentpieroxy/lz-string

lz-string for Haxe

Nice, thanks for the explanation! Surprised Haxe doesn't optimize stuff like this away though:

dictionary_h[0] = "" + 0;
dictionary_h[1] = "" + 1;
dictionary_h[2] = "" + 2;

On Fri, Apr 12, 2019, 10:46 Mark Knol notifications@github.com wrote:

It will look like this https://gist.github.com/markknol/1012a7ad76d9cffd363d7c29656e4105

Some notes to understand where you are looking at:

  • Including the test it is 18kb (Minified this will be ~7kb. gzipped thats ~3kb)
  • As comparison, the original lz-string.js in this repo is 16kb
  • Haxe always bundles all code into one file
  • In my version I changed the dictionaries for a typed Map, which work on all targets, but add some standard library code.
  • Haxe has a static analyzer that does dead code elimination, so unused functions are stripped. In my example I only use compressFromBase64 and decompressFromBase64, you won't see the compressFromUint8 function for example.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/pieroxy/lz-string/issues/133#issuecomment-482492429, or mute the thread https://github.com/notifications/unsubscribe-auth/AAP3AG5L3jTxrG3Ul424tl3JZl8OQPbgks5vgEfbgaJpZM4cpcH- .

markknol

comment created time in a month

issue commentpieroxy/lz-string

lz-string for Haxe

Nice! I'm also curious what the JavaScript version of compiled Haxe lookes like

markknol

comment created time in a month

startedFlaque/quirk

started time in a month

startedLisaDziuba/Awesome-Design-Tools

started time in 2 months

startedaardappel/aarded

started time in 2 months

issue commentalshakero/perf.zone

Strange results in Chromium compared to other benchmarking sites

P.S. Dang, Firefox is fast for the switch-based snippets -- 500 million+ operations per second!

That's usually a sign it has compiled constants away, and given that the input is a constant array that seems likely:

var parts = ["some1","some2",3,"some4",5];

If I edit the set-up a bit to randomize the input, the numbers change quite dramatically although the switches are still much, much faster:

https://jsperf.com/join-vs-template-venryx/2

I'm honestly still a bit suspicious of these numbers

JobLeonard

comment created time in 2 months

issue commentpieroxy/lz-string

Use js to compress data, and use another language like python to decompress?

Yes, this is possible. See: http://pieroxy.net/blog/pages/lz-string/index.html#inline_menu_7

As for your particular example, here is a Python 3 version: https://github.com/eduardtomasek/lz-string-python

tianhaoo

comment created time in 2 months

issue commentpieroxy/lz-string

Is there a compression algorithm without ZERO width char ?

Here you go: https://gist.github.com/JobLeonard/7a49b8e5adf17d9a3783ffcfa21eec3f

I also removed the string-characters, so:

`
"
'

So copying/pasting a compressed string won't suddenly lead to strange broken string behavior.

Did a quick test round here: https://observablehq.com/d/d223e05380aa85c9/

finscn

comment created time in 2 months

issue commenttaylorconor/tinytetris

Request: modern Tetris randomization logic

Why two though? Wouldn't the simplest way be to have a sequence of seven and shuffle that sequence every seven steps?

Currently, the logic for a new piece is:

// create a new piece, don't remove old one (it has landed and should stick)
void new_piece() {
  y = py = 0;
  p = rand() % 7;
  r = pr = rand() % 4;
  x = px = rand() % (10 - NUM(r, 16));
}

The key line being p = rand() % 7;

If I'm correct, something like this should work: (just wrote this of the top of my head, haven't really written C++ in a while so probably contains a mistake somewhere)

// index into bag sequence and bag of seven tetronimos
int n = 0, bag[7] = {0, 1, 2, 3, 4, 5, 6}

void new_piece() {
  y = py = 0;
  // Fisher-Yates shuffle the bag every time
  // one random sequence is finished
  if (n == 0) { 
    for(int i = 1; i < 7; i++) {
      int j = rand() % i;
      p = bag[j];
      bag[j] = bag[i];
      bag[i] = p;
    }
  }
  p = bag[n];
  n = (n + 1) % 7;
  r = pr = rand() % 4;
  x = px = rand() % (10 - NUM(r, 16));
}
JobLeonard

comment created time in 2 months

issue openedtaylorconor/tinytetris

Request: modern Tetris randomization logic

Currently any piece can follow any piece. In modern Tetris implementations we instead get pieces in shuffled sequences, where each sequence contains every tetronimo piece exactly once. See also:

https://tetris.fandom.com/wiki/Random_Generator

Would make the game a lot more "fair" to play :)

created time in 2 months

startedtoji/gl-matrix

started time in 2 months

starteddheera/rosshow

started time in 2 months

startedstdlib-js/stdlib

started time in 2 months

issue commentpieroxy/lz-string

File extension?

Well, LZString compresses UTF16 strings to more compact UTF16 strings, so it's not really intended to have its own file format. So none of what I'm about to write is official guidelines, I'm just trying to think along and give some helpful suggestions. Let me know if it works for you.

Given that we don't really need a file format of our own, your question becomes more one about storing plain-text, for which you have a number of options. The most obvious and cross-platform friendly would be a simple .txt file (UTF encoded of course). Alternatively, if you are compressing JSON data, .json arguably also works, since storing a plain string is actually valid JSON!

But that misses the point a bit: I guess you want to know which file extension is appropriate so that intent is stored in the filename, right? And something like mydata.txt or mydata.json does not convey that the data in that text is compressed. But there's a simple way to achieve that: mydata.lzstring.txt or mydata.lzstring.json. The latter can be interpreted as "a JSON file compressed with lzstring".

Then, if you want load the data later you can just test if the filename ends with .lzstring.txt to verify it's a LZString compressed string, or .lzstring.json to verify it's data that you should run through JSON.parse(LZString.decompress(<some DOMString to your file>)) (assuming you are using JavaScript in your browser) to get your data back.

Does this answer your questions, or were you trying to do something else?

Richienb

comment created time in 2 months

issue commentpieroxy/lz-string

How safe is lz-string?

It will most likely return an empty string as it bails out, and in the unlikely worst case give you a garbage string instead. Hypothetically a null can also be returned, if you return try to decompress an empty array.

decompressFromUint8Array just treats pairs of 8-bit values from the Uint8Array as 16-bit UTF16 char codes, converts the array to a string that way, and then calls the regular decompression algorithm after that:

  //decompress from uint8array (UCS-2 big endian format)
  decompressFromUint8Array:function (compressed) {
    if (compressed===null || compressed===undefined){
        return LZString.decompress(compressed);
    } else {
        var buf=new Array(compressed.length/2); // 2 bytes per character
        for (var i=0, TotalLen=buf.length; i<TotalLen; i++) {
          buf[i]=compressed[i*2]*256+compressed[i*2+1];
        }

        var result = [];
        buf.forEach(function (c) {
          result.push(f(c));
        });
        return LZString.decompress(result.join(''));

    }
  decompress: function (compressed) {
    if (compressed == null) return "";
    if (compressed == "") return null;
    return LZString._decompress(compressed.length, 32768, function(index) { return compressed.charCodeAt(index); });
  },

Try it for yourself in your console:

randomString = (() => {let s = ''; for(let i = 0; i < 100; i++) s += String.fromCharCode(Math.random()*0x10000|0); return s})();
LZString.decompress(randomString); // Assumes you loaded LZString

This will almost always return ""

caracal7

comment created time in 2 months

startedgoogle/pik

started time in 2 months

issue openedalshakero/perf.zone

Strange results in Chromium compared to other benchmarking sites

Somehow, the "switch and template string"-based snippets of this benchmark perform a lot worse on perf.zone than on the other benchmarking sites (see screenshots and links below).

I don't know if that means that there is something preventing the code from being properly optimized, or something that creates extra overhead, but it's strange. I tried measuring performance with the DevTools, but the memory/node graphs don't really clarify anything (neither memory allocation nor garbage collection seems to line up with the different sub-benchmarks in any of the tested sites).

https://jsperf.com/join-vs-template-venryx http://jsbench.github.io/#7f03c3d3fdc9ae3a399d0f2d6de3d69f http://jsben.ch/9DaxR https://run.perf.zone/view/Join-vs-Template-Venryx-1512492228976

Chromium

image image image image

JSPerf: image

jsbench.github.io: image

jsben.ch: (WTF?!) image

perf.zone: image

Firefox

This problem is not present in Firefox, but I add the results just for the sake of completion: (And yes, here jsben.ch is the benchmarking site with weird results, but that's not really a problem for perf.zone)

image image image image

created time in 2 months

issue commentpieroxy/lz-string

How safe is lz-string?

You need to be more clear about "safe" and "breaking" here, as well as which version you are using. But TL;DR: no, not that we know of, unless you count breaking due to running out of memory on large objects. That is not exactly something that LZString can be held responsible for though.

For example, the 1.34 version throws every substring into one large dictionary. So if you throw a large enough string at it (I'm talking millions of characters), it will start to stutter simply because JS objects aren't made to hold millions of keys.

The 2.0RC version builds a trie of small objects instead. You risk running out of memory, but each individual node has at most 65k chars (because that is the number of char codes we can get out of UTF16) smaller so shouldn't have this issue.

If you use the 2.0 unsafe version, well, it says unsafe for a reason. It is trivial to build a string that freezes that one (not crash, just freeze), namely one that iterates over all 65k charcodes in sequence.

caracal7

comment created time in 2 months

startedmozilla/mozjpeg

started time in 2 months

starteddanielgtaylor/jpeg-archive

started time in 2 months

startedkornelski/giflossy

started time in 2 months

startedobservablehq/stdlib

started time in 2 months

startedinjinj/smhasher

started time in 2 months

startedcmuratori/meow_hash

started time in 2 months

starteddvkt/vscode-ldpl

started time in 2 months

startedtimvisee/ffsend

started time in 2 months

issue openedmozilla/multi-account-containers

When using "Reopen in containter" from tab, "Firefox Multi-Account Containers" sometimes is missing from the context menu

  • Is "Firefox will: Never remember history" in the Firefox Preferences/Options under "Privacy & Security > History" selected? Yes/No: No
  • Are you using Firefox in a Private Window? Yes/No: No
  • Can you see a grayed out but ticked Checkbox with the description "Enable Container Tabs" in the Firefox Preferences/Options under "Tabs"? Yes/No: Yes
  • Multi-Account Containers Version: 6.1.0
  • Operating System + Version: KDE Neon, GIT Stable
  • Firefox Version: 67.0b1
  • Other installed Add-ons + Version + Enabled/Disabled-Status:
Extension Version
Block Site 0.1.9
Clean Links 3.2.5
Container Tabs Sidebar 0.0.4
Decentraleyes 2.0.10
Desktop Wikipedia 0.1
DjVu.js Viewer 0.2.4.3
Download all Images 0.5.7
DuckDuckGo Hide Unwanted Results 0.7
Extension for Gmail Basic HTML View 2.0
Extension source viewer 1.6.10
File Icon for GitHub, GitLab and Bitbucket 0.8.1
Firefox Color 2.1.2
Firefox Multi-Account Containers 6.1.0
Forget that page 1.6.0
Fx Color (github) 1.0.1
Gecko Profiler 0.29
Google Search Filter 1.0.10
Google search link fix 1.6.7
Happy Right-Click 1.1.0
image-save 1.2
Let's get color blind 1.0.0
Link Cleaner 1.5
Live Reload 1.6.0
Neat URL 4.1.5
New Tab Override 14.2.0
Notes by Firefox 4.3.3
Octotree 2.5.6
Old Reddit Redirect 1.1.2
pinterest-guest 2.1
Plasma Integration 1.4
Reddit Enhancement Suite 5.14.5
Redirect AMP to HTML 2.0.0
Refined GitHub 19.3.10.1842
Render Whitespace on GitHub 1.3.12
Side View 0.4.3710
Stop AutoPlay Next for YouTube™ 0.1.7
Stylus 1.5.2
Theater Mode for YouTube™ (large player view) 0.1.3
Trackerless Magnet URI 1.0.2
Twitter View Original Images 0.1.8.100
uBlock Origin 1.18.4
uMatrix 1.3.16
Universal Bypass 10.6
Unpaywall 3.78
Wayback machine website 1.2.1
Youtube Audio 0.0.2.2
YouTube Classic 1.3

Actual behavior

  • "Firefox Multi-Account Container" is missing from right-click context menu (the one seen by right-clicking on the website itself, not the one you get by clicking on the tab) of the page reopened in a container. This behavior is persistent until said page is refreshed a second time. After doing so, the "Firefox Multi-Account Container" is visible in the context menu, and any other website re-opened through right-clicking the tab will show the extension from the first reload.

Expected behavior

  • "Firefox Multi-Account Container" is immediately visible

Steps to reproduce

  1. open a website
  2. right-click on tab, select "Reopen in Container"
  3. select a container
  4. open new tab
  5. right-click on the document body to open the context menu

Notes

created time in 2 months

startedaalhour/awesome-compilers

started time in 2 months

issue openedneocities/neocities

Allow for editing .appcache files like other plain text files

Not that many people will use them these days, but since we can already edit .txt files, why not extend that functionality to .appcache files?

created time in 2 months

issue commentMicrosoft/TypeScript

Methods labeled as properties when defined by assigning earlier-defined function to prototype

I don't think I quite follow:

There are two equally-valid ways of interpreting this:

  • Methods are callable, properties are not
  • Methods are on the prototype, properties are own

Shouldn't the aProperty in my example should be interpreted as a method no matter which of these two ways we pick, since we are talking about a function assigned to the prototype?

I don't have a principled way to resolve this, but would note that prototype methods are always subject to this context loss, so showing the difference as it is today seems fairly valuable from a safety perspective.

It think you are suggesting that there are all-else-being-equal cases where aMethod would behave differently from aProperty, but I'm not seeing how. Could you elaborate?

mjbvz

comment created time in 2 months

startedgokr/spry

started time in 2 months

startedcitybound/citybound

started time in 2 months

startedV-Sense/DeepNormals

started time in 3 months

startedbootchk/resynthesizer

started time in 3 months

issue commentalessandrofrancesconi/gimp-plugin-bimp

Ubuntu 16.04. Don't work

@rich2005: any special last steps required for installing the compiled-from-source plugin if I use flatpak? Can I just run make and then move the output to the plugin folder?

nemex1975

comment created time in 3 months

startedalessandrofrancesconi/gimp-plugin-bimp

started time in 3 months

startedstillwater-sc/universal

started time in 3 months

PR opened Lartu/narivm

Replace all tab-characters with four spaces

This is why I always have visible white space characters turned on in my editors:

image

+53 -53

0 comment

1 changed file

pr created time in 3 months

push eventJobLeonard/narivm

Job van der Zwan

commit sha dd018c353d8ecd0b5b2ac9f36e1c09b5b2f676f1

Replace all tab-characters with four spaces

view details

push time in 3 months

fork JobLeonard/narivm

Stack-based microlanguage interpreter designed to work as a virtual machine for more complex languages.

fork in 3 months

startedLartu/ldpl

started time in 3 months

startedJiaXianYao/Bilateral-Texture-Filtering

started time in 3 months

startedFreak613/stage0

started time in 3 months

startedsmacke/subsync

started time in 3 months

startedlemire/simdjson

started time in 3 months

more