cat /dev/zero | ssh username@remotehost "cat > /dev/null"
That caused 100% CPU loading on the Raspberry Pi. Throughput is about 6MB per second.
cat /dev/zero | ssh username@remotehost "cat > /dev/null"
String s = "" + bd;
import java.util.HashMap; import java.util.Map; import java.util.Set; import java.util.List; import net.sourceforge.pmd.lang.ast.Node; import net.sourceforge.pmd.lang.java.ast.ASTLocalVariableDeclaration; import net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceBodyDeclaration; import net.sourceforge.pmd.lang.java.ast.ASTFormalParameter; import net.sourceforge.pmd.lang.java.ast.ASTVariableDeclarator; import net.sourceforge.pmd.lang.java.ast.ASTType; import net.sourceforge.pmd.lang.java.ast.ASTLiteral; import net.sourceforge.pmd.lang.java.ast.ASTName; import net.sourceforge.pmd.lang.java.ast.ASTVariableDeclaratorId; import net.sourceforge.pmd.lang.java.ast.ASTAdditiveExpression; import net.sourceforge.pmd.lang.java.rule.AbstractJavaRule; import net.sourceforge.pmd.lang.java.symboltable.NameOccurrence; import net.sourceforge.pmd.util.CollectionUtil; /** * */ public class ScanBigDecimal extends AbstractJavaRule { /** * These are the BigDecimal methods */ private static final Set<String> BIG_DECIMAL_METHODS = CollectionUtil.asSet(new String[] { ".toString" }); /** * These are the classes that the rule can apply to */ private static final Map<String, Set<String>> MAP_CLASSES = new HashMap<String, Set<String>>(); static { MAP_CLASSES.put("java.math.BigDecimal", BIG_DECIMAL_METHODS); MAP_CLASSES.put("BigDecimal", BIG_DECIMAL_METHODS); } @Override public Object visit(ASTLocalVariableDeclaration node, Object data) { ASTVariableDeclaratorId var = getDeclaration(node); if (var == null) { return super.visit(node, data); } String variableName = var.getImage(); for (NameOccurrence no: var.getUsages()) { // FIXME - getUsages will return everything with the same name as the variable, // see JUnit test, case 6. Changing to Node below, revisit when getUsages is fixed Node sn = no.getLocation(); Node primaryExpression = sn.jjtGetParent().jjtGetParent(); Class<? extends Node> parentClass = primaryExpression.jjtGetParent().getClass(); // see if we are calling the methods we are interested in String methodCall = sn.getImage().substring(variableName.length()); ASTType nodeType = node.getTypeNode(); if (nodeType != null && MAP_CLASSES.get(nodeType.getTypeImage()).contains(methodCall)) { addViolation(data, sn); } } return super.visit(node, data); } @Override public Object visit(ASTAdditiveExpression node, Object data) { boolean hasLiteral = true; boolean hasClass = false; if (node == null) { return super.visit(node, data); } for (int i = 0; i < node.jjtGetNumChildren(); i++) { Node child = node.jjtGetChild(i); if (child.hasDescendantOfType(ASTLiteral.class)) { hasLiteral = true; } else { ASTName nameNode = (ASTName)child.getFirstDescendantOfType(ASTName.class); if (nameNode != null && findDeclaration(node, nameNode.getImage()) != null) { hasClass = true; } } if (hasLiteral && hasClass) { addViolation(data, node); break; } } return super.visit(node, data); } /** * This method checks the variable declaration if it is on a class we care * about. If it is, it returns the DeclaratorId * * @param node * The ASTLocalVariableDeclaration which is a problem * @return ASTVariableDeclaratorId */ private ASTVariableDeclaratorId getDeclaration(ASTLocalVariableDeclaration node) { ASTType type = node.getTypeNode(); if (MAP_CLASSES.keySet().contains(type.getTypeImage())) { return node.getFirstDescendantOfType(ASTVariableDeclaratorId.class); } return null; } private ASTVariableDeclaratorId findDeclaration(Node node, String varName) { if (node == null || varName == null) { return null; } Node parent = node.getFirstParentOfType(ASTClassOrInterfaceBodyDeclaration.class); if (parent != null) { List<ASTVariableDeclaratorId> list = parent.findDescendantsOfType(ASTVariableDeclaratorId.class); for (ASTVariableDeclaratorId declarator : list) { if (varName.equals(declarator.getImage())) { ASTType nodeType = null; if (declarator.jjtGetParent() instanceof ASTFormalParameter) { nodeType = ((ASTFormalParameter)(declarator.jjtGetParent())).getTypeNode(); } else if (declarator.jjtGetParent() instanceof ASTLocalVariableDeclaration) { nodeType = ((ASTLocalVariableDeclaration)(declarator.jjtGetParent())).getTypeNode(); } else if (declarator.jjtGetParent() instanceof ASTVariableDeclarator) { nodeType = ((ASTLocalVariableDeclaration)(declarator.jjtGetParent().jjtGetParent())).getTypeNode(); } else { System.err.println("Unknown type"); } if (nodeType != null && MAP_CLASSES.keySet().contains(nodeType.getTypeImage())) { return declarator; } } } } return null; } }
<?xml version="1.0"?> <ruleset name="My custom rules" xmlns="http://pmd.sourceforge.net/ruleset/2.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd" xsi:noNamespaceSchemaLocation="http://pmd.sourceforge.net/ruleset_2_0_0.xsd"> <rule name="ScanBigDecimal" message="Avoid using BigDecimal.toString or implicit casting to string" class="ScanBigDecimal"> <description> Avoid using BigDecimal.toString or implicit casting to string </description> <priority>3</priority> <example> <![CDATA[ } ]]> </example> </rule> </ruleset>
java -cp "C:/Users/clarence/Documents/MyApps/pmd-bin-5.0.0/lib/*";. net.sourceforge.pmd.PMD C:/Users/clarence/Documents/MyTest/pmd/MyTestCase.java text bigdecimal.xml
import java.math.BigDecimal; public class MyTestCase { public static void main(String args) { BigDecimal bd = new BigDecimal("12.345"); // will trigger error System.out.println("This is the number: " + bd); // this type can't be detected... System.out.println(bd); // will trigger error; String s = "" + bd; String s2 = "" + bd.toString(); String s3 = bd + ""; String s4 = bd + MyTestCase.returnStr(); // can't be detected String s5 = "" + returnBigDecimal("12.34"); System.err.println(returnString(bd)); // this wont trigger warning String s6 = "" + bd.toPlainString(); String s7 = "" + "a" + "b"; } private static String returnStr() { return "hello"; } private static String returnString(BigDecimal bd) { return "" + bd; } private static BigDecimal returnBigDecimal(String num) { return new BigDecimal(num); } }
config interface 'wan' option ifname 'eth0' option proto 'dhcp' config interface 'wifi' option proto 'static' option ipaddr '192.168.2.1' option netmask '255.255.255.0'
config wifi-iface option device radio0 option network wifi option mode ap option ssid put_your_wireless_ssid_here #option encryption none option encryption psk2 option key put_your_wireless_password_here
config dhcp wifi option interface wifi option start 100 option limit 150 option leasetime 12h
config zone option name wifi option input ACCEPT option output ACCEPT option forward REJECT config forwarding option src wifi option dest wan
ifup wifi wifi /etc/init.d/firewall restart /etc/init.d/dnsmasq restart
#!/bin/sh /bin/cp -f /etc/config/dhcp.ap /etc/config/dhcp /bin/cp -f /etc/config/firewall.ap /etc/config/firewall /bin/cp -f /etc/config/network.ap /etc/config/network /bin/cp -f /etc/config/wireless.ap /etc/config/wireless /bin/sync /sbin/ifup wifi /sbin/wifi /etc/init.d/firewall restart /etc/init.d/dnsmasq restart
#!/bin/sh /bin/cp -f /etc/config/dhcp.router /etc/config/dhcp /bin/cp -f /etc/config/firewall.router /etc/config/firewall /bin/cp -f /etc/config/network.router /etc/config/network /bin/cp -f /etc/config/wireless.router /etc/config/wireless /bin/sync /sbin/ifup wan /sbin/ifup wifi /sbin/wifi /etc/init.d/firewall restart /etc/init.d/dnsmasq restart
uci add system button uci set system.@button[-1].button=BTN_0 uci set system.@button[-1].action=released uci set system.@button[-1].handler="/sbin/sw_router_mode" uci commit system uci add system button uci set system.@button[-1].button=BTN_0 uci set system.@button[-1].action=pressed uci set system.@button[-1].handler="/sbin/sw_ap_mode" uci commit system
/usr/bin/sudo /bin/mount -t vfat -o uid=pi,gid=pi /dev/sda /mnt/usb/
# create an empty swapfile /bin/dd if=/dev/zero of=/mnt/usb/swapfile bs=1M count=512 # create a loop device /usr/bin/sudo /sbin/losetup /dev/loop0 /mnt/usb/swapfile # setup swap area /usr/bin/sudo /sbin/mkswap /dev/loop0 # enable the swap /usr/bin/sudo /sbin/swapon /dev/loop0
# disable swap /usr/bin/sudo /sbin/swapoff /dev/loop0 # delete loop /usr/bin/sudo /sbin/losetup -d /dev/loop0
/usr/bin/sudo /bin/umount /mnt/usb/
sudo aptitude update
sudo aptitude install firmware-atheros
cd /lib/firmware sudo wget http://linuxwireless.org/download/htc_fw/1.3/htc_9271.fw
sudo chmod 0600 /etc/network/interfaces
sudo vi /etc/network/interfaces
auto wlan0 allow-hotplug wlan0 iface wlan0 inet dhcp wireless-essid your-ssid wireless-key your-hex-key
sudo ifup wlan0