CSS For Fast Scroll – No Lags!

Pure CSS (no JavaScript!) tricks to allow you a faster, more reactive page.

Lags while scrolling native pages
are caused by an overly complex styles (usually “zero css” or “normalize css”)
overriding the proper definitions.

Continue reading

Solved: CMD – Comma And Apostrophe In File Name

working with com.whatsapp_2.17.35' 8-452027_minAPI15(armeabi,armeabi-v7a,mips,x86)(nodpi)_apkmirror.com.apk,
the %1, %~1 tries to parse a list of arguments
and will give you: com.whatsapp_2.17.35' 8-452027_minAPI15(armeabi.

%~s1 will fail too.

A workaround:
gulp the entire thing,
and re-parse content into short-path for easier usage.

@echo off
::                              enable Unicode support for path/file-name.
chcp 65001 2>nul >nul

::                              single arg - workaround weird file-name.
set "ARG=%*"
for /f %%a in ("%ARG%") do ( set 'ARG=%%~fsa' )

pure CMD:
the code above will generate a fully-qualified,
short (8.3-DOS like) path.

if you do need to pass more than one argument,
this is not the solution for you.

– – – – – –

The above code does not always works
since it will turn off any tries to parse single argument from the string,

Passing %* to other programs as an argument will always work,
but built-in handling of file-names, with apostrophes will still fail,
due to “by design” issues in CMD (wrapping phrases uses apostrophes..)

instead, try passing %* to GetShortPathName.exe from github.com/eladkarako/GetShortPathName,
with the additional processing allowing empty-strings/empty-character (\0) and Windows API.
it will return a short 8.3 version of the path (relative or full),
if you want a fully qualified path try using GetFullPathName.exe from github.com/eladkarako/GetFullPathName.

You can use your choice of implementations, that simple one is written in VB6.

JavaScript Snippet – A Human-Readable Memory-Formatter, Add Commas To A Number By Regular-Expression

function human_readable_bytes_size(bytes, decimals, sap) {
  decimals = "number" === typeof decimals ? decimals : 2;
  sap = "string" === typeof sap ? sap : "";

  var 
    size = ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
  , factor = Math.floor(  (String(bytes).length - 1) / 3  )
  ;
  
  bytes = bytes / Math.pow(1024, factor);  //calc
  bytes = Math.floor(bytes * Math.pow(10, decimals)) / Math.pow(10, decimals);  //round digits
  
   
  return String(bytes) + sap + size[factor];
}



human_readable_bytes_size(29)
//"29B"
human_readable_bytes_size(29000000000000000)
//"25.75PB"
human_readable_bytes_size(2900000000000)
//"2.63TB"
human_readable_bytes_size(290000000000)
//"270.08GB"
human_readable_bytes_size(290000000000,5)
//"270.08354GB"
human_readable_bytes_size(290000000000,5,"---")
//"270.08354---GB"

also available on GitHub: https://github.com/eladkarako/javascript_human_readable_bytes_size

Would you like the PHP version? – http://icompile.eladkarako.com/php-snippet-a-human-readable-memory-formatter-add-commas-to-a-number-by-regular-expression/


This is a variation with comma-separation (only for the integer part since the fraction part looks weird w/ commas..)

function human_readable_bytes_size(bytes, digits, sap, is_comma_sap) {  "use strict";
  digits       = "number"  === typeof digits        ? digits         :  2;
  sap          = "string"  === typeof sap           ? sap            : "";
  is_comma_sap = "boolean" === typeof is_comma_sap  ? is_comma_sap   : false;

  var  size = ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
     , factor = Math.floor(  (String(bytes).length - 1) / 3  )
     ;

  bytes = bytes / Math.pow(1024, factor);  //calc
  bytes = Math.floor(bytes * Math.pow(10, digits)) / Math.pow(10, digits);  //round digits
  
  if(true === is_comma_sap){
    bytes = String(bytes).split(".");
    bytes[0] = bytes[0].replace(/(\d)(?=(\d{3})+$)/g, "$1,");
    bytes = bytes.join(".");
  }

  return String(bytes) + sap + size[factor];
}

since it is very rare (actually improbable) to use the comma-feature when measuring to the largest scale available,
– In my project https://github.com/eladkarako/any2base64 I’m using a slightly different variation that actually ‘reduce a scale by one’ meaning, instead of using 1GB it will use 1024MB (or 1000-MiB..
* [1] [2])

It works nicely, and sometimes helps to comprehend byte sizes more clearly… Ahhh.. human perspective! ;] ;]


Update:

Here is another variation:
1. it breaks with an error, which is useful for simpler to use within try/catch
without need to pre-check the input is valid.
2. it allows a full/long description.

function human_readable_bytes_size(bytes, decimals, sap, is_desc_short) {
  bytes          = Number(bytes);                                              //normalize input.
  decimals       = "number"  === typeof decimals      ? decimals      : 2;     //
  sap            = "string"  === typeof sap           ? sap           : "";    //
  is_desc_short  = "boolean" === typeof is_desc_short ? is_desc_short : true;  //

  if(true === /NaN/i.test(String(bytes)))                         //handle invalid input.
    throw new Error("\"bytes\" Input-Argument Is NOT A Number.");

  var factor     = Math.floor(  (String(bytes).length - 1) / 3  )
     ,desc_short = ['B',     'kB',        'MB',        'GB',        'TB',        'PB',        'EB',       'ZB',         'YB']
     ,desc_long  = ['Bytes', 'KiloBytes', 'MegaBytes', 'GigaBytes', 'TeraBytes', 'PetaBytes', 'ExaBytes', 'ZettaBytes', 'YottaBytes']
     ;

  bytes = bytes / Math.pow(1024, factor);  //calc
  bytes = Math.floor(bytes * Math.pow(10, decimals)) / Math.pow(10, decimals);  //round digits

  return  String(bytes)
        + sap
        + (true === is_desc_short ? desc_short[factor] : desc_long[factor])
        ;
}

and using it with:

console.log(
  human_readable_bytes_size(10000000000000,3," ",false)
);

//will give you "9.095 TeraBytes"

and

human_readable_bytes_size("a10000000000000",3," ",false)

//will give you something like...
//Uncaught Error: "bytes" Input-Argument Is NOT A Number.

Negative Regular-Expression

I’ve got a text-file, and I want to delete all
of the lines which do not contain the sub-string “switch“.

Some regex-engines will allow the search-replace ^.*((?!switch)).*$,
with empty string.
Most of “gnu-based” engines like grep and sed will support that.

For those who won’t,
you can mimic it with a positive, two-steps replacement,
it will require match-memory/backtrack/back-trace support
($1 or \1 is commonly used to remember the first match).
V8/JavaScript and Scintilla-based editor will support that.

I’m using my modded-version of Notepad2, which supports a such search-replace.

first replacement is to “mark a good line”:
replace ^(.*switch.*)$ with #\1 (adds a # characters at line-start).

second replacement will remove bad-lines with (simple) single-character-NOT rule:
replace ^[^#].*$ with an empty-string (removes lines that do not start with #).

(and you may probably want to restore the original-line by removing the # prefix using last search-replace: replace ^# to empty-string)

Continue reading

CSS For Speed

include those to override some of the browser’s default definitions,
it should be placed in the few first CSS file to load, but after the “reset CSS” (if you use any),
and before any of the websites’ main style.

Continue reading

CrossDomain.xml And ClientAccessPolicy.xml – Extremely Permissive

CrossDomain.xml

<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "http://www.adobe.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
  <site-control permitted-cross-domain-policies="all"/>
  <allow-access-from domain="*" to-ports="*" secure="false"/>
  <allow-http-request-headers-from domain="*" headers="*" secure="false"/>
</cross-domain-policy>

ClientAccessPolicy.xml

<?xml version="1.0" encoding="utf-8"?>
<access-policy>
  <cross-domain-access>
    <policy>
      <allow-from http-request-headers="*">
        <domain uri="*"/>
      </allow-from>
      <grant-to>
        <resource path="/" include-subpaths="true"/>
      </grant-to>
    </policy>
  </cross-domain-access>
</access-policy>

Some notes:
– Now days only Flash, Flex and Silverlight have any use for it.
encoding="utf-8", encoding="utf8", encoding="ISO-8859-1" or encoding="US-ASCII" doesn’t really matter. You should probabbly only use ASCII encoded files (4-bit).
– Serve your file with media-type (mimetype) HTTP header of Content-Type: text/x-cross-domain-policy,
(but text/plain, text/xml, application/xml or application/xhtml+xml would probably work too…)
– If you want to place those XML files anywhere- not only the root of the domain, but sub-domain or any path/sub-directory, you should make-sure your server sends X-Permitted-Cross-Domain-Policies HTTP header, with the value all, you only need to send it with the index and the xml files,
but you can send it with all of the resources using Header set X-Permitted-Cross-Domain-Policies "all" (APACHE/.htaccess) which may be more easy.

Alternative policy file-schemas
Generic DTD – http://www.adobe.com/xml/dtds/cross-domain-policy.dtd
Generic XSD – http://www.adobe.com/xml/schemas/PolicyFile.xsd
HTTP XSD – http://www.adobe.com/xml/schemas/PolicyFileHttp.xsd
HTTPS XSD – http://www.adobe.com/xml/schemas/PolicyFileHttps.xsd
FTP XSD – http://www.adobe.com/xml/schemas/PolicyFileFtp.xsd
Socket XSD – http://www.adobe.com/xml/schemas/PolicyFileSocket.xsd


For best results you can add your server some permissive HTTP CORS headers for a more modern, HTML5 permissive resource access.

CORS

Here are extremely permissive set of CORS HTTP headers,
in a .htaccess/APACHE compatible format.

If you’re using an old GoDaddy.com hosting you’ll need that first:

Header unset   Access-Control-Allow-Methods
Header unset   Access-Control-Allow-Origin
Header unset   Access-Control-Allow-Headers
Header unset   Access-Control-Expose-Headers
Header unset   Access-Control-Allow-Credentials
Header unset   Timing-Allow-Origin
Header unset   X-Permitted-Cross-Domain-Policies

This is what you’re looking for:

Header   set   Access-Control-Allow-Methods        "CONNECT,DELETE,GET,HEAD,OPTIONS,PATCH,PING,POST,PUT,TRACE"
Header   set   Access-Control-Allow-Origin         "*"
Header   set   Access-Control-Allow-Headers        "Accept,Accept-Charset,Accept-Encoding,Accept-Language,Access-Control-Allow-Credentials,Access-Control-Allow-Headers,Access-Control-Allow-Methods,Access-Control-Allow-Origin,Access-Control-Expose-Headers,Access-Control-Max-Age,Access-Control-Request-Headers,Access-Control-Request-Method,Alt-Svc,Cache-Control,Connection,Content-Description,Content-Encoding,Content-Language,Content-Length,Content-Security-Policy,Content-Transfer-Encoding,Content-Type,Cookie,Date,DNT,Downlink,DPR,Expires,Host,If-Modified-Since,Keep-Alive,Last-Event-ID,Last-Modified,Origin,P3P,Pragma,Referer,Referrer-Policy,Remote-Address,Save-Data,Server,Set-Cookie,Strict-Transport-Security,Timing-Allow-Origin,Transfer-Encoding,Upgrade-Insecure-Requests,User-Agent,Vary,Viewport-Width,Width,X-Backend-Server,X-Cache-Info,X-Content-Type-Options,X-CustomHeader,X-Forwarded-For,X-Forwarded-Host,X-Forwarded-Port,X-Forwarded-Proto,X-Forwarded-Server,X-Frame-Options,X-HTTP-Method-Override,X-Kuma-Revision,X-Modified,X-OTHER,X-Permitted-Cross-Domain-Policies,X-PING,X-PINGOTHER,X-Powered-By,X-Real-IP,X-Requested-With,X-XSS-Protection"
Header   set   Access-Control-Expose-Headers       "Accept,Accept-Charset,Accept-Encoding,Accept-Language,Access-Control-Allow-Credentials,Access-Control-Allow-Headers,Access-Control-Allow-Methods,Access-Control-Allow-Origin,Access-Control-Expose-Headers,Access-Control-Max-Age,Access-Control-Request-Headers,Access-Control-Request-Method,Alt-Svc,Cache-Control,Connection,Content-Description,Content-Encoding,Content-Language,Content-Length,Content-Security-Policy,Content-Transfer-Encoding,Content-Type,Cookie,Date,DNT,Downlink,DPR,Expires,Host,If-Modified-Since,Keep-Alive,Last-Event-ID,Last-Modified,Origin,P3P,Pragma,Referer,Referrer-Policy,Remote-Address,Save-Data,Server,Set-Cookie,Strict-Transport-Security,Timing-Allow-Origin,Transfer-Encoding,Upgrade-Insecure-Requests,User-Agent,Vary,Viewport-Width,Width,X-Backend-Server,X-Cache-Info,X-Content-Type-Options,X-CustomHeader,X-Forwarded-For,X-Forwarded-Host,X-Forwarded-Port,X-Forwarded-Proto,X-Forwarded-Server,X-Frame-Options,X-HTTP-Method-Override,X-Kuma-Revision,X-Modified,X-OTHER,X-Permitted-Cross-Domain-Policies,X-PING,X-PINGOTHER,X-Powered-By,X-Real-IP,X-Requested-With,X-XSS-Protection"
Header   set   Access-Control-Allow-Credentials    "true"
Header   set   Timing-Allow-Origin                 "*"
Header   set   X-Permitted-Cross-Domain-Policies   "all"

Note that both Access-Control-Allow-Headers and Access-Control-Expose-Headers lack the options of having * as a value, to this reason their value is quite a long string of the most common used HTTP header-names (collected by me…).
Some hosting/servers might have issues with such a long header-value,
you can try to split the value in half, using two headers
in some cases you’ll need to shorten things up,
in case the length of the HTTP header-value is too long for your server.

You could try splitting the value into two calls using add:

Header   add   Access-Control-Allow-Headers        "Accept,Accept-Charset,Accept-Encoding,Accept-Language,Access-Control-Allow-Credentials,Access-Control-Allow-Headers,Access-Control-Allow-Methods,Access-Control-Allow-Origin,Access-Control-Expose-Headers,Access-Control-Max-Age,Access-Control-Request-Headers,Access-Control-Request-Method,Alt-Svc,Cache-Control,Connection,Content-Description,Content-Encoding,Content-Language,Content-Length,Content-Security-Policy,Content-Transfer-Encoding,Content-Type,Cookie,Date,DNT,Downlink,DPR,Expires,Host,If-Modified-Since"
Header   add   Access-Control-Allow-Headers        "Keep-Alive,Last-Event-ID,Last-Modified,Origin,P3P,Pragma,Referer,Referrer-Policy,Remote-Address,Save-Data,Server,Set-Cookie,Strict-Transport-Security,Timing-Allow-Origin,Transfer-Encoding,Upgrade-Insecure-Requests,User-Agent,Vary,Viewport-Width,Width,X-Backend-Server,X-Cache-Info,X-Content-Type-Options,X-CustomHeader,X-Forwarded-For,X-Forwarded-Host,X-Forwarded-Port,X-Forwarded-Proto,X-Forwarded-Server,X-Frame-Options,X-HTTP-Method-Override,X-Kuma-Revision,X-Modified,X-OTHER,X-Permitted-Cross-Domain-Policies,X-PING,X-PINGOTHER,X-Powered-By,X-Real-IP,X-Requested-With,X-XSS-Protection"

Header   add   Access-Control-Expose-Headers       "Accept,Accept-Charset,Accept-Encoding,Accept-Language,Access-Control-Allow-Credentials,Access-Control-Allow-Headers,Access-Control-Allow-Methods,Access-Control-Allow-Origin,Access-Control-Expose-Headers,Access-Control-Max-Age,Access-Control-Request-Headers,Access-Control-Request-Method,Alt-Svc,Cache-Control,Connection,Content-Description,Content-Encoding,Content-Language,Content-Length,Content-Security-Policy,Content-Transfer-Encoding,Content-Type,Cookie,Date,DNT,Downlink,DPR,Expires,Host,If-Modified-Since"
Header   add   Access-Control-Expose-Headers       "Keep-Alive,Last-Event-ID,Last-Modified,Origin,P3P,Pragma,Referer,Referrer-Policy,Remote-Address,Save-Data,Server,Set-Cookie,Strict-Transport-Security,Timing-Allow-Origin,Transfer-Encoding,Upgrade-Insecure-Requests,User-Agent,Vary,Viewport-Width,Width,X-Backend-Server,X-Cache-Info,X-Content-Type-Options,X-CustomHeader,X-Forwarded-For,X-Forwarded-Host,X-Forwarded-Port,X-Forwarded-Proto,X-Forwarded-Server,X-Frame-Options,X-HTTP-Method-Override,X-Kuma-Revision,X-Modified,X-OTHER,X-Permitted-Cross-Domain-Policies,X-PING,X-PINGOTHER,X-Powered-By,X-Real-IP,X-Requested-With,X-XSS-Protection"

And you can also simply remove some…


In additional to the permissive CORS HTTP Headers,
which will suite HTML5 and newer web-programming-
– you can add permissive CrossDomain.xml and ClientAccessPolicy.xml,
which will add support for Adobe (Macromedia) Flash, Flex and .NET’s Silverlight to your website.

And thanks to using X-Permitted-Cross-Domain-Policies set to all you will be able to place those two xml file in any sub-path you’ll like (normally they are limited root/sub-domain’s root).

Segoe-UI For The Web From Skype

Install Skype,
once done look for Skype.msi around your PC. Either %TEMP% or %ProgramData%\Skype\{ ...a long string of characters... } would be most likely to have it, download 7-Zip and open Skype.msi,
look for Product.cab (open it) and login.cab (open it too),
select all of the content, drag&drop it to your desktop.

Sometimes you’ll find the login.cab‘s content has already extracted to %UserProfile%\AppData\Local\Skype\Apps\login\ or %LocalAppData%\Skype\Apps\login\, it is usually happens after you first login to your account, as a cache (but the MSI-extraction method above is better..)

The fonts and css folders is what your want, you can use it for testing and private stuff on your PC. For the web you should probably buy a server-licence from M$…

Here are some screenshots:


Edit:This trick will work for old installation of Skype,
version 74.85.102 from April 2015 will do just fine,
you’ll probably won’t be able to extract the login.cab,
or have a login folder in newer versions.
Try using FileHippo.

also available here: gist.github.com/eladkarako/93b8ca176eb150bd7408f107e9f2d59e.

Android Custom Ringtone

Samsung/HTC/LG all have a configuration entry for setting a custom ringtone,
heck! you can even select a MP3 file out of your External-SDCard!

For ROMs such as AOSP or LineageOS, you will have to walk through some extra steps in-order to add some custom sounds.

Continue reading

Java And UTF-8

When running a java application,
make sure to use -Dfile.encoding=UTF8,
for an 8-bit Unicode-support.

Interaction with standard input/output
requires setting the output’s code-page too.

For Windows run: chcp 65001 before you execute java.

For Unix/Linux: export LC_ALL="en_US.UTF-8".


Here is an example of a Windows batch-file named apktool.cmd,
that wraps around a jar-program named apktool.jar:

@echo off
chcp 65001 2>nul >nul
call java.exe "-d64 -Xverify:none -Duser.language=en -Dfile.encoding=UTF8" -jar "%~dp0\apktool.jar" %*

and here is why it is important to specify the output’s encoding: github.com/iBotPeaches/Apktool/issues/1595


Reader classes are now covered, for Writer classes make sure to explicit use UTF-8.
prefer using OutputStreamWriter (instead of FileWriter which does not support explicit charset):

BufferedWriter out = new BufferedWriter(
                       new OutputStreamWriter(
                         new FileOutputStream(path)
                        ,"UTF-8"
                       )
                     );

Some swear by explicit providing and additional reader/writer set,
so here is that too:

 OutputStreamWriter char_output = new OutputStreamWriter(
     new FileOutputStream("some_output.utf8"),
     Charset.forName("UTF-8").newEncoder() 
 );

 InputStreamReader char_input = new InputStreamReader(
     new FileInputStream("some_input.utf8"),
     Charset.forName("UTF-8").newDecoder() 
 );

which can be specified to handle input-error, which is sometime useful..

CharsetEncoder encoder = Charset.forName("UTF-8").newEncoder();
encoder.onMalformedInput(CodingErrorAction.REPORT);
encoder.onUnmappableCharacter(CodingErrorAction.REPORT);
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("jedis.txt"),encoder));

Everything here is considered quite-safe to use,
since 8-bit Unicode (UTF-8) will still allow a fallback to displaying
characters out-of US-ASCII (for example) without the need for adding an
extra BOM bits, unlike UTF-16…

Enjoy!

Modification For default.prop (“from boot”) / build.prop (“from system”)

Done for cm_golden-userdebug 7.1.2 NJH47F db0312e049 release-keys/RR-N-v5.8.4-20170821-golden/rr7.1_golden.nova.20170822.zipNougat 7.1.2 (Resurrection Remix) 20170822, for Samsung Galaxy S3-Mini NFC (I8190N).
The base of the partition-structure is from I8190NXXAMI1_I8190NILOAMJ2_HOME.

It will disable the Security-Enhanced Linux (SELinux)🔗︎ and newly Android 7.0 added dalvik's ART Just-In-Time (JIT)🔗︎, the SELinux will be set to permissive settings, just in-case it will be enabled in the future. The modification will allow mtp and adb access from boot and recovery, so you could access your phone at that stage too, it will resolve some WiFi and cast problems and will allow ADB access without annoying popups (default allowed), knox is disabled too but it won’t do much on the custom ROM (unless you’ll be manually download KNOX to access Samsung-pay, which in this case it could be useful to keep it anyway).

Continue reading

WTF Is “Bulk Texture File Conversion” Shell-Menu-Item

The Convert to file format... context-menu item
and Bulk Texture File Conversion dialog,
are a shell-contextmenu item, added after registering TxView.dll which is a part of DirectX SDK package.

You’ll have the menu-item when you’ll right-click on the a Directory, jpegfile, Paint.Picture, pfmfile, pngfile and TxView.1 file-types classes,

Continue reading