for busybox shell ash, string starts with function
1 2 3 4 5 6 7 8 9 10 |
stringstartswith(){ local len=$(expr length $2) local input=$(expr substr $1 1 $len) if [ $input = $2 ];then echo true else echo false fi } |
for busybox shell ash, string starts with function
1 2 3 4 5 6 7 8 9 10 |
stringstartswith(){ local len=$(expr length $2) local input=$(expr substr $1 1 $len) if [ $input = $2 ];then echo true else echo false fi } |
a pure javascript library for node.js is published. “icoimagejs”
it converts a 32 bit RGBA raw image structure to ico image format
https://www.npmjs.com/package/icoimagejs
I have coded for my free online photo editor project. that it will convert any image to ico format.
bmp image decoder library for nodejs is published to npm.
it is ported from a c library http://www.netsurf-browser.org/projects/libnsbmp/
https://www.npmjs.com/package/bmpimagejs,
https://github.com/hamzakilic/bmpjs
enjoy
for a while I was working on a html based online “image/photo editor” that you don’t need to install anything for image/photo process.now I have published the first version.
just type www.imageeditor.online , completely free
It supports multi layer, multi workspace,image effects and more…
enjoy
bir süredir üzerinde çalıştığım, angular temelli bir image editor programı olan www.imageeditor.online nihayet ilk sürüm aşamasına geldi.
multi layer,multi selection, multi workspace, image effects,pixel to pixel work gibi bir çok yetenek barındıyor.
imaj işlemlerinizde yardımcı olması dileğiyle.
Edge browser does not contain createBitmapImage function.
if you want to use it with ImageData
you can use this function as polyfill with typescript
Window.prototype.createImageBitmap = function(imageData):Promise{
return new Promise((resolve,reject)=>{
let canvas=document.createElement('canvas');
canvas.width=imageData.width;
canvas.height=imageData.height;
let context= canvas.getContext("2d");
context.putImageData(imageData,0,0);
return resolve(canvas);
});
}
Typescript ile extension method nasıl yazılır.
let x: number = 5.5;
let rounded = Math.round(x);
böyle yazmaktan sıkıldıysanız.
let rounded = x.extRound();
şeklinde yazmak isterseniz.
extensions.ts adlı bir dosya açalım
interface Number { extRound: () => number; } Number.prototype.extRound = function(): number { return Math.round(this); }
calculator.ts dosyasında söyle kullanalım
import "./extensions"; export class calculator { public roundedVal(): number { let test = 5.5; return test.extRound(); } }
Tabiki burada extension methodlar yazarken dikkat edilmesi gereken, methodlara mutlaka unique bir isim vermeniz. aksi takdirde kullandığınız diğer library’lerden aynı isimli methodları ezme ihtimaliniz var. bu yüzden ben methodun başına ext koydum.
nodejs muhteşem dimi ?
acayip kavramları hayatımıza getirmiş gibi gözüküyor?
öncelikli olarak ben nodejs’i seviyorum ve kullanıyorum. ama pazarlanmasını pek sevmedim o yüzden, pazarlanmasında öne çıkan şeyleri aşağıda eleştireceğim.
olaya biraz derinlemesine bakalım.
I/O
öncelikli olarak bir var socket= createSocket(…..) açtığımızı düşünelim
işletim sistemlerinde 3 türlü I/O mekanızması vardır .
a) blocking I/O mode
int size= read(socket,…) dediğimizde socket’te data yoksa, gelinceye kadar program bekler
b) non/blocking I/O mode
int size=read(socket,…) dediğimizde method hemen geri döner, veri varsa size >0 olur yoksa size=0 olur.
c) Async I/O
read(soket, $callback) mantığı ile çalışır. yani sokete veri geldiğinde $callback methodunu çağır ile çalışır.
gördüğünüz gibi node.js kullandığı model c modelidir.
node.js async IO yapmak için https://github.com/libuv/libuv projesini geliştirmiş . bu projenin feature kısmında zaten “epoll,kqueue …..” gibi şeyleri gördünüzde async I/O görürsünüz.
yani işletim sistemleri (linux,bsd,windows) zaten bu üç modelide çok eskiden beridir destekliyorlar. bayağı eski hemde
yoksa apache,nginx, IIS ve ismini sayamadığım müthiş performanslı çalışan web serverları yazmak mümkün olmazdı.
yani yeni bir şey yok.
Event-driven
event-driven zaten çok eski bir fikir. “event-driven architecture” diye geçer. bu fikir üzerine inşa edilmiş bir sürü şey var.
yine yeni bir şey yok.
velhasılı kelam, node.js bir “javascript ecosystem” yaratmak için güzel bir başlangıç noktası olmuştur. ama müthiş bir backend programlama dilimi acaba, pek emin değilim.
yani hayatımıza yeni kavramlar falan getirmedi. hepsi zaten kullandığımız şeylerdi.
hakkınıda çok yemeyeyim, ben seviyorum nodejs’i
lets talk about gpio events.
bcm2835 arm peripherals document explains that, there as some registers for detecting events. page 97-99
GPIO Rising Edge Detect Enable Registers (GPRENn)
GPIO Falling Edge Detect Enable Registers (GPRENn)
GPIO High Detect Enable Registers (GPHENn)
GPIO Low Detect Enable Registers (GPLENn)
GPIO Asynchronous Falling Edge Detect Enable Registers (GPAFENn)
GPIO Asynchronous rising Edge Detect Enable Registers (GPARENn)
these above registers are used to set which pin you want to detect.enable pin bit 1,disable for pin bit 0.
at the end, when an event occurs, you can get it from below register related pin. if it is 1 than you got the event. writing 1 to the related pin clears event.
GPIO Event Detect Status Registers (GPEDSn)
Note: default raspian kernels have gpio driver enabled, and this gpio driver catch’s interrupts.when event occurs also it generates interrupts, before you can see event from register, interrupt handler reads event and clears register. if you want to detect event, you must disable interrupts, or driver.
you can use my compiled kernel. kernel.img.tar.gz
prepare your circuit as below
and here is the code event_pull.c
have a nice day.
next article we will talk about raspberry pi mini uart
hi, again.
when you put a pin to mode INPUT. you can set pull up/down registers.
because when you booted raspberry pi ,all gpio’s have default PULL UP or PULL DOWN registers. previus article sample is working because when we put pin to INPUT, it’is LOW. if you use another pin that is HIGH it will not work.
look at below picture. it is taken from bcm2835 sheet page 102
now changing pull up/down
in document page 91, I have taken this address’s
0x 7E20 0094 GPIO Pin Pull-up/down Enable 32
0x 7E20 0098 GPIO Pin Pull-up/down Enable Clock 0
0x 7E20 009C GPPUDCLK1 GPIO Pin Pull-up/down Enable Clock 1
#define PERIPHERALS_GPIO_PULL_PHYSICAL (0x94/sizeof(int))
#define PERIPHERALS_GPIO_PULL_CLOCK_PHYSICAL (0x98/sizeof(int))
as you see we defined two address, why ?
because we will set PULL value to PERIPHERALS_GPIO_PULL_PHYSICAL address
and pin value to PERIPHERALS_GPIO_PULL_CLOCK_PHYSICAL address.
but procedure of changing pull value is more than this.
from document:
1. Write to GPPUD to set the required control signal (i.e. Pull-up or Pull-Down or neither
to remove the current Pull-up/down)
2. Wait 150 cycles – this provides the required set-up time for the control signal
3. Write to GPPUDCLK0/1 to clock the control signal into the GPIO pads you wish to
modify – NOTE only the pads which receive a clock will be modified, all others will
retain their previous state.
4. Wait 150 cycles – this provides the required hold time for the control signal
5. Write to GPPUD to remove the control signal
6. Write to GPPUDCLK0/1 to remove the clock
lets start:
write correct bit values to (gpio+PERIPHERALS_GPIO_PULL_PHYSICAL)
correct values:
00 = Off – disable pull-up/down
01 = Enable Pull Down control
10 = Enable Pull Up control
then
wait 5 microseconds
then
set correct pin bit to 1 at (gpio+PERIPHERALS_GPIO_PULL_CLOCK_PHYSICAL) adress
then
wait 5 microsecond
then
write zero to (gpio+PERIPHERALS_GPIO_PULL_PHYSICAL) address
then
wait 5 microsecond
then
write (gpio+PERIPHERALS_GPIO_PULL_CLOCK_PHYSICAL) adress
below is the algorithm.
now create a template board above. and test it
neededs:
2 cables (yellow is output, and orange is input)
1 10K resistor
1 push button
as you see, orange cable is at 7 pin, which is HIGH when rebooted raspberry.
if you disable
setPull(inputpin,EM_PULL_DOWN);
code it will now work as expected.
reboot your raspberry before testing. when you change a pin PULL_DOWN, until you change again it will be PULL_DOWN.
here is test code pull.c
gcc -o test pull.c