Tagged: code Toggle Comment Threads | Keyboard Shortcuts

  • John Cartwright 10:59 AM on January 18, 2017 Permalink | Reply
    Tags: , code, , spawn, tanks,   

    Easily spawn an enemy jet to patrol an AO in Arma 3 with a script. 

    This simple script will spawn a jet to patrol an AO and attack any enemy vehicle or helicopter it sees.

    // Spawn a CAS jet to patrol the AO.
    
    _plane = createVehicle ["O_Plane_CAS_02_F", getMarkerPos("plane"), [], 0, "FLY"];
    _pilotguy = [[26761.4,24593.4,0.000909805], EAST, ["O_Pilot_F"],[],[],[],[],[],232] call BIS_fnc_spawnGroup;
    
    ((units _pilotguy) select 0) moveInDriver _plane;
    _wpcas = _pilotguy addWaypoint [getMarkerPos("mkr1"), 0];
    _wpcas setWaypointBehaviour "SAFE";
    _wpcas setWaypointCombatMode "RED";
    _wpcas setWaypointCompletionRadius 1900;
    curator1 addCuratorEditableObjects [[_plane],true ];
    

    This spawns the jet in the air at the Molos airfield and it will move to the marker named mkr1 and patrol this area. Very useful indeed. Put this script into the initServer.sqf and this will work in your mission.

    Use the code below to spawn an OPFOR tank platoon to patrol an AO. They will spawn at the salt flats and will then move to the object named man1.

    _randTanks90 = [[23762.7,18920.1,3.33786e-006] , 0, 400, 10, 0, 0.3, 0] call BIS_fnc_findSafePos;
    
    _newtanks29 = [_randTanks90, EAST, (configFile >> "CfgGroups" >> "EAST" >> "OPF_F" >> "Armored" >> "OIA_TankPlatoon")] call BIS_fnc_spawnGroup;
    
    [_newtanks29, man1 getRelPos [15, 0], 600] call bis_fnc_taskPatrol;
    

    Finally, this code will spawn an OPFOR Kajman that will fly to the HQ and then the crew will get out and shut down the chopper. The chopper will spawn at the onbject named heli99 and will move to the object named man1, then they will land and exit the vehicle.

    _randPos11 = [getPos heli99 , 0, 1200, 12, 0, 0.3, 0] call BIS_fnc_findSafePos;
    _heli1 = [_randPos11, 0, "O_Heli_Attack_02_F", EAST] call BIS_fnc_spawnVehicle;
    
    _group_ifrit1 = _heli1 select 2;
    _wp = _group_ifrit1 addWaypoint [getPosATL man1, 0];
    _wp setWaypointBehaviour "SAFE";
    _wp setWaypointCombatMode "GREEN";
    _wp setWaypointCompletionRadius 1300;
    _wp setWaypointSpeed "FULL";
    _wp setwaypointType "GETOUT";
    
    _group_ifrit1 = _heli1 select 2;
    _wp2 = _group_ifrit1 addWaypoint [getPosATL man1, 0];
    _wp2 setWaypointBehaviour "SAFE";
    _wp2 setWaypointCombatMode "GREEN";
    _wp2 setWaypointCompletionRadius 1300;
    _wp2 setWaypointSpeed "FULL";
    _wp2 setwaypointType "DISMISSED";
    

    Complete code to spawn a mission with a radio tower and a HQ. You just need a huge marker covering most of Altis named mkr1.

    // Find a random area to spawn the HQ. This is within the area of the marker "mkr1".
    
    _mrk = "mkr1";
    _area = markerSize _mrk;
    _nul = _area pushBack markerDir _mrk;
    _nul = _area pushBack ( markerShape _mrk isEqualTo "Rectangle" );
    _pos = [ _mrk, _area ] call BIS_fnc_randomPosTrigger;
    
    _randPos = [_pos , 0, 1200, 12, 0, 0.3, 0] call BIS_fnc_findSafePos;
    
    _cargo = "Land_Cargo_HQ_V1_F" createVehicle _randPos;
    
    _randPos14 = _cargo getRelPos [9, 12];
    
    _mg13 = createVehicle ["O_GMG_01_high_F", _randPos14, [], 0, "CAN_COLLIDE"];
    
    _mgguy13 = [_randPos14, EAST, ["O_Soldier_F"],[],[],[],[],[],232] call BIS_fnc_spawnGroup;
    
    ((units _mgguy13) select 0) moveInGunner _mg13;
    
    // Spawning the radio tower.
    
    _randPos2 = [_pos , 0, 1200, 10, 0, 0.3, 0] call BIS_fnc_findSafePos;
    
    _tower = "Land_TTowerBig_1_F" createVehicle _randPos2;
    _tower setVectorUp [0,0,1]; // Make sure the tower is not leaning.
    
    _towerbox = "Land_spp_Transformer_F" createVehicle _randPos2;
    _towerbox setVectorUp [0,0,1];
    
    _towerbox2 = "Land_TTowerSmall_1_F" createVehicle _randPos2;
    _towerbox2 setVectorUp [0,0,1];
    
    _tower setVehicleVarName "tower1"; tower1 = _tower;
    
    _genny = _tower getRelPos [7, 9];
    
    // Spawn a random minefield around the radio tower.
    // *********************************************************************
    
    _initialPos = getPos tower1; // Pos of tower.
    for "_count" from 1 to 50 do {
    	_minePos = [
    		(_initialPos select 0) + ((random 80) - 40),
    		(_initialPos select 1) + ((random 80) - 40)
    	];
    	_minen = createMine [
    		"APERSBoundingMine",
    		_minePos,
    		[],
    		0
    	];
    };
    
    // End mine code.
    // *********************************************************************
    
    _minefield = "Land_PowerGenerator_F" createVehicle _genny;
    
    // Spawning a MG guy near tower.
    
    _randPos3 = [_randPos2, 1, 60, 3, 0, 20, 0] call BIS_fnc_findSafePos;
    
    _mg = createVehicle ["O_HMG_01_high_F", _randPos3, [], 0, "CAN_COLLIDE"];
    
    _mgguy = [_randPos3, EAST, ["O_Soldier_F"],[],[],[],[],[],232] call BIS_fnc_spawnGroup;
    
    ((units _mgguy) select 0) moveInGunner _mg;
    
    
    // Spawning a couple of infantry groups to defend the HQ.
    // *********************************************************************
    
    _hqdef2 = _cargo getRelPos [-96, 256];
    
    _group = [_hqdef2, EAST, configfile >> "CfgGroups" >> "East" >> "OPF_F" >> "Infantry" >> "OIA_InfSquad_Weapons"] call BIS_fnc_spawnGroup;
    
    private _buildingPositions = _cargo buildingPos -1;
    private _buildingPosition = [0,0,0];
    if (!(_buildingPositions isEqualTo [])) then {
        {
            if (_buildingPositions isEqualTo []) exitWith {};
            _buildingPosition = selectRandom _buildingPositions;
            _x setPos _buildingPosition;
    		_x disableAI 'PATH';
            _buildingPositions deleteAt (_buildingPositions find _buildingPosition);
        } forEach (units _group);
    };
    
    _randPos99 = [_pos , 0, 1200, 12, 0, 0.3, 0] call BIS_fnc_findSafePos;
    
    _towerhq = "CamoNet_OPFOR_big_Curator_F" createVehicle _randPos99;
    _towerSTUFF = "Box_East_Grenades_F" createVehicle _randPos99;
    _ammo1 = _towerSTUFF getRelPos [2, 2];
    box1 = "O_supplyCrate_F" createVehicle _ammo1;
    
    _ammo2 = _towerSTUFF getRelPos [-2, 2];
    box2 = "Box_East_WpsLaunch_F" createVehicle _ammo1;
    
    _ammo3 = _towerSTUFF getRelPos [3, 2];
    box3 = "Box_East_Ammo_F" createVehicle _ammo1;
    
    _ammo4 = _towerSTUFF getRelPos [3, 4];
    box4 = "Box_East_Wps_F" createVehicle _ammo1;
    
    _hqdef3 = _towerhq getRelPos [16, 23];
    
    _group99 = [_hqdef3, EAST, configfile >> "CfgGroups" >> "East" >> "OPF_T_F" >> "Infantry" >> "OIA_InfSquad_Weapons"] call BIS_fnc_spawnGroup;
    
    [_group99, getPos _towerhq, 300] call bis_fnc_taskPatrol;
    
    _officer = _group createUnit ["O_officer_F",_randPos3,[],0.6,"Colonel"];
    _officer setVehicleVarName "man1"; man1 = _officer;
    man1 setpos (_cargo buildingpos 1);
    _officer disableAI 'PATH';
    
    // *********************************************************************
    
    //Spawn the group
    private "_group2";
    _group2 = [_randPos3, EAST, configfile >> "CfgGroups" >> "East" >> "OPF_T_F" >> "Infantry" >> "OIA_InfSquad_Weapons"] call BIS_fnc_spawnGroup;
    
    //Make the group defend the area.
    
    [_group2, _randPos] call bis_fnc_taskDefend;
    
     
  • John Cartwright 9:15 AM on July 11, 2016 Permalink | Reply
    Tags: , code, , ,   

    Original Apollo 11 Guidance Computer (AGC) source code posted on github. 

    The original ASM source code for the lunar command and landing modules has been posted on Github. This gives us an insight into how it all worked. I wonder if someone could compile this code and get it working or not. I guess it would require the same hardware as was used in the 1960`s. This code was digitized from images of the original hardcopy source code from NASA. Here is a sample of the code.

    TIG-35		CAF	5SEC
    		TC	TWIDDLE
    		ADRES	TIG-30
     
    		TC	PHASCHNG
    		OCT	40154		# 4.15SPOT FOR TIG-30 RESTART
     
    		CS	BLANKDEX	# BLANK DSKY FOR 5 SECONDS
    		TS	DISPDEX
     
    		INDEX	WHICH
    		CS	6		# CHECK ULLAGE TIME.
    		EXTEND
    		BZMF	TASKOVER
    		CAF	4.9SEC		# SET UP TASK TO RESTORE DISPLAY AT TIG-30
    		TC	TWIDDLE
    		ADRES	TIG-30.1
     
    		CAF	PRIO17		# A NEGATIVE ULLAGE TIME INDICATES P41, IN
    		TC	NOVAC		# WHICH CASE WE HAVE TO SET UP A JOB TO
    		EBANK=	TTOGO		# BLANK THE DSKY FOR FIVE SECONDS, SINCE
    		2CADR	P41BLANK	# CLOKJOB IS NOT RUNNING DURING P41.
     
    		TCF	TASKOVER

    This is very cool, after all of these years, to see some actual NASA source code released to the public. Actually, I am not sure that you could compile this and run it. Better to just read through it an learn how they did things in 1969. There are already 6 issues with the source code that need to be addressed. Better get on to that very soon. Check this out for yourself and see what you think: https://github.com/chrislgarry/Apollo-11. I personally think this is awesome. Code like this belongs in a museum. Along with many other artifacts from the Apollo moon landing. NASA themselves also have a Github account with many open-source applications available for download: https://github.com/nasa. Very open indeed. This is a good way to interact with the public. Give something to the open-source community and they will give you something back.

    This PDF contains information about the instruction set used by the Apollo guidance computer. This would be helpful if the reader wanted to compile this code. But an Apollo guidance computer cannot be purchased. Better to build your own.

    http://www.galaxiki.org/web/main/_blog/all/build-your-own-nasa-apollo-landing-computer-no-kidding.shtml.

     
  • John Cartwright 1:55 PM on April 26, 2016 Permalink | Reply
    Tags: code, , facepalm,   

    Fixed the PHP date code. 

    I have fixed my PHP date code, major facepalm when I had a default date hardcoded in the PHP…

    OCP facepalm.

    OCP facepalm.

    Should be all good now.

     
  • John Cartwright 11:21 PM on August 5, 2015 Permalink | Reply
    Tags: , code, , ,   

    Useful C tricks and code samples. 

    How to define a string and print it out with the printf() function.

    #include <stdio.h>
     
    /* Defining a global string. */
     
    #define hi "Hello Sire."
     
    int main(void)
    {
       /* Printing out the string. */
       printf("%s\n", hi);
     
       return 0;
    }

    How to run the /bin/sh executable with some C code.

    #include <stdlib.h>
    #include <unistd.h>
     
    int main(void)
    {
            execve("/bin/sh", NULL, NULL);
            return 0;
    }

    When no parameters are passed to a C program, display a menu.

    	if (!argc || !argv[1]) {
    		char *myarg;
    		myarg = argv[0];
    		printf("%s Usage:\n--datetime - Date & Time.\x2e\n" \
    		"--uname1 - Kernel Information\x2e\n" \
    		"--uname2 - Information on memory & processes\x2e\n" \
    		"--fortune - View a fortune cookie.\x2e\n" \
    		"--about - The Readme for this program\x2e\n\n" \
    		, myarg);
    	}

    Print the current time and date.

    void DateTime()
    {
    	struct tm *ptr;
    	time_t tm;
    	char str[60];
    	tm = time(NULL);
    	ptr = localtime(&tm);
    	strftime(str, 100, "%A %d %B %Y. %H:%M:%S %Z.", ptr);
    	printf("\n\n%s\n\n", str);
    }

    How to define and use a function as well as getting input from the console.

    #include <stdio.h>
    #include <string.h>
     
    #define MSG "World"
     
    int goku(void) {
    	printf("Hello %s.\n", MSG);
    	return 1;
    }
     
    int main(int argc, char **argv) {
     
    	char *name;
     
    	name = argv[1];
     
    	if (strlen(name) < 5) {
    		printf("Name too short.\n");
    	}
    	goku();
    	printf("%s\n", name);
    	return 0;
    }

    Here is a simple C program for printing a verbose time and date.

    #include 	/* For time function (random seed). */
    #include       /* For extra functions. printf().   */
    #include      /* For getenv();                    */
     
    #define format "The time and date is: %A %d %B %Y. The time is: %H:%M:%S, %Z."
     
    int print_time(void) {
    	struct tm *ptr;
    	time_t tm;
    	char length[60];
    	tm = time(NULL);
    	ptr = localtime(&tm);
    	strftime(length, 100, format, ptr);
    	printf("%s\n", length);
    }
     
    int main(void)
    {
    	print_time();
    	return 0;
    }

    Simple Hello World program.

    int main() {
    	write(1, "Hello World\n", 14);
    }
     
  • John Cartwright 12:17 PM on June 10, 2015 Permalink | Reply
    Tags: code, , ,   

    Examining a piece of Linux malware with Kali Linux tools. 

    I have recently downloaded an executable, this is a piece of Linux malware. I run a query with strings on this file and I find out that this file makes changes to various utility commands on a Linux system such as netstat, ps, top and /bin/sh. This would be all the hallmarks of a rootkit executable. This is a rare find, malware intended for a Linux machine. But this is a chance to see this for once. I am not sure if I can run this executable without it doing damage. I wish there was a sandbox environment where I could run it and see what it does when executing. The strace command would be very good for this, even though there are no debugging symbols in the executable. Cuckoo Sandbox allows analysis of malware in a safe environment. This could be a good way to find out exactly what this executable does. I have found an installation guide here: https://www.proteansec.com/linux/installing-using-cuckoo-malware-analysis-sandbox/. I have decompiled the executable using this website: https://retdec.com/ and this is the result, a gzipped file containing the source code.

    This section is interesting. This shows a list of all the Linux binaries targeted by this executable.

    char * g15[12] = {
        "/bin/netstat",
        "/bin/lsof",
        "/bin/ps",
        "/bin/ss",
        "/usr/bin/netstat",
        "/usr/bin/lsof",
        "/usr/bin/ps",
        "/usr/bin/ss",
        "/usr/sbin/netstat",
        "/usr/sbin/lsof",
        "/usr/sbin/ps",
        "/usr/sbin/ss"
    }; // 0x8131cc0

    And this is a huge list of IP addresses…

    char * g13[113] = {
        "61.132.163.68",
        "202.102.192.68",
        "202.102.213.68",
        "202.102.200.101",
        "58.242.2.2",
        "202.38.64.1",
        "211.91.88.129",
        "211.138.180.2",
        "218.104.78.2",
        "202.102.199.68",
        "202.175.3.3",
        "202.175.3.8",
        "202.112.144.30",
        "61.233.9.9",
        "61.233.9.61",
        "124.207.160.110",
        "202.97.7.6",
        "202.97.7.17",
        "202.106.0.20",
        "202.106.46.151",
        "202.106.195.68",
        "202.106.196.115",
        "202.106.196.212",
        "202.106.196.228",
        "202.106.196.230",
        "202.106.196.232",
        "202.106.196.237",
        "202.112.112.10",
        "211.136.17.107",
        "211.136.28.231",
        "211.136.28.234",
        "211.136.28.237",
        "211.147.6.3",
        "219.141.136.10",
        "219.141.140.10",
        "219.141.148.37",
        "219.141.148.39",
        "219.239.26.42",
        "221.130.32.100",
        "221.130.32.103",
        "221.130.32.106",
        "221.130.32.109",
        "221.130.33.52",
        "221.130.33.60",
        "221.176.3.70",
        "221.176.3.73",
        "221.176.3.76",
        "221.176.3.79",
        "221.176.3.83",
        "221.176.3.85",
        "221.176.4.6",
        "221.176.4.9",
        "221.176.4.12",
        "221.176.4.15",
        "221.176.4.18",
        "221.176.4.21",
        "58.22.96.66",
        "218.104.128.106",
        "202.101.98.55",
        "211.138.145.194",
        "211.138.151.161",
        "211.138.156.66",
        "218.85.152.99",
        "218.85.157.99",
        "222.47.29.93",
        "202.101.107.85",
        "119.233.255.228",
        "222.47.62.142",
        "122.72.33.240",
        "211.98.121.27",
        "218.203.160.194",
        "221.7.34.10",
        "61.235.70.98",
        "113.111.211.22",
        "202.96.128.68",
        "202.96.128.86",
        "202.96.128.166",
        "210.21.3.140",
        "210.21.4.130",
        "211.95.193.97",
        "211.98.2.4",
        "211.98.4.1",
        "211.162.61.225",
        "211.162.61.235",
        "211.162.61.255",
        "211.162.62.1",
        "211.162.62.60",
        "221.4.66.66",
        "202.103.176.22",
        "202.96.144.47",
        "210.38.192.33",
        "202.96.134.33",
        "202.96.134.133",
        "202.96.154.15",
        "210.21.196.6",
        "221.5.88.88",
        "202.103.243.112",
        "202.193.64.33",
        "61.235.164.13",
        "61.235.164.18",
        "202.103.225.68",
        "221.7.136.68",
        "202.103.224.68",
        "211.97.64.129",
        "211.138.240.100",
        "211.138.242.18",
        "211.138.245.180",
        "221.7.128.68",
        "222.52.118.162",
        "202.98.192.67",
        "202.98.198.167",
        "211.92.136.81",
        "211.139.1.3"
    }; // 0x8131760

    This program might phone home or join your computer to a botnet. Anyway, As well as creating many new processes on your machine that perform all sorts of evil things to your computer and the network. I have found an example of a person that was owned by this rootkit and their machine was taken over. if you find this executable on the Internet do not run it. But it is fun to play with and learn about Linux rootkits though. The source code I have posted is decompiled source and may not even compile on your machine. I just posted it for interests sake.

     
  • John Cartwright 10:43 AM on May 15, 2015 Permalink | Reply
    Tags: , code, ,   

    A simple C code snippet that shows how to do a function call. 

    This simple C code snippet shows how to do a function call in C. This calls the hi() function and runs it in main(). Very simple but useful code. And this does not need to call any include files. As I am using the built-in write() function.

    int hi()
    {
            int i;
            i = 0;
     
            write(1, "Hi.\n", 5);
     
            while (i < 8) {
                    system("echo 'This is a loop.'");
                    i++;
            }
    }
     
    int main(int argc, char** argv)
    {
            write(1, "Hello World\n", 15);
            hi();
     
            return 0;
    }
     
  • John Cartwright 2:11 AM on January 13, 2015 Permalink | Reply
    Tags: , code, , ,   

    C code that will open a file and print the contents to the terminal. 

    This code will print the contents of a file to the terminal. Feel free to use this in your own projects if you wish.

    #include <stdio.h>
     
    #define MEM "/proc/meminfo"
     
    int main (void) {
     
    	FILE *g;
    	char Meminfo[40];
    	g = fopen(MEM, "r");
    	if(!g) {
    		printf ("Sorry, I cannot" \
    			"open: %s.\n", MEM);
    	} else {
    		while (feof(g) != 1) {
    			fgets(Meminfo, 2, g);
    				printf("%s", Meminfo );
    		}
    		fflush(stdout);
    	}
    	fclose(g);
    }

    This code is very fast and useful for opening a text file and reading the contents.

     
  • John Cartwright 10:11 PM on January 5, 2015 Permalink | Reply
    Tags: code, , , stealth   

    Stealth Linux code that can run on a machine and open a port invisibly. 

    This code that I found: http://paste.scratchbook.ch/view/6f74b58f can run on a Linux machine and open a port invisibly. This allows access to a Linux server without the process showing in process manager and on a port scan of the machine. This might be controversial thing to post on a Linux focused website, but this might be interesting to someone that is in to network security and penetration testing of a Linux server. This would be an interesting challenge. Defeating this code would be a good way to secure a Linux server. I am not sure if NSA Selinux can guard against this code but this is a good example of stealth code. There will be no open port shown in a scan as there is no service listening. But the system will respond to certain SYN packets transmitted to the target system and then the port(s) will be open as required. This code could be detected on a machine, but naming the binary to something innocuous like ‘top’ would make it pass a casual inspection. This is used on Windows to run malicious code without the user seeing it as something unwanted running as a process.

    So, check this code out and see how you get on testing this program.

     
  • John Cartwright 2:15 PM on October 12, 2013 Permalink | Reply
    Tags: code, , ,   

    My sysinfo program updated with new code. Even better than before! 

    http://www.securitronlinux.com/files/sysinfo.kdevelop-1.0.tar.gz.

    This is the link to my newly updated sysinfo program. This has code added using the sysinfo struct. This means that the memory and uptime information that is output is actually readable now. This is what the output of the memory and uptime section looks like now.

    [email protected]:~/Documents/sysinfo.kdevelop-1.0$ ./sysinfo 2
    		Ram & swap information.
    Filename				Type		Size	Used	Priority
    /dev/sdb2                               partition	12287996	0	-1
    /dev/sdb5                               partition	2559996	0	-2
    
    System uptime : 0 days, 2:23:45
    Total RAM   : 5900.9 MB
    Free RAM   : 147.0 MB
    Number of running processes : 368
    

    Stackoverflow has been a great help in terms of getting this code to work.

    Here is the code section in question. This outputs much more readable output. A great result.

    	if (argc > 1 and strncmp(argv[1], "2", BUF) == 0) {
    		printf("\t\tRam & swap information.\n");
    		kernel("/proc/swaps", 2);
    
    		/* This code from:
    		 * http://stackoverflow.com/questions/14345937/sysinfo-returns-incorrect-value-for-freeram-even-with-mem-unit
    		 */
    		/* Conversion constants. */
    		const long minute = 60;
    		const long hour = minute * 60;
    		const long day = hour * 24;
    		const double megabyte = 1024 * 1024;
    
    		/* Obtain system statistics. */
    		struct sysinfo si;
    		sysinfo (&si);
    
    		/* Summarize interesting values. */
    		printf ("System uptime : %ld days, %ld:%02ld:%02ld\n", 
    		    si.uptime / day, (si.uptime % day) / hour, 
    		    (si.uptime % hour) / minute, si.uptime % minute);
    		printf ("Total RAM   : %5.1f MB\n", si.totalram / megabyte);
    		printf ("Free RAM   : %5.1f MB\n", si.freeram / megabyte);
    		printf ("Number of running processes : %d\n", si.procs);
    
    
    	}
    
     
  • John Cartwright 11:00 AM on September 4, 2013 Permalink | Reply
    Tags: , code, render, spiral   

    A nice sample of code that will render a spiral on your terminal screen. This could be useful indeed. 

    This code sample will render a spiral on your terminal when you compile and execute it. Very interesting indeed.

    #include <sstream>
    #include <iostream>
    #include <string>
    
    std::string rle =
    "32 [email protected] 1n16 [email protected] [email protected] 1n13 [email protected] [email protected] [email protected] 1n10 [email protected] [email protected] [email protected] 1n7 [email protected] [email protected] [email protected] "
    "1n6 [email protected] [email protected] [email protected] [email protected] 1n4 [email protected] [email protected] [email protected] [email protected] [email protected] 1n3 [email protected] [email protected] [email protected] [email protected] [email protected] 1n3 "
    "[email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected]"
    "1 [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] "
    "[email protected] [email protected] [email protected] 1n3 [email protected] [email protected] [email protected] [email protected] 1n3 [email protected] [email protected] [email protected] [email protected] 1n4 [email protected] [email protected] [email protected] [email protected] 1"
    "n6 [email protected] [email protected] [email protected] [email protected] 1n7 [email protected] [email protected] [email protected] 1n9 [email protected] [email protected] 1n12 [email protected] [email protected] 1n16 [email protected] 4@"
    "16 1n22 [email protected] 1n";
    
    int main()
    {
    	std::stringstream ss(rle);
    	while (!ss.eof())
    	{
    		int n = 0;
    		while (ss.peek() >= '0' && ss.peek() <= '9')
    		n = n * 10 + ss.get() - '0';
    		char c = ss.get();
    		while (0 < n--)
    			std::cout << (c != 'n' ? c : 'n');
    		}
    }
    
     
  • John Cartwright 9:24 PM on August 29, 2013 Permalink | Reply
    Tags: , code, , , sign, tick   

    Very cool code that prints a tick sign in asterisks. This is awesome C++ code. 

    This code prints out a tick sign using asterisks. I tested this code on Fedora 19 and gcc 4.8 and it compiles without any problems.

    #include <iostream>
    #include <iomanip>
    
    using std::cout;
    
    int main() {
    
    	cout<<std::setw(8)<<"*"<<"n";
    	cout<<std::setw(7)<<"*"<<"n";
    	cout<<std::setw(6)<<"*"<<"n";
    
    	cout<<"*  *"<<"n"<<"* *"<<"n"<<"*";
    	cout<< "n";
    
    	return 0;
    }
    

    This is what you should get when you compile and run this code sample.

    [email protected] $ ./loop 
           *
          *
         *
    *  *
    * *
    *
    

    Very cool indeed.

     
  • John Cartwright 9:45 PM on July 22, 2013 Permalink | Reply
    Tags: code, packets, , , ,   

    Useful code snippets and commands for Linux. 

    Alternatives to the ping and traceroute commands on a Linux system.

    There are many alternatives to the ping and traceroute commands on a Linux system. The mtr command is one of them. This command will trace the route the network packets are taking to the target IP address.

    bash 06:42:02 Mon Jul 22 [[email protected] $ mtr 8.8.8.8

    This code will ping a server and use tcp, udp, icmp, stream, and syn packets to do so. This is useful to see if a server is up, but they block icmp packets, this script will work regardless of this and still allow you to see if the server is up or not. Good if you are behind a proxy at a college or something like that. There is also a tcpping command for Linux that can work when you are behind a restrictive firewall. There is some information about this here: http://xmodulo.com/2013/01/how-to-install-tcpping-on-linux.html.

    #!/usr/bin/perl
    
    use warnings;
    use strict;
    
    use Net::Ping;
    
    # code source: http://www.perlmonks.org/?node_id=943892
    # More: http://stackoverflow.com/questions/3960595/how-can-i-ping-a-host-with-a-perl-one-liner-with-netping
    
    #$| = 1;
    print "Please type a host to check: -:\n";
    my $host = <>; #Reading input from STDIN.
    
    if (length($host) < 3) {
        print "You did not type a host!\n";
        exit(0);
    }
    
    my @proto = ("tcp", "udp", "icmp", "stream", "syn");
    
    foreach my $pro ( @proto ) {
        print "#-Protocol $pro \n";
        my $p = Net::Ping->new($pro);
        chomp($host);
        # Specify source interface of pings
        print "$host is ";
        print "NOT " unless $p->ping($host, 2);
        print "reachable.\n";
        $p->close();
    }
    
    exit(0);

    This is a good alternative for tracing the route taken from one host to another.

    [email protected] ~ % sudo tcptraceroute 127.0.0.1
    [sudo] password for homer: 
    traceroute to 127.0.0.1 (127.0.0.1), 30 hops max, 60 byte packets
     1  localhost (127.0.0.1) <syn,ack>  0.031 ms  0.004 ms  0.005 ms

    This is how to ping the TCP port of a remote host. This is using the netcat tool.

    [email protected] ~ % nc -zvv yahoo.cn 80
    Connection to yahoo.cn 80 port [tcp/http] succeeded!

    The hping3 command on Linux Mint 15 is very useful for sending TCP packets to a remote host to test the configuration of the server.

    Type this command to install this utility: sudo apt-get install hping3.

    And this is the output you get when you are pinging the Yahoo website with hping3.

    bash 09:32:38 Mon Jul 22 [[email protected] $ sudo hping3 -S -p 80 yahoo.com
    HPING yahoo.com (eth1 206.190.36.45): S set, 40 headers + 0 data bytes
    len=46 ip=206.190.36.45 ttl=112 id=51335 sport=80 flags=SA seq=0 win=8192 rtt=208.4 ms
    len=46 ip=206.190.36.45 ttl=110 id=53804 sport=80 flags=SA seq=1 win=8192 rtt=197.2 ms
    len=46 ip=206.190.36.45 ttl=110 id=56362 sport=80 flags=SA seq=2 win=8192 rtt=211.5 ms
    len=46 ip=206.190.36.45 ttl=110 id=58939 sport=80 flags=SA seq=3 win=8192 rtt=211.0 ms
    len=46 ip=206.190.36.45 ttl=110 id=61474 sport=80 flags=SA seq=4 win=8192 rtt=197.5 ms
    len=46 ip=206.190.36.45 ttl=112 id=64019 sport=80 flags=SA seq=5 win=8192 rtt=195.7 ms
    len=46 ip=206.190.36.45 ttl=112 id=998 sport=80 flags=SA seq=6 win=8192 rtt=194.8 ms
    len=46 ip=206.190.36.45 ttl=112 id=3556 sport=80 flags=SA seq=7 win=8192 rtt=210.2 ms
    len=46 ip=206.190.36.45 ttl=112 id=6243 sport=80 flags=SA seq=8 win=8192 rtt=210.6 ms
    len=46 ip=206.190.36.45 ttl=110 id=8839 sport=80 flags=SA seq=9 win=8192 rtt=197.2 ms
    ^C
    --- yahoo.com hping statistic ---
    10 packets transmitted, 10 packets received, 0% packet loss
    round-trip min/avg/max = 194.8/203.4/211.5 ms
    Ralph using a computer.

    Ralph using a computer.

     
  • John Cartwright 7:00 PM on September 9, 2012 Permalink | Reply
    Tags: , code, , , , , wrap   

    Wrapping the printf() statement onto multiple lines in C and some other useful samples. 

    This code sample shows how we are wrapping a printf() statement onto multiple lines using backslashes.

    #include "stdio.h"
    
    #define hello "Hello World."
    
    int main(int argc, char* argv[])
    {
    	printf("This is a very long sentence we are handing down\n"\
    		   "Mr smith, do you have anything to say for yourself"\
    		   "?");
    
    	printf("%s\n", hello);
    
    	return 0;
    }
    

    This is the most obfuscated version of the C “Hello World” program that I could find.

    #include 
    
    #define e 3
    #define g (e/e)
    #define h ((g+e)/2)
    #define f (e-g-h)
    #define j (e*e-g)
    #define k (j-h)
    #define l(x) tab2[x]/h
    #define m(n,a) ((n&(a))==(a))
    
    long tab1[] = { 989L, 5L, 26L, 0L, 88319L, 123L, 0L, 9367L };
    int tab2[] = { 4, 6, 10, 14, 22, 26, 34, 38, 46, 58, 62, 74, 82, 86 };
    
    main(m1, s)
    char *s;
    {
    	int a, b, c, d, o[k], n = (int)s;
    	if (m1 == 1) {
    		char b[2 * j + f - g];
    		main(l(h + e) + h + e, b);
    		printf(b);
    	} else
    		switch (m1 -= h) {
    		case f:
    			a = (b = (c = (d = g) << g) << g) << g;
    			return (m(n, a | c) | m(n, b) | m(n, a | d) |
    				m(n, c | d));
    		case h:
    			for (a = f; a < j; ++a)
    				if (tab1[a] && !(tab1[a] % ((long)l(n))))
    					return (a);
    		case g:
    			if (n < h)
    				return (g);
    			if (n < j) {
    				n -= g;
    				c = 'D';
    				o[f] = h;
    				o[g] = f;
    			} else {
    				c = '\r' - '\b';
    				n -= j - g;
    				o[f] = o[g] = g;
    			}
    			if ((b = n) >= e)
    				for (b = g << g; b < n; ++b)
    					o[b] = o[b - h] + o[b - g] + c;
    			return (o[b - g] % n + k - h);
    		default:
    			if (m1 -= e)
    				main(m1 - g + e + h, s + g);
    			else
    				*(s + g) = f;
    			for (*s = a = f; a < e;)
    				*s = (*s << e) | main(h + a++, (char *)m1);
    		}
    }
    

    This is a program that writes to a text file. You are of course free to use this code in your own projects.

    #include 
    #include 
    
    #define EQ ==
    #define log "hello.txt"
    
    int main(int argc, char *argv[]) {
    
    	int x;
    
    	x = 0;
    
    	FILE *f;
    	char Kyo[40];
    	int Fsize;
    	f = fopen(log, "w");
    	Fsize = sizeof(f);
    	if(!f) {
    		printf("Sorry, I cannot open: %s.\n", log);
    		exit(1);
    	} else {
    
    		while (x < 100) {
    			fprintf(log,"*");
    			if (x EQ 50) {
    				fprintf(log,"-\n-");
    			}
    		x++;
    
    		}
    		fprintf(log, "\n\x78*----* Done. *----*\x78\n");
    	}
    	fclose(f);
    
    	return 0;
    }
    
     
  • John Cartwright 9:09 PM on August 28, 2012 Permalink | Reply
    Tags: code, , , loops, , , , , writing   

    Miscellaneous Perl programming information. How to use for loops and printing HTML properly. 

    Opening a folder and listing the contents, and not listing certain files. This is the Perl code I was using on my very old Tripod.com website.

    opendir(DNAME, "$folder") || die "I cannot open the requested directory $folder \n $!";
    @dirfiles2 = readdir (DNAME);
    @dirfiles2 = sort(@dirfiles2);
    foreach $x2 (@dirfiles2) {
        if ($x2 eq ".") {
    	$x2 = ' ';
        }
        if ($x2 eq "..") {
    	$x2 = ' ';
        }
        if ($x2 =~ /REMOVED/) {
    	$x2 = ' ';
        }
        if ($x2 eq ".cgiclean") { # What is this?
    	$x2 = ' ' ;
        }
        if ($x2 eq ".htaccess") {
    	$x2 = ' ';
        }
        if ($x2 eq "$archive") {
    	print "\n";
        } else {
    # Simple hack to weed out those annoying zero length() strings...
    	if (length $x2 > 3) {
    	    print "\n";
    	}
        }
    }
    
    closedir(DNAME);
    

    How to get the date and time with Perl scripting. All you need to do is print “$date”; and you are done.

    my @Days = ('Sunday','Monday','Tuesday',
    	    'Wednesday','Thursday','Friday',
    	    'Saturday');
    my @Mon1 = ('January','February','March',
    	    'April','May','June',
    	    'July','August','September',
    	    'October','November','December');
    
    my ($Sec,$Min,$Hour,$MDay,$Mon,$Year,$WkDay) = (localtime)[0,1,2,3,4,5,6];
    $Year += 1900;
    if($Sec < 10) {
        $Sec = "0$Sec"
    };
    if($Min < 10) {
        $Min = "0$Min"
    };
    if($Hour < 10) {
        $Hour = "0$Hour"
    };
    
    $date = "$Hour:$Min:$Sec - $Days[$WkDay] $MDay $Mon1[$Mon] $Year";
    

    Here is an example showing how to do a for() loop in Perl.

    for ( $i=  0; $i <  32; $i++) {
    	print "*";
    }
    

    This comprehensive script will print a HTML page to the terminal when you run it. This is a good starter for writing a CGI script that will print out its own HTML. This is using the CGI.pm module. This also sets a cookie containing the date that expires in 3 days.

    #!/usr/bin/perl
    
    use CGI qw/:standard -nosticky/;
    my $query = new CGI;
    
    print $query->header(-type=>'text/html',
    		     -expires=>'+3d',
    		     -cookie=>$date,
    		     -charset=>'UTF-8');
    
    print $query->start_html(-title=>'CGI Viewblog CGI Script.',
    			 -meta=>{'keywords'=>'Blog Doom2 Level Editing Linux Doom',
    				 'copyright'=>'Copyright 2004 John Cartwright.',
    				 'definition'=>'General Viewblog Script.',
    				 'Appeal'=>'Wide',
    				 'description'=>'CGI Viewblog Script.'},
    			 -BGCOLOR=>'#FFFFFF',
    			 -TEXT=>'#000000',
    			 -LINK=>'#888fff');
    
    print $query->h1("CGI HTML Script.\n");
    
    print $query->p("This script prints HTML to the terminal.\n");
    
    print $query->end_html;
    

    Finally, this code will write some information to a log file.

    open FILE, ">> log.txt" || die "I cannot open the file: log.txt:\n $!\n";
    print FILE "Visited: $date\n";
    if ($user_ref) {
        print FILE "Referrer URL: $user_ref.\n";
    }
    print FILE "Users Browser: $user_agent.--\n\n";
    close FILE;
    
     
  • John Cartwright 7:57 PM on May 11, 2012 Permalink | Reply
    Tags: , code, , , , snprintf   

    Useful old C code of mine. Might be useful for reference. 

    This is a nice little program I wrote ages ago.

    /*
    * This program is free software; you can redistribute it and/or modify
    * it under the terms of the GNU General Public License as published by
    * the Free Software Foundation; either version 2 of the License, or
    * (at your option) any later version.
    *
    * This program is distributed in the hope that it will be useful,
    * but WITHOUT ANY WARRANTY; without even the implied warranty of
    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    * GNU General Public License for more details.
    *
    * You should have received a copy of the GNU General Public License
    * along with this program; if not, write to the Free Software
    * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
    */
    
    /********************************************************************
    * Description:
    * Author:  
    * Created at: Wed Jan 19 13:06:21 EST 2011
    * Computer: myhost
    * System: Linux 2.6.33-ARCH on x86_64
    *
    * Copyright (c) 2011   All rights reserved.
    *
    ********************************************************************/
    
    #include 
    #include 
    
    #define format "At this time: %H:%M:%S"
    #define text "OP is a Troll."
    
    int lineofstars (void) {
    	int x = 0;
    	while (x < 64) {
    		printf("*");
    		x++;
    		if (x == 31) {
    			printf("<|>");
    		} else if (x == 64) {
    			printf("\n-\n");
    		}
    	}
    	return 0;
    }
    
    int main (int argc, char** argv) {
    
    	lineofstars();
    
    	char *File;
    	char String[60];
    	struct tm *ptr;
    	time_t tm;
    	char length[60];
    
    	tm = time(NULL);
    	ptr = localtime(&tm);
    	strftime(length, 100, format, ptr);
    
    	File = "log.txt";
    	snprintf(String, 100, "%s, %s\n", length, text);
    
    	FILE *f;
    	f = fopen (File, "a+");
    
    	if (!f) {
    		printf("Sorry, I cannot open the file %s.\n", File);
    		return 0;
    	}
    
    	fprintf(f, String);
    
    	fflush(stdout);
    	fclose(f);
    
    	return 0;
    }
    
     
  • John Cartwright 2:48 PM on May 3, 2012 Permalink | Reply
    Tags: , code, , , ,   

    Miscellaneous programming tricks with C. 

    This is a very simple Hello World program in C.

    int main() {
    	write(1, "Hello World\n", 14);
    }

    Counting how long a text string is.

    #include 
    #include 
    #define MSG "Hello Doctor, let's get back to the TARDIS!"
    int main() {
    int g;
    g = strlen(MSG);
    if (g < 1) {
    printf("The string is not very long!\n");
    } else {
    printf("The length of the string `MSG' is: %i characters.\n", g);
    }
    return 0;
    }

    Code sample to check for a certain argument to a C program. using strncmp() to read from the argv[1], which is the first argument to the C program and checking if it contains the value “2”. And the value BUF sets the maximum length of the string expected.

    if (argc > 1 and strncmp(argv[1], "2", BUF) == 0) {
    	printf("\t\tRam & swap information.\n");
    	kernel("/proc/swaps", 2);
    	printf("-Uptime: ");
    	kernel("/proc/uptime", 2);
    	kernel("/proc/meminfo", 2);
    }

    More code from my sysinfo C program that reads in files and processes them accordingly.

    #ifndef SYSINFO_H_
    #define SYSINFO_H_
    
    #define BUF 0x05
    
    /*
     * Function prototypes. Sexy... And unlike on the show `24', function
     * prototypes have nothing to to with hard disk sectors!
     */
    
    void kernel(char,int);
    
    /*
     *  @brief  /proc file opener
     *  @param  File  An output stream.
     *  @param  len  A string length.
     *  @return  none.
     *  @pre  @a len must be a non-NULL int.
     * I hope this little function is not offending anyone. it is the only
     * way I could think to have a single function that would be able to 
     * load the different files quickly and without fuss. And it works just
     * fine, and that is what matters in the end.
     */
    
    struct _kern1 {
    	char *File;
    	int len;
    	char Kyo[40];
    } *kern1 = (struct _kern1 *) 0x80;
    
    void kernel(const char *File, int len)
    {
    	FILE *f;
    	char Kyo[40];
    
    	if (len > 10 or len < 2)
    		return;
    
    	f = fopen(File, "r");
    	if(!f) {
    		printf ("Sorry, I cannot open: %s.\n", File);
    		printf("Please check your permissions with\n"		\
    			"your supervisor. The feature may not\n"	\
    			"be compiled and\\or enabled in your\n"		\
    			"kernel version. Or a scsi device, eg,\n"	\
    			"a USB drive may not be attached.\n");
    		return;
    	} else {
    /* Based on sample code from:
     * www.koders.com/c/fid84CFEFBF311605F963CB04E0F84A2F52A8120F33.aspx
     * Specifically the section on parsing the /proc/version.
     */
    		while (feof(f) != 1) {
    			fgets(Kyo, len, f);
    			if (strncmp(Kyo, "((", 1) == 0)
    				printf ("\n-");
    			if (strncmp(Kyo, "#", 1) == 0) {
    				printf ("\nVersion: #");
    			} else {
    /*
     * This function is fast, owing to this i feel. especially with gcc 
     * 4.3.2 & glibc 2.5+. it is faster than using: printf (Kyo);
     */
    				fprintf (stdout, "%s", Kyo);
    			}
    			fflush(stdout);
    		}
    	}
    	fclose(f);
    }
    
    #endif /* sysinfo.h */
     
  • John Cartwright 12:16 PM on March 20, 2012 Permalink | Reply
    Tags: 3.3, , angry, birds, code, , mainline   

    Linux kernel 3.3 released, including some Android code? 


    The Linux kernel 3.3 has been released and among other features that have been included, there is some code from Google Android included. This is an interesting development, this does not mean that you can run Angry Birds on a Debian or Linux Mint system, but this could lead to something cool in the future. The Linux kernel is a free kernel that makes up a free operating system called Linux. The whole operating system is sometimes called Linux, but Linux is only the kernel, you could build a UNIX operating system using the GNU Coreutils, gcc, and Xorg, but have a different kernel maybe one you developed with your own team of developers and then you could distribute that as something else. FreeBSD uses Coreutils, gcc and the same software available on Linux distributions like Ubuntu, but FreeBSD uses a different kernel and a different executable format. The FreeBSD kernel is available for Debian with Debian KFreeBSD, that is an interesting idea, I prefer the Linux kernel, the hardware support is pretty good now, the need for binary firmware will not go away anytime yet, but at least you have a reasonable expectancy that the WIFI dongle you have bought will work with Linux. Netgear is a good brand. I am having some problems with my Internet connection right now, but I am wanting to try Debian Stable again.

    The Linux kernel is truly a massive achievement, it would have cost a staggering, amount if a major corporation had developed the Linux kernel instead of a worldwide network of kernel hackers that have helped develop the Linux kernel and get this kernel to the state that is right now. There are many devices in the world that are running the Linux kernel including the Android operating system that is using the Linux kernel to provide a Linux powered operating system, as an alternative to Symbian and IOS. The Apple Macintosh operating system is built on top of the Darwin UNIX operating system kernel, the Darwin kernel is free to download, the interface and software placed on top of the underlying UNIX kernel is what you are actually paying for. I downloaded the Darwin operating system ISO, burned it to a DVD  and tried to boot it on a PC, but it would not boot, I just got an error. I guess that I need the expensive hardware to run the Darwin operating system, but I could just run OpenBSD  or FreeBSD if I wanted a UNIX operating system to experiment with. FreeBSD has the standard Linux Gnome desktop, the Desktop BSD live disc has a nice desktop as well, but the BSD desktops are lacking GEM/KMS support at the moment, something we take for granted with Linux. But this is coming slowly but surely. I might consider switching to FreeBSD if they added V4l support as well.

     
  • John Cartwright 8:27 PM on March 16, 2012 Permalink | Reply
    Tags: code, index, , ,   

    My PHP code for my Linux pages index. 

    This code is on my http://securitron.securitronlinux.com page. It shows a random image and a random webpage link.

    <?php
    $time = strftime(%A %d %B %Y. %r – %Z”);
    srand(time(NULL));
    $day = rand() % 6;
    $string = sprintf(<font size=\”2pt\”><p>Welcome to my website.</p>\n”);
    $links = array(“BejArray” => array(0=> “perl_code.php”,1=> “psx_doom.php”,2=> “cgi_code.php”,3=> “doom_wadfiles.php”,4=> “my_linux_system_2.php”,5=> “linux_configs.php”,6=> “my_linux_system.php”
    ));
     
    echo $string;
     
    switch($day) {
    case 0:
    $string2 = “Perl CGI Code”;
    break;
    case 1:
    $string2 = “PSX Doom goodness”;
    break;
    case 2:
    $string2 = “Misc programming code”;
    break;
    case 3:
    $string2 = “My Doom wadfiles”;
    break;
    case 4:
    $string2 = “My Linux system tips part 2;
    break;
    case 5:
    $string2 = “My Linux configuration tips”;
    break;
    case 6:
    $string2 = “My Linux system tips part 1;
    break;
    default:
    $string2 = “Take pot luck”;
    }
     
    printf(<p>Random page: <a href=%s>%s</a>.</p>\n”, $links[“BejArray”][$day], $string2);
    printf(<p>Welcome to my GNU/Linux pages. Server time is: %s.</p></font>, $time);
    echo<img src=\”maps/00$day.png\” width=\”320\” height=\”200\” alt=\”Random Doom screenshot.\” style=\”float:right;padding: 8px\”>;
     
    ?>
     
  • John Cartwright 5:54 PM on February 11, 2012 Permalink | Reply
    Tags: 11.0, , code, , , , , ,   

    Good Firefox 11.0 setup for safer web browsing. 

    Good Firefox 11.0 setup for safer web browsing.

    The Firefox web browser truly is a very good and safe browser for everyday use, but with the addition of some extensions, the browsing experience can be made even more secure. Firstly, the Noscript extension is the best and most useful extension for blocking web scripts that can perform malicious actions against your browser.

    Secondly, the Ghostery extension will further block tracking code embedded in the HTML code of web pages, as well as the 1×1 pixel tracking images that are sometimes embedded in web pages to track user visits. This extension will pop up a small purple dialog that will display the blocked content on a website. This extension as with Noscript allows you to whitelist a domain that you trust whilst automatically blocking tracking code as you browse the Internet.

    The Adblock extension allows the Internet user to block web ads they find annoying. This extension has drawn some criticism from web masters for a reduction in ad revenue caused by the blocking of Adsense advertisements on web pages, but if someone is blocking ads, they were not interested in clicking the advertisement and making a purchase anyway, so that is a moot point. This extension may also be used to block certain elements on a web page, such as an Iframe or large annoying logos on the website, making subsequent visits faster. A very useful plugin indeed.

    [My Firefox 11.0 toolbar. Showing the extensions I have installed.

    The LinkExtend extension for Firefox gives you a Google toolbar styled toolbar that displays the pagerank of a website and the SiteTraffic rating as well. Above you may see a screenshot of this toolbar in action, you can also see the Ghostery popup and the icons for Adblock and Ghostery on the Firefox 11.0 toolbar. I can not get the Google toolbar to install with Firefox 10.0 or Firefox 11.0, so this is a good alternative.

    Flashblock is another good extension that is invaluable when you are browsing a PHPBB message board and someone posts a long post with about 30 Youtube embeds in it, that can really slow down the page. With this extension installed, you do not need to worry at all about all of that loading at once. This will replace all of those video embeds with a button that will allow you to enable the flash embed and play the video if you want, putting control back in your hands. and it will block those annoying hidden flash embeds that play repeating music when the website loads. Some imageboard websites are notorious for that.

    Firefox eating the competition.

    Firefox eating the competition.

    Internet Explorer 9.0 has a good script blocking feature built into the browser, you have to add some Tracking Protection Lists to the web browser using the inbuilt tracking protection system in the web browser. But since I am no longer using Windows it is strictly Feuerfuchs for me. Even the old Mozilla 1.7 web browser was better than Internet Explorer 6.0, that is still being used these days even though it is totally insecure. Firefox with these extensions installed is far more secure and reliable. The Ghostery extension will block facebook tracking as well as other nasty stuff. Just whitelist some blocked elements if the website you are using appears to break.

    Finally Downloadhelper is an extension that allows the user to download video content from Youtube and other video sharing websites. This can be useful if you wish to download the video you are watching to enjoy later on. I do not see the downside to talking about this extension, what is the difference between watching a music video online and being able to download it for your personal use? This extension also allows you to download pictures from a website as well.

     
  • John Cartwright 12:13 PM on September 24, 2011 Permalink | Reply
    Tags: , code, , , reading, STDIN   

    Useful C++ snippet. A better way to read in a sentence with STDIN. 

    Tsar Bomba on a car. A misfire?

    Tsar Bomba on a car. A misfire?

    This is a very useful C++ code snippet for reading in a line of text into STDIN. Hopefully this will be useful to someone.

    #include <iostream>
    #include <string.h>
    #include <sstream>
     
    using namespace std;
     
    int goku(void) {
    	cout << "Hello, Please enter your name.\n" << endl;
    	return 1;
    }
     
    int main(int argc, char **argv) {
     
    	goku();
     
    	string name = "";
    	getline(cin, name);
     
    	cout << "Welcome "<< name << ".\n"<< endl;
     
    	return 0;
    }
     
c
Compose new post
j
Next post/Next comment
k
Previous post/Previous comment
r
Reply
e
Edit
o
Show/Hide comments
t
Go to top
l
Go to login
h
Show/Hide help
shift + esc
Cancel