반응형

php에서 문자열을 치환해주는 함수가 있다.

str_place()함수인데 아래와 같이 사용하면 된다


str_replace("치환할 문자", "치환될 문자", "대상 문자열") 


예) article변수에서 "<b>"라는 내용을 ""로 대체한다. 즉, "<b>"내용을 찾아 지우라는 것과 같다.

$tmp = str_replace("<b>", "", "$article") 


반응형

file_get_contents 함수는 서버 보안상 off되있는곳이 많다.

이 함수를 curl를 이용하여 대체가능하다.


세부 링크 :http://www.partner114.com/bbs/board.php?bo_table=B07&wr_id=126

<?php

function curl($url) {

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);

$g = curl_exec($ch);

curl_close($ch);

return $g;

}

?>

위와 같이 별도의 함수를 파일로 만들어서 include해서 사용할수 있다.


반응형

Link : http://jmnote.com/wiki/PHP_%EC%88%98%ED%96%89%EC%8B%9C%EA%B0%84_%EC%B8%A1%EC%A0%95


<!DOCTYPE html>
<meta charset="utf-8" />
<?php
function get_time() {
    list($usec, $sec) = explode(" ", microtime());
    return ((float)$usec + (float)$sec);
}
 
$start = get_time();
/*
수행할 내용
*/
$end = get_time();
$time = $end - $start;
echo '<br/>'.$time.'초 걸림'

?>


반응형

안드로이드 앱 개발시 화면이 꺼지는것을 방지해야하는 때가 있다.

그럴 경우 다음과 같이 한다.


필요 클래스 :
import android.view.WindowManager;

  

그리고 onCreate 메소드 안에 아래를 추가한다.

getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

반응형

참고 URL : http://elinux.org/RPi_VNC_Server



What does it do?

Sometimes it is not convenient to work directly on the Raspberry Pi. Maybe you would like to work on it but from another computer by remote control. You can do this and the remote computer can even be anywhere in the world over the internet. This tutorial shows how you can view and control the raspberry pi desktop from your computer's desktop by using special software.

What do you need?

  • A Raspberry Pi
  • A boot SD card for the Raspberry Pi
  • A network connection (Ethernet or WiFi)
  • Special software on both the Raspberry Pi and the remote, controlling computer

What skill level is required?

This project does not require any coding or compilation. Very basic Linux and networking knowledge would be useful, but not essential.

You need to...

  • Install software
  • Enter basic Linux commands
  • Use standard software tools (Windows/Linux/Mac) to add software to your PC
  • Connect computers using ethernet cables

How does it work?

The commands described below start a "virtual" graphical session. Instead of using a hardware framebuffer, this uses RAM for a framebuffer. It also opens a network channel or port that allows programs on other computers (if they provide the password) to show the framebuffer and provide mouse and keyboard events.

This way you can run a desktop session on the raspberry pi, but display and control it elsewhere.

Because the framebuffer isn't the real framebuffer you cannot take advantage of the GPU to accelerate operations on the screen.

Overview of this project

You need to

  • Install VNC (Virtual Network Computing) server software on the Raspberry Pi
  • Start the VNC server software
  • Install a VNC client on another computer
  • Connect over a network from your computer to the Raspberry Pi

Instructions

Log in to your Pi and install the Tight VNC Package

$ sudo apt-get install tightvncserver

Next Run TightVNC Server which will prompt you to enter a Password and an optional View Only Password

$ tightvncserver

Once that is done you can start a VNC server from the shell prompt. This example starts a session on VNC display zero (:0) with full HD resolution:

$ vncserver :0 -geometry 1920x1080 -depth 24

(If fonts appear the wrong size, add '-dpi 96' to the end.) Or you could create a script to save typing in the whole thing.

$ nano svnc.sh (call the file whatever you like)

Add the lines:

#!/bin/sh
vncserver :0 -geometry 1920x1080 -depth 24 -dpi 96

Ctrl-x y <return> (To Exit Nano and Save)

Set the file to Execute

$ chmod +x svnc.sh

then to run

$ ./svnc.sh

Run at boot.

Start a root session

sudo bash

Create a file in /etc/init.d with a suitable name such as vncboot with the following content.

### BEGIN INIT INFO
# Provides: vncboot
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start VNC Server at boot time
# Description: Start VNC Server at boot time.
### END INIT INFO

#! /bin/sh
# /etc/init.d/vncboot

USER=root
HOME=/root

export USER HOME

case "$1" in
 start)
   echo "Starting VNC Server"
   #Insert your favoured settings for a VNC session
   /usr/bin/vncserver :0 -geometry 1280x800 -depth 16 -pixelformat rgb565
   ;;

 stop)
   echo "Stopping VNC Server"
   /usr/bin/vncserver -kill :0
   ;;

 *)
   echo "Usage: /etc/init.d/vncboot {start|stop}"
   exit 1
   ;;
esac

exit 0

Modify the file permissions so it can be executed

chmod 755 /etc/init.d/vncboot

Enable dependency based boot sequencing

update-rc.d /etc/init.d/vncboot defaults

If enabling dependency based boot sequencing was successful, it says

 update-rc.d: using dependency based boot sequencing

But if it says

update-rc.d: error: unable to read /etc/init.d//etc/init.d/vncboot

then try the following command

update-rc.d vncboot defaults

Reboot your Raspberry PI and you should find a vncserver already started.


Install Tight VNC on your desktop from the link below or most VNC clients work I believe.

http://www.tightvnc.com/download.php

Or install it using your package manager. The following works on my ubuntu 11.10 workstation

sudo apt-get install xtightvncviewer

Then use <Your Pi IP>:1 (e.g. 192.168.1.2:1) as the host name when connecting.[1]

Works Great, select full screen from the tool bar and a full 1080p 24bit desktop is yours from anywhere.

  1.  You can put your raspberry pi in /etc/hosts on Linux systems. I think you can make such a file on windows too. Then you can refer to your raspberry pi as "rpi" or whatever you called it.

Getting VNC Server to Work on a Specific User

Instead of using the script in the Raspberry Pi wiki, use this one provided by "PenguinTutor":

#!/bin/sh
# /etc/init.d/tightvncserver
# Customised by Stewart Watkiss
#http://www.penguintutor.com/linux/tightvnc
# Set the VNCUSER variable to the name of the user to start tightvncserver under
VNCUSER='pi'
eval cd ~$VNCUSER
case "$1" in
 start)
   su $VNCUSER -c '/usr/bin/tightvncserver :1'
   echo "Starting TightVNC server for $VNCUSER "
   ;;
 stop)
   pkill Xtightvnc
   echo "Tightvncserver stopped"
   ;;
 *)
   echo "Usage: /etc/init.d/tightvncserver {start|stop}"
   exit 1
   ;;
esac
exit 0

Now, change the VNCUSER=pi to your desired username, so for example: VNCUSER=jsmith

That'll make it boot on the username of which you want it to boot on... but I then received the grey screen error when remotely accessing the Pi from my computer, now the way you fix this is, open up the xstartup file that was created when VNCSERVER executes on your desired username. Now the way you access it and edit it is by:

sudo nano .vnc/xstartup 

.vnc is usually in the home directory.

Delete everything that is in xstartup (or not in as mine was), and add this:

!/bin/sh
xrdb $HOME/.Xresources
xsetroot -solid black
/usr/bin/lxsession -s LXDE &

Now it should work.

Does Your Openbox Configuration Settings Not Start on VNC?

You'll often find yourself in a position where VNC will start, but you'll get things such as multiple virtual desktops appearing, and you try to save it in the "Openbox Configuration Manager," and they go away for a second, but then you find you'll restart the Pi and then they appear again. Here's how to fix it:

Create, or edit the current autostart.sh file which is located in:

.config/openbox/autostart.sh

Edit using "Nano" or any other text editor, I use Nano as it is the most comfortable for me, so do:

sudo nano .config/openbox/autostart.sh/

Add the line: exec openbox-session

Now add the line exec openbox-session again in .vnc/xstartup and now it should work.

But you can't really save the setting in Openbox Configuration Manager on VNC, but you have to do it manually; so you open this file:

nano .config/openbox/lxde-rc.xml

Scroll down to: <desktops>

You should see a bunch of stuff there, but only focus on this: <number>6</number> or something similar.

Change the number of desktops you want within the <number></number> bit.

I changed mine to 1, because that's all I want.

It should now work!

Limitations and Alternatives

In this example TightVNC has been used. This is a popular and relatively friendly program that uses the VNC protocols and is included in most GNU/Linux distributions. However it does have it's limitations. The biggest of these is that it creates new desktops for each connection. It may be that what you want to do though is view and control the same desktop that shows on the monitor/TV plugged into the Raspberry Pi. To do this a better tool to use is x11vnc. This is more powerful but less easy to use. However if you already have a desktop running it will latch on to it and share it as a default. This too is fairly popular and included in many GNU/Linux distribution repositories such as Raspbian.

Security Considerations

Be aware that basic VNC is not secure. It is not encrypted unless you are advanced in setting it up. If you use it over the internet it can result in criminals "bouncing" you off your connection and taking over. There are even computer robot tools that try to do this. You must set a password but even then it is sometimes possible to take over someone's connection after they have entered it. A good tip is to set the server to shift from the default port 5900 to something else chosen randomly as long as it is spare.

'Programming' 카테고리의 다른 글

PHP 수행시간 측정  (0) 2013.08.11
[Android] 화면 꺼짐 방지 소스  (0) 2013.06.27
Using PWM in RPi.GPIO  (0) 2013.05.28
[소스]라즈베리파이 서보모터 컨트롤하기  (0) 2013.05.28
MySQL 기본 명령어 정리  (0) 2013.05.20
반응형
import time
import RPi.GPIO as GPIO
GPIO
.setmode(GPIO.BOARD)
GPIO
.setup(12, GPIO.OUT)

p
= GPIO.PWM(12, 50)  # channel=12 frequency=50Hz
p
.start(0)
try:
   
while 1:
       
for dc in range(0, 101, 5):
            p
.ChangeDutyCycle(dc)
            time
.sleep(0.1)
       
for dc in range(100, -1, -5):
            p
.ChangeDutyCycle(dc)
            time
.sleep(0.1)
except KeyboardInterrupt:
   
pass
p
.stop()
GPIO
.cleanup()


+ Recent posts