Navigation

example

Arduino Prtotothreads alternative - without protothread library

Protothread alternative:

unsigned long timestamp = 0;
int interval = 1000; // =1s

void loop()
{
  if(millis() - timestamp > (unsigned long)interval) {
    timestamp = millis();
    //doSomething();
  }  
}

.

Arduino - servos example

#include <Servo.h> 
#define number_of_servos 12
#define servo_max_possition 100
#define min_possition 20
#define max_working_servos 6
Servo servos[number_of_servos];
int servoPins[] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13};
int servoStatus[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int servoPosition[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int servoSpeed[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int active_servos = 0;
int i;

void setup() 
{ 
  for (i=0; i<number_of_servos; i++) 
  {
    servos[i].attach(servoPins[i]);
    servos[i].write(min_possition);

Example PHP SESSION_START

index.php

SED examples

sed '/^$/d' $file # remove empty lines
sed 's/replace/perpleaxed/g' # replace text
var=`echo "Hello\,World" | sed 's/\\\,/,/'`; echo $var --> "Hello,World" # remove backslash
sed -n 'H; /^CHECK/h; ${g;p;}' f1.txt # sed print from last occurrence match until the end of file
sed -n '/<pattern>/,$ p' <file> # from pattern to end of file
sed -n '/<pattern1>/,/<pattern2>/ p' <file> # from pattern1 to pattern2
sed -n '1,/<pattern>/ p' <file> # print from the first line until pattern is matched

IPTables - masquerade

1. Nastavte v klikátku pevnou IP karty,která je připojená k ostatním počítačům v DOMACÍ SÍTI - například 192.168.0.1 a masku podsítě 255.255.255.0 2. Nějaký dodatečný nastavení NAT - ethX je karta připojená k internetu Kód: {syntaxhighlighter brush: php}sudo iptables -t nat -A POSTROUTING -o ethX -j MASQUERADE{/syntaxhighlighter} 3. Povolení IP forwardingu (potřebujete terminál superuživatele, ne příkaz sudo!) Kód: sudo gnome-terminal (resp. konsole) echo 1 > /proc/sys/net/ipv4/ip_forward 4. Nainstalujeme dnsmasq a ipmasq (to je na sdílení připojení nejdůležitější...

IPTables

#!/bin/sh
# 1. Co jde do retezce INPUT , jde JEN_NA_TEN_STROJ do lokalniho procesu.
# 2. Co jde do retezce FORWARD je urceno jinam a nekam preposlano.
# 3. Co jde do retezce OUTPUT jde z LOKALNIHO_PROCESU masiny ven.
# 4. FORWARD i OUTPUT jdou nakonec do POSTROUTING
# Zakladni traverse packetu retezci je:
# Ethx -> PREROUTING -> FORWARD (nebo INPUT -> OUTPUT) -> POSTROUTING -> Ethx
 
# loopback
LO_IP="127.0.0.1/32"

# vnejsi rozhrani (eth0, eth1)
INET_IFACE="eth0"
LAN_IFACE="eth1"

# cesta k programu iptables
IPTABLES="/sbin/iptables"

Upload souborů

<p>
<INPUT type="file" name="uploadedfile" size="62">

$trimmed=htmlspecialchars($_FILES["uploadedfile"]["name"]);
$trimmed=substr($trimmed, -3, 3);
$retez=$num_rows.".".$trimmed;

mysql_query("INSERT INTO quads (nazev,popis,cena,razeni,typ) VALUES ('$x_nazev','$x_popis','$x_cena','$x_razeni','$trimmed')");

$result=mysql_query("SELECT * FROM quads where nazev='$x_nazev' and popis='$x_popis'");
$cislo = @mysql_fetch_array($result);
//echo"$cislo[0]"; echo"<br>";
$uploaddir = './pictures/';
$uploadfile = $uploaddir . $cislo[0] . "." . $trimmed;

PHP - File upload

<p>
<INPUT type="file" name="uploadedfile" size="62">

$trimmed=htmlspecialchars($_FILES["uploadedfile"]["name"]);
$trimmed=substr($trimmed, -3, 3);
$retez=$num_rows.".".$trimmed;

mysql_query("INSERT INTO quads (nazev,popis,cena,razeni,typ) VALUES ('$x_nazev','$x_popis','$x_cena','$x_razeni','$trimmed')");

$result=mysql_query("SELECT * FROM quads where nazev='$x_nazev' and popis='$x_popis'");
$cislo = @mysql_fetch_array($result);
//echo"$cislo[0]"; echo"<br>";
$uploaddir = './pictures/';
$uploadfile = $uploaddir . $cislo[0] . "." . $trimmed;
Subscribe to example