Skip to content

Latest commit

 

History

History
246 lines (210 loc) · 8.34 KB

index.md

File metadata and controls

246 lines (210 loc) · 8.34 KB

Cheatsheets:

️️️❤️ Angular

❤️ Cloud

GWT

Docker / k8s / Helm / Istio

❤️ PHP

Python

❤️ Qt

Qt .pro/QML (with a chapter for git)

❤️ Security

❤️ Rx

Scrum

Spark

❤️ DevOps

.

🚀 Diverse:

.

How to protect Secret Keys in JavaScript source code?

use jscrambler

  1. use jscrambler, with config entry "propertyKeysObfuscation"
  2. Take care: this hint is not hacker-safe, but often ~good-enough!
  3. cfg prop: "name": "propertyKeysObfuscation"
npm install jscrambler --save-dev 
npm i --save-dev jscrambler-webpack-plugin 

How to convert PSD to HTML/CSS & pics ?

Use Avocode (desktop app, available for macOS, Win, Linux)

  1. Use Avocode (the app is not free) (can also handle Sketch designs with a plugin)
  2. After opening the project, you can edit the CSS styles.
  3. can export images
  4. often, you edit the HTML manually and use the styles & images given by Avocode
  5. app shows padding & margin of elements visually

How to do (mobile) Cross-Browser testing?

Use online service of http://www.browserstack.com (not free!)

  1. Can do:
    1. live: interactive test & debug of websites in real browsers & mobile devices
    2. Automate
    3. Screenshots & Responsive
  2. you can choose from a lot of browser-versions & OSs(Win, macOS, iOS, Android)
  3. Plugin for Chrome: 'Local Testing' for non-public websites, eg. from localhost

How to speed up Apache?

Use mod_pagespeed: it compresses JS & CSS

wget https://dl-ssl-google.com/dl/linux/direct/mod-pagespeed-stable_current_amd64.deb
dpkg -i mod-pagespeed*.deb
sudo service apache2 restart
gedit /etc/apache2/mods-available/pagespeed.conf # -> ModPagespeed on|off
gedit /etc/apache2/mods-enabled/pagespeed.conf   # -> /pagespeed_admin = Admin Area!
sudo service apache2 reload

/etc/apache2/mods-available/pagespeed.conf

<IfModule pagespeed_module>
    ModPagespeed on
    ...

/etc/apache2/mods-enabled/pagespeed.conf

<Location /pagespeed_admin>
    Order allow,deny
    Allow from localhost
    Allow from 127.0.0.1
    Allow from 0.0.0.0
    SetHandler pagespeed_admin
</Location>
<Location /pagespeed_global_admin>
    Order allow,deny
    Allow from localhost
    Allow from 127.0.0.1
    Allow from 0.0.0.0
    SetHandler pagespeed_global_admin
</Location>
    ModPagespeedStatisticsLogging on

🚀 SQL: Find book(s) with the minimum average rating

select avg3.title, avg3.avg_rating
from

(select b.title, avg(r.rating) as avg_rating from ratings r join books b on b.id = r.book_id group by b.title) as avg3

where avg_rating = (select min(avg2.avg_rating2) from (select r2.book_id as id, avg(r2.rating) as avg_rating2 from ratings r2 group by r2.book_id) as avg2);

Analyze Java Stream

(incomplete)

public class OrdersAnalyzer {

  /**
   * Should return at most three most popular products. Most popular product is the product that have the most occurrences
   * in given orders (ignoring product quantity).
   * If two products have the same popularity, then products should be ordered by name
   *
   * @param orders orders stream
   * @return list with up to three most popular products
   */
  public List<Product> findThreeMostPopularProducts(Stream<Order> orders) {
	  
	  List<Product> ps = new ArrayList<Product>();
    
	 Stream<OrderLine> ols = orders.flatMap((order) -> order.getOrderLines().stream());
	 Map<Product, Integer> acc = new HashMap();
	 ols.forEach(ol -> acc.merge(ol.getProduct(), ol.getQuantity(), Math::addExact));
	 acc.entrySet().stream().sorted(Map.Entry.comparingByValue()).limit(3).forEachOrdered(p -> ps.add(p.getKey()));
	 
	 return ps;
  }

  /**
   * Should return the most valuable customer, that is the customer that has the highest value of all placed orders.
   * If two customers have the same orders value, then any of them should be returned.
   *
   * @param orders orders stream
   * @return Optional of most valuable customer
   */
  public Optional<Customer> findMostValuableCustomer(Stream<Order> orders) {

	  List<Customer> cs = new ArrayList<Customer>();
	  Map<Customer, Integer> acc = new HashMap();
	  orders.forEach(order -> acc.merge(order.getCustomer(), value(order.getCustomer(), order.getOrderLines()), Math::addExact));
	  return acc.entrySet().stream().sorted(Map.Entry.comparingByValue()).map(ac -> ac.getKey()).findFirst();
  }
  private Integer value(Customer c, Set<OrderLine> ols) {
	  
	  int i = ols.stream().mapToInt(ol -> ol.getProduct().getPrice().intValue() * ol.getQuantity()).sum();
	  System.out.println(""+c.getFirstName()+" "+c.getLastName()+" -> val: "+i);
	  return i;
  }
}

🚀 implement js function for which is the call sum(2)(3)(5); is valid!

//solution 1:
function sum(n1)
{
	return function(n2) {
		return function (n3) {
			return n1 + n2 + n3;
		}
	}
}
//alert(sum(2)(3)(4)); //should be 9

//solution 2: ES6
var sum = n1 => n2 => n3 => n1 + n2 + n3;
//alert(sum(2)(3)(4)); //should be 9

How to combine html files of a directory into one single html file containing all the small file contents?

copy *.html all.html

how to declare a self-made map in typescript, without using the 'Map' type?

Advantage: automatic JSON <-> JS object conversion works
(e.g. from the return of REST calls)
(in contrast to the Map type)

//declare
let mymap: {[id: string]: boolean};
//lookup
if (mymap[id2Look4]) { doSomething(); }
//iterate
Object.keys(mymap).forEach(key => ...);

TODO: log without unnecessary computation (lambda!)