num_digits = 3; bit_divisor = 2.^(0:num_digits-1); bit = zeros(2^num_digits,num_digits); for combination = 0 : 2^num_digits - 1, for nd = 1:num_digits, % just bit shift to right and mask the right-most bit bit(combination+1,num_digits-nd+1) = rem(floor(combination/bit_divisor(nd)), 2) end end % combination loop
Technical Things Around Me
How to Create Binary Table in MATLAB Elegantly
Create Raspberry Pi as A DLNA Media Center
OS : Raspbian
1. Install the following
2. Configure AP Daemon
3. set up /etc/hostapd/hostapd.conf as the configuration file
4. configure the network settings for clients connecting to AP
5. set up DHCP server configuration file
6. configure wlan0 for static IP adress (the same as router IP in dhcpd.conf file)
7. setting up Network Address Translation (NAT). Turn on packet forwarding in /etc/sysctl.conf
8. start the translation right away by running:
9. setting up the actual translation between the ethernet port called eth0 and the wireless card called wlan0
10. save the setting
11. In order to start AP on boot run the following commands:
12. When you got trouble with the dhcp server, restarting both hostapd and isc-dhcp-server on start up
1. install :
2. configure :
3. start / restart the service
References :
Access Point
1. Install the following
sudo apt-get install hostapd isc-dhcp-server iptables wpasupplicant
2. Configure AP Daemon
sudo nano /etc/hostapd/hostapd.conf -- interface=wlan0 #wlan0 will be working in AP mode ssid=Your_AP_SSID #your AP SSID channel=1 #WiFi channel used by AP # WPA and WPA2 configuration macaddr_acl=0 #indicates that you do not use MAC address allow/deny list auth_algs=1 #indicates algorithm specified by IEEE 802.11 ignore_broadcast_ssid=0 #AP will broadcast SSID #WPA settings wpa=2 #WPA algorithm used (WPA2 in this case) wpa_passphrase=my_secret_pass #AP password wpa_key_mgmt=WPA-PSK #WPA key mangement type wpa_pairwise=TKIP #encription algorithm rsn_pairwise=CCMP #encription algorithm #Hardware configuration driver=rtl871xdrv #type of driver to be used (in may be different depending on your WiFi dongle chipset) #in majority of cases it will be driver=nl80211 <-- use this for Buffalo Wifi USB dongle ieee80211n=1 #Whether IEEE 802.11n (HT) is enabled hw_mode=g #WPS RF Bands (a = 5G, b = 2.4G, g = 2.4G, ag = dual band) ##Note : for Buffalo Wifi USB dongle (Ralink RT8070) #country_code=JP #channel=2 #beacon_int=100 #max_num_sta=5
3. set up /etc/hostapd/hostapd.conf as the configuration file
sudo nano /etc/default/hostapd DAEMON_CONF="/etc/hostapd/hostapd.conf"
4. configure the network settings for clients connecting to AP
sudo nano /etc/dhcp/dhcpd.conf --- ddns-update-style none; #DDNS disabled default-lease-time 600; #IP lease time max-lease-time 7200; authoritative subnet 192.168.10.0 netmask 255.255.255.0 { #AP Subnet definition range 192.168.10.10 192.168.10.20 ; #Range of IP addresses available for clients option broadcast-address 192.168.10.255; option routers 192.168.10.1; #your client's gateway / router IP option domain-name "local-network"; #optional domain name option domain-name-servers 8.8.8.8, 8.8.4.4; #your DNS IP }
5. set up DHCP server configuration file
sudo nano /etc/default/isc-dhcp-server DHCPD_CONF="/etc/dhcp/dhcpd.conf" INTERFACES="wlan0"
6. configure wlan0 for static IP adress (the same as router IP in dhcpd.conf file)
sudo nano /etc/network/interfaces ---- auto lo iface lo inet loopback iface eth0 inet dhcp allow-hotplug wlan0 iface wlan0 inet static address 192.168.10.1 netmask 255.255.255.0 up iptables-restore < /etc/iptables.ipv4.nat
7. setting up Network Address Translation (NAT). Turn on packet forwarding in /etc/sysctl.conf
sudo nano /etc/sysctl.conf ---- net.ipv4.ip_forward=1
8. start the translation right away by running:
sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"
9. setting up the actual translation between the ethernet port called eth0 and the wireless card called wlan0
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE sudo iptables -A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT sudo iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT
10. save the setting
sh -c "iptables-save > /etc/iptables.ipv4.nat"
11. In order to start AP on boot run the following commands:
sudo update-rc.d hostapd enable sudo update-rc.d isc-dhcp-server enable
12. When you got trouble with the dhcp server, restarting both hostapd and isc-dhcp-server on start up
sudo nano /etc/rc.local --- add these line : --- sudo service hostapd stop sudo service isc-dhcp-server stop sudo ifdown wlan0 sudo ifup wlan0 sudo service hostapd restart sudo service isc-dhcp-server restart13. reboot
DLNA Server
1. install :
sudo apt-get install minidlna
2. configure :
sudo nano /etc/minidlna.conf --- # port for HTTP (descriptions, SOAP, media transfer) traffic port=8200 network_interface=wlan0 #Specify paths to directories containing digital media. media_dir=A,/media/stream/Music media_dir=V,/media/stream/Videos media_dir=P,/media/stream/Pictures friendly_name=Media Server db_dir=/mnt/tmp/minidlna album_art_names=Cover.jpg/cover.jpg/AlbumArtSmall.jpg/albumartsmall.jpg/AlbumArt.jpg/albumart.jpg/Album.jpg/album.jpg/Folder.jpg/folder.jpg/Thumb.jpg/thumb.jpg inotify=yes enable_tivo=no strict_dlna=no presentation_url=http://192.168.10.1:8200/ notify_interval=900 serial=12345678 model_number=1
3. start / restart the service
sudo service minidlna force-reload
References :
1. http://raspberry-at-home.com/hotspot-wifi-access-point/
2. http://raspberrypihq.com/how-to-turn-a-raspberry-pi-into-a-wifi-router/
3. http://www.dd-wrt.com/phpBB2/viewtopic.php?t=84881
4. http://terminal28.com/minidlna-upnp-media-server-debian-linux/
Setup Raspberry Pi As A Media Server
OS : Raspbian
To check the server: "IP_Address":8200. The webpage should show the number of content files in the server database.
1. install the server: sudo apt-get install minidlna 2. create media folder : mkdir /media/stream/Videos 3. updload file to the folder 4. set /etc/minidlna.conf . media_dir=V,/media/stream/Videos . to set DLNA automatically index new media : inotify=yes 5. reload : sudo service minidlna force-reload
To check the server: "IP_Address":8200. The webpage should show the number of content files in the server database.
Hide number on axis in a plot on MATLAB
set(gca,’XThick’,[])
set(gca,’YThick’,[])
set(gca,’ZThick’,[])
set(gca,’YThick’,[])
set(gca,’ZThick’,[])
How to make extRoot for openwrt on TL MR3040 v2
Preliminary : Upgrade firmware
- Grab the firmware from here: https://downloads.openwrt.org/barrier_breaker/14.07/ar71xx/generic/
- From command line :
cd /tmp
wget https://downloads.openwrt.org/barrier_breaker/14.07/ar71xx/generic/openwrt-ar71xx-generic-tl-mr3040-v2-squashfs-sysupgrade.bin
sysupgrade -n -v openwrt-ar71xx-generic-tl-mr3040-v2-squashfs-sysupgrade.bin
Preliminary : Format your flash drive with an ext4 or ext3 filesystem.
for example format from your PC: http://redacacia.files.wordpress.com/2013/04/mr3420_11.jpg
Install Packages:
/dev/sda2: UUID="9fa36631-ac09-42a0-b090-f61efe6c1bfb" NAME="EXT_JOURNAL" VERSION="1.0" TYPE="ext4"
Create a directory and mount your device on it:
Copy the router's internal flash to the flash drive :
Edit /etc/config/fstab file :
Enable and Start fstab :
Restart the router :
After booting and login, check the mount point:
You should see that /dev/sda2 has been mounted on /
- Grab the firmware from here: https://downloads.openwrt.org/barrier_breaker/14.07/ar71xx/generic/
- From command line :
cd /tmp
wget https://downloads.openwrt.org/barrier_breaker/14.07/ar71xx/generic/openwrt-ar71xx-generic-tl-mr3040-v2-squashfs-sysupgrade.bin
sysupgrade -n -v openwrt-ar71xx-generic-tl-mr3040-v2-squashfs-sysupgrade.bin
Preliminary : Format your flash drive with an ext4 or ext3 filesystem.
for example format from your PC: http://redacacia.files.wordpress.com/2013/04/mr3420_11.jpg
Install Packages:
root@OpenWrt:~# opkg update root@OpenWrt:~# opkg install kmod-usb-storage kmod-fs-ext4 block-mountFind the name of your flash drive with the : block info
root@OpenWrt:~# block info/dev/mtdblock2: UUID="20ad40ea-d33a421e-785b7d2d-ada99230" VERSION="4.0" TYPE="squashfs" /dev/mtdblock3: TYPE="jffs2"
/dev/sda2: UUID="9fa36631-ac09-42a0-b090-f61efe6c1bfb" NAME="EXT_JOURNAL" VERSION="1.0" TYPE="ext4"
Create a directory and mount your device on it:
root@OpenWrt:~# mkdir -p /mnt/flash root@OpenWrt:~# mount -t ext4 /dev/sda2 /mnt/flash
Copy the router's internal flash to the flash drive :
root@OpenWrt:~# mkdir -p /tmp/cproot root@OpenWrt:~# mount --bind / /tmp/cproot root@OpenWrt:~# tar -C /tmp/cproot -cvf - . | tar -C /mnt/flash -xf - root@OpenWrt:~# umount /tmp/cproot
Edit /etc/config/fstab file :
root@OpenWrt:~# vi /etc/config/fstab
config global option delay_root 1 config global automount option from_fstab 1 option anon_mount 1 config global autoswap option from_fstab 1 option anon_swap 0 config mount option target / option device /dev/sda2 option fstype ext4 option options rw,sync option enabled 1 option enabled_fsck 0 config swap option device /dev/sda1 option enabled 1
Enable and Start fstab :
root@OpenWrt:~# /etc/init.d/fstab enable root@OpenWrt:~# /etc/init.d/fstab start
Restart the router :
root@OpenWrt:~# reboot -f
After booting and login, check the mount point:
root@OpenWrt:~# mount
You should see that /dev/sda2 has been mounted on /
root@OpenWrt:~# mount rootfs on / type rootfs (rw) /dev/root on /rom type squashfs (ro,noatime) proc on /proc type proc (rw,noatime) sysfs on /sys type sysfs (rw,noatime) tmpfs on /tmp type tmpfs (rw,nosuid,nodev,noatime) /dev/sda2 on / type ext4 (rw,relatime,data=ordered) tmpfs on /dev type tmpfs (rw,relatime,size=512k,mode=755) devpts on /dev/pts type devpts (rw,relatime,mode=600) debugfs on /sys/kernel/debug type debugfs (rw,noatime)
How to Sort a Vector With the Same Order As Other Vector in Matlab
Example :
A = [5 3 4 1 2]; B = [-6 -8 -7 -10 -5];Answer :
C = sortrows([A.' B.']);or
[A, idx] = sort(A); B = B(idx);
Subscribe to:
Posts (Atom)