PHP unicode decoder

function unicode_decode($txt) {
 $txt = preg_replace_callback(
  '/%u([[:alnum:]]{4})/',
  create_function('$match', 'return "&#".hexdec($match[1]).";";'),
  $txt
 );
 $txt = preg_replace_callback(
  '/%([[:alnum:]]{2})/',
  create_function('$match', 'return "&#".hexdec($match[1]).";";'),
  $txt
 );
 return ($txt);
}

 

Udgivet i Knowledge Base, Old Base, PHP, Programmering | Skriv en kommentar

Dead paths in FreeBSD

If your FreeBSD can’t find the path to a newly installed program from ports, just run “rehash”

Udgivet i FreeBSD, Knowledge Base, Old Base | Skriv en kommentar

Binary Prefix Definition

http://physics.nist.gov/cuu/Units/binary.html

MegaBytes = 1000 * 1000 bytes
MeBiBytes = 1024 * 1024 bytes

Udgivet i Knowledge Base, Old Base | Skriv en kommentar

cvsup FreeBSD to current

Install cvsup:

cd /usr/ports/net/cvsup-without-gui && make install

For Stable use tag=RELENG_4

Create file /usr/src/current-supfile with this inside:
Use this cvsup file:
# IMPORTANT: Change the next line to use one of the CVSup mirror sites
*default host=cvsup.dk.FreeBSD.org
*default base=/usr
*default prefix=/usr
*default release=cvs tag=.
*default delete use-rel-suffix
*default compress
src-all

Run cvs up
/usr/local/bin/cvsup -g -L 2 /usr/src/current-supfile

Compile new source

rm -rf /usr/obj/* <- deletes old objectfiles cd /usr/src make buildworld <- starts the compile configure the kernel makefile cd /usr/src/sys//conf/
cp GENERIC MYKERNEL

edit mykernel to fit your configuration

compile kernel:

cd /usr/src
make buildkernel KERNCONF=MYKERNEL

install kernel:
make installkernel KERNCONF=MYKERNEL

reboot the machine, go into boot prompt and type: boot -singel now machine will boot into singelmode

fsck / <- run fsck on / mount -u / <- remont / rw mount -a -t ufs <- mount other unix file systems swapon -a <- activate swap install the souce we compiled before cd /usr/src make installworld Merge config files: (i almost never do this) /usr/sbin/mergemaster -a update sysinstall cd /usr/src/release/sysinstall make all install reboot into youre newly upgraded os: fastboot

Udgivet i FreeBSD, Knowledge Base, Old Base | Skriv en kommentar

Using threads in perl

Remember setting threads in your ./Configure, cause it’s not compiled by default!

Example:

#!/usr/bin/perl

use Thread;

new Thread \&test_sub;

sub test_sub {
while(1) {
sleep 2;
print “TestSUB\n”;
}
}

while(1){
sleep 3;
print “NormalProc\n”;
}

For more information, see http://www.xav.com/perl/lib/Thread.html

Udgivet i Knowledge Base, Old Base, Programmering | Skriv en kommentar

Netgear MR314 telnet interface

ifaces:
enif0 = lan
enif1 = wan

ifconfig:
ip ifconfig

route:
ip route status
ip route add [/] []
ip route addiface [/] []
ip route drop [/]

dhcp:
ip dhcp status
ip dhcp client release
ip dhcp client renew

arp:
ip arp status

Udgivet i Hardware hacking, Knowledge Base, Old Base | Skriv en kommentar

Change NIC MAC in linux

root@spacecamp:~# ifconfig eth2 down
root@spacecamp:~# ifconfig eth2 hw ether aa:aa:aa:aa:aa:aa
root@spacecamp:~# ifconfig eth2 up
root@spacecamp:~# ifconfig eth2
eth2      Link encap:Ethernet  HWaddr AA:AA:AA:AA:AA:AA
          inet addr:192.168.20.1  Bcast:192.168.20.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1275 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:100
          RX bytes:0 (0.0 b)  TX bytes:319067 (311.5 Kb)
          Interrupt:11 Base address:0x4000
Udgivet i Knowledge Base, Linux, Networking, Old Base | Skriv en kommentar

Adding an ip alias to a NIC in FreeBSD & Linux

Freebsd :
rc.conf:

ifconfig_rl0_alias0=”10.1.1.24 netmask 0xffffffff”

manually:

ifconfig rl0 alias 10.1.1.24 netmask 0xffffffff

Linux:

ifconfig eth0:0 10.1.1.25 netmask 255.255.255.255

Udgivet i FreeBSD, Knowledge Base, Linux, Old Base | Skriv en kommentar

No color when programming ncurses on linux when connected via putty.

When you login via putty then your TERM is set to 'xterm'. You will not be able to see colors with ncurses.

Set TERM='linux' and you can now see the colors.

cc
Udgivet i Knowledge Base | Skriv en kommentar

No color when programming ncurses on linux when connected via putty.

When you login via putty then your TERM is set to ‘xterm’. You will not be able to see colors with ncurses.

Set TERM=’linux’ and you can now see the colors.

cc

Udgivet i Linux | Skriv en kommentar