Jak stworzyć dyrektywę w AngularJS ? Na przykładzie prostej dyrektywy input-label-text.

Możliwe, że wielu z Was, przeglądając kod, natknęło się na magiczne wyrażenie ‚directive’. Czym tak naprawdę jest? Jak można coś takiego stworzyć samemu? Na te pytania spróbuję odpowiedzieć, opisując krok po kroku tworzenie prostej dyrektywy input-label-text.

  1. Czym jest dyrektywa w AngularJS?

    Jest to reużywalny komponent, w kodzie widoczny najczęściej jako znacznik (tag), atrybut lub wartość atrybutu. Klasycznie składa się z części skryptowej, gdzie możemy zdefiniować potrzebne zmienne, funkcje, etc. oraz z części HTML-owej, czyli tzw. template’a – kawałku kodu, ‚wstrzykiwanego’ w miejsce wywołania dyrektywy.

  2. Jak ją stworzyć? Jak skonfigurować swoje pliki, aby dyrektywa zadziałała?

    Pokaże to na przykładzie komponentu, który łączy ze sobą tagi <input> i <label> oraz implementuje prostą logikę w swoim własnym wydzielonym kontrolerze.

Czytaj dalej

JSoup mini-tutorial – parsowanie HTML w środowisku java

Wstęp

Biblioteka JSoup pozwala w sposób szybki i przyjemny przeparsować dokument HTML i wyciągnąć z niego interesujące nas dane. Używając gotowego parsera (zamiast na przykład wyrażeń regularnych) oszczędzimy sporo czasu i nerwów, a przede wszystkim umożliwimy samym sobie stworzenie czytelniejszego rozwiązania.

JSoup umożliwia zarówno klasyczne przechodzenie po drzewie (children <> parent), jak i wyszukiwanie węzłów po:

  • html’owym id
  • dowolnych atrybutach
  • html’owym class
  • html’owym tagu (czyli nazwie znacznika)
  • selektorze css (tak, jak w arkuszu styli / jQuery)

Czytaj dalej

AliExpress / EBay / China market fake DS18B20 Sensors

Update 23.05.2016

Some sensors MAY actually work. This does not discard what i wrote before (I tested them all), but: For some reason some of the sensors gives invalid response to ‚Power supply’ command. They always respond as they are parasite-powered. Some devices (ex. mine) do check that and reported them as invalid. However I tested all ‚Invalid’ with osciloscope. Some of them gave some response, so i took the deeper test.

Introduction

If you’re planning to order cheap DS18B20 sensors from AliExpress – keep in mind that irrationally low price (less than $0.8 / pc) smells really fishy.

Manufacturer price for 1k is $1.18.

My experience:

I recently ordered two six lots from two different sellers:

http://www.aliexpress.com/item/10pcs-lot-DS18B20-TO-92-18B20-chips-Temperature-Sensor/32615902919.html (Keeps data line low)

http://www.aliexpress.com/item/DS18B20-DALLAS-TO-92-Programmable-Resolution-1-Wire-Digital-Thermometer-new-and-original-free-shipping/32460503179.html (No response for presence)

http://www.aliexpress.com/item/10PCS-LOT-DS18B20-TO92-18B20-TO-92-Temperature-sensor-New-and-Origianl-DS18B20/32353012700.html (No response for presence)

http://www.aliexpress.com/item/Free-Shipping-10PCS-DS18B20-TO92-Sensor-18B20-TO-92-Digital-Thermometer/514174063.html (All works!)

http://www.aliexpress.com/item/Free-Shipping-10pcs-lot-DS18B20-18B20-TO-92-DALLAS-MAXIM-100-New-Original/883530054.html (Keeps data at +1.0V)

http://www.aliexpress.com/item/Free-Shipping-20pcs-DALLAS-DS18B20-18B20-18S20-TO-92-IC-CHIP-Thermometer-Temperature-Sensor/32236763433.html (All works)

In first case I received 4x DS18S20 and 6x something else (not really sure what, but definitely not DS18B20)

In rest none was DS18B20 sensor. Instead i got one NPN transistor, one PNP transistor and  8x something else (thyristors actually).

2016-04-26 16.25.03 2016-04-26 16.26.24

The easy test:

According to DS18B20 datasheet, there should be an input diode somewhere between VCC and GND. If you connect the sensor in the opposite way it should give a short.

To test it, I simply used multimetr with diode check mode, connected between VCC and GND.

For real sensor it should ‚detect’ the diode.

For fake of course it would not.

2016-04-26 16.09.19

Real DS18B20

2016-04-26 16.09.32

Fake DS18B20

 

 

How to recognize fake parts?

As for today (18.05.16) I see some common attributes of all fake parts:

  • They have DALLAS marking. Normally, when ordering from china, I got parts with ‚7Q-Tek’ or others. Some working parts have DALLAS also. But no DALLAS marking increases chances for working product.
  • Some fakes had +919AF serial code, none worked. The +233AA – some good, some dead
  • Surface with marking is ‚sandy’, not glossy. Its probably because of removed marking
  • The diode test (above)
  • Test for any communication

More information:

https://www.telldus.com/forum/viewtopic.php?f=12&t=5958

AliExpress Hidden search options: Show Price Per Piece, Max Quantity, etc

Some time ago AliExpress (and probably others of their family) has simplified their search engine, removing some useful search options like:

  • Sorting by price per piece / lot
  • Selecting maximum quantity
  • Showing price per piece

Although they are removed from the search panel, they are still valid and correctly parsed if added to URL.

To get those options, please append following parameters to URL. They are separated by & character:

Option Name URL Parameter
Show Price Per Piece isUnitPrice=y
Maximal quantity in lot maxQuantity=n
Minimal quantity in lot minQuantity=n

To get lowest price per piece simply combine: „Show Price Per Piece” + Order by Lowest Price + (optionaly) Maximal quantity

How to disable OnePlus / CyanogenOS application suggestions

If you are getting annoyed with recent update new feature showing microsoft office (and possibly other) applications as suggested while opening some files, here are steps to disable them:

  1. Go to Settings
  2. Go to Applications
  3. Swipe to All (last on the right) tab
  4. Find ‚Cyanogen Application Suggestions’
  5. Click
  6. Click Disable

Done

Smart Prototyping – PCB Prototyping review

http://smart-prototyping.com/PCB-Prototyping.html – another cheap Chinese PCB Manufacturer review

My order:

  • PCB
    • 2 layers
    • 10cm x 10 cm
    • 10 pieces
    • PCB Thickness: 1.6mm
    • Copper thickness: double – 2oz/ft2 = 70um
    • Surface finish: HASA
    • Solder mask color: Green (additional fees for other colors)
    • No sub-boards
    • 100% E-Test
  • Stencil – frameless 13cm x 21cm

Czytaj dalej

ShenZen2U PCB Prototyping Review

http://www.shenzhen2u.com/PCB – cheap Chinese PCB Manufacturer review

My order:

  • PCB
    • 2 layers
    • max 5cm x 5 cm
    • 10 pieces
    • PCB Thickness: 1.6mm
    • Copper thickness: standard – 1 oz/ft2 = 35um
    • Surface finish: HASA
    • Solder mask color: Green (additional fees for other colors)
    • No sub-boards
    • 100% E-Test
  • Stencil – frameless 19cm x 29cm

Czytaj dalej

Cheap PCB prototyping in China – review

Hi again!

I’m in progress of testing some of cheap Chinese PCB manufacturers. I’m going to try to write detailed description for each of them.

Right now I found:

ShenZen2U and SmartPrototyping looks bascily like the same company. But they are not (as SmartPrototyping explained).

AMD AM1 (Athlon 5350) Real power consumption

Rationale

A few days ago I was building rack 19″ server based on AMD Athlon 5350 CPU. The main goal was to create a hardware set that will operate on wide supply voltage ranges (48V, 24V, 19V) and will be power efficient.

I decided to take a look at quite cheap AMD AM1 Athlon APU with TDP said to be 25W.

Czytaj dalej

Installing and running SCons on Windows with MinGW

1. Installing Python 2.x 32bit

Right now, when SCons  2.3.4 is the latest available version, it won’t work with python >= 3.4.1. Thats because of modified behavior of print function. Its usage without ( ) is depracted and causes errors in latest python version. This construction is still used in some of SCons scripts.

SCons installer is also not capable of finding installation of 64 bit python.

Thats why you should choose latest ‚2’ version in 32 bit. For me – 2.7.9

For purposes of this test I put Python in default directory:

C:\Python27\

2. Installing SCons

The easiest way to install SCons on windows is to use default Win32 installer. There are no sophisticated install options.

Installer will put some files in <Python>\Scripts directory. Nothing more, nothing less.

Main SCons executable is wrapped with scons.bat which should be used as default SCons launcher.

3. Creating SCons launcher in projects directory

In your project directory in which your SConstruct file is located you should create new batch file. For purposes of this tutorial I called it ‚run_scons.bat’.

Inside put something like:

"C:\Python27\Scripts\scons.bat"
if NOT ["%errorlevel%"]==["0"] pause

This will simply run scons.bat in SCons installation directory and pause closing of command line dialog if error occurred.

Creating shortcut to scons.bat won’t work since shortcut changes working directory of environment to targets directory. We want to stay in projects directory.

 4. Configuring SCons to use MinGW instead of MSVC++

Some steps must be done in SConstruct to properly use MinGW compiler

  1. Environment must be initialized with tools = [‚mingw’] parameter
  2. Environment[‚ENV’][‚PATH’] must have „bin” directory of MinGW
  3. Target should be linked with -static option enabled

for example:

(...)
E = Environment(tools = ['mingw'])
E['ENV']['PATH'] += ';' + r'C:\Program Files (x86)\mingw-w64\i686-4.9.2-posix-dwarf-rt_v3-rev1\mingw32\bin'
E.Append(LINKFLAGS = "-static")
(...)

5. Running SCons

Just double-click run_scons.bat 🙂