Monday, October 31, 2016

cpu benchmarking on linux with sysbench

TL;DR

install synaptic package
$ sudo apt-get install sysbench

run
$ sysbench --num-threads=1 --test=cpu --cpu-max-prime=25000 run


from the man page @ http://man.cx/sysbench(1)
DESCRIPTION

SysBench is a modular, cross−platform and multi−threaded benchmark tool for evaluating OS parameters that are important for a system running a database under intensive load.

The idea of this benchmark suite is to quickly get an impression about system performance without setting up complex database benchmarks or even without installing a database at all.

Current features allow to test the following system parameters:

• file I/O performance
• scheduler performance
• memory allocation and transfer speed
• POSIX threads implementation performance
• database server performance

The design is very simple. SysBench runs a specified number of threads and they all execute requests in parallel. The actual workload produced by requests depends on the specified test mode. You can limit either the total number of requests or the total time for the benchmark, or both.

Available test modes are implemented by compiled−in modules, and SysBench was designed to make adding new test modes an easy task. Each test mode may have additional (or workload−specific) options.

...

TEST MODEs

CPU

The cpu is one of the most simple benchmarks in SysBench. In this mode each request consists in calculation of prime numbers up to a value specified by the −−cpu−max−primes option. All calculations are performed using 64−bit integers.

Each thread executes the requests concurrently until either the total number of requests or the total execution time exceed the limits specified with the common command line options.

Example:
$ sysbench --test=cpu run

--- --- --- --- --- ---

sample output - Lenovo IdeaPad 300:

dog@cat:~$ sysbench --num-threads=4 --test=cpu --cpu-max-prime=25000 run
sysbench 0.4.12:  multi-threaded system evaluation benchmark

Running the test with following options:
Number of threads: 4

Doing CPU performance benchmark

Threads started!
Done.

Maximum prime number checked in CPU test: 25000

Test execution summary:
    total time:                          12.2696s
    total number of events:              10000
    total time taken by event execution: 49.0625
    per-request statistics:
         min:                                  4.22ms
         avg:                                  4.91ms
         max:                                 34.80ms
         approx.  95 percentile:               5.20ms

Threads fairness:
    events (avg/stddev):           2500.0000/28.85
    execution time (avg/stddev):   12.2656/0.00

Thursday, September 29, 2016

convert m4a to mp3 in lunux via the command line

ex Lord Neckbeard at SuperUser

http://superuser.com/questions/704493/ffmpeg-convert-m4a-files-to-mp3-without-significant-loss-of-information-quali

$ mkdir mp3
$ for f in *.m4a; do ffmpeg -i "$f" -codec:v copy -codec:a libmp3lame -q:a 2 mp3/"${f%.m4a}.mp3"; done

Saturday, September 3, 2016

getting set up with the raspberry pi 3 B and ubuntu linux

1. download the 16-04 for Pi3B image from the official Canonical page.

With the release of the Raspberry Pi 2 Model B and its ARMv7-based BCM2709 processor, it is now possible to run Ubuntu directly on the Raspberry Pi.
...
Raspberry Pi 3: ubuntu-16.04-preinstalled-server-armhf+raspi3.img.xz (4G image, 216M compressed)
...
This Raspberry Pi 3 image is built by Ryan Finnie using modified Xenial packages in a PPA (ppa:ubuntu-raspi2/ppa-rpi3), and is not supported directly by Canonical. 

2. initialize the SD card with the image

2.1 Decompress the archived image from within the Nautilus file explorer using the archive manager that comes pre-installed with 16-04.

2.2 uBuntu 16-04 comes pre-installed with a GUI disk-image tool 'Startup Disk Creator', which is as complicated to use as selecting the the image and the SD card.

3. login and configure

// at this point you will need to plug in a keyboard and monitor.

Login username is "ubuntu", password is "ubuntu". You will be asked to change the password on first login.

4. install the development platform

since we're going for a lite-weight install, and installing even the optimized xubuntu-desktop would require something like 1.6GB of space, so drop that idea, we're flying from the terminal.

I have plans for working in all of javascript, python and mono.NET, but since mono tends to be something of a beast, I'm going to get started with js/py only.


4.0 web server

// nginx
$ sudo apt-get install nginx

4.1 persistence


4.1.1 mongodb


32-bit version @ 2.6.10

- database limited to 2GB in size

// install
$ sudo apt-get install mongodb

// launch shell
$ sudo mongo

4.1.1 postgresql


$ sudo apt-get install postgresql


4.2 python /django web server stack

python3 (pre-installed)

// django web server
$ sudo apt-get install python-django

4.3 javascript / nodejs / express web server stack


4.3.1 nodejs & package management


$ sudo apt-get install nodejs
$ sudo apt-get install npm
$ sudo apt-get install bower

4.3.2 persistence

$ sudo npm install -g pg
$ sudo npm install -g mongo
 
5.0 install infosec tools

5.1 scapy wifi tools

// scapy dependencies

// python crypto
$ sudo apt-get install python-crypto

// python graphics
$ sudo apt-get install python-pyx

$ sudo apt-get install gnuplot
$ sudo apt-get install python-gnuplot

// scapy
$ sudo apt-get install python-scapy

5.2 reaver
 
$ sudo apt-get install reaver

5.3 pyscard = python smartcard

// python 2
$ sudo apt-get install python-pyscard
// python 3
$ sudo apt-get install python3-pyscard


Monday, August 29, 2016

Install MongoDB 3.? on uBuntu 1604

Official Instructions
https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/

then create folder @ /data/db, i.e.
$ sudo mkdir /data
$ sudo mkdir /data/db


then fix file permissions:
$ sudo chown -R `id -u` /data/db

Saturday, July 2, 2016

Debugging nodejs w Chromium

electron
https://github.com/electron/electron
>>
The Electron framework lets you write cross-platform desktop applications
using JavaScript, HTML and CSS. It is based on Node.js and
Chromium and is used by the Atom
editor and many other apps.
<< 

https://mattdesl.svbtle.com/debugging-nodejs-in-chrome-devtools
 
# first install electron
$ sudo ln -s /usr/bin/nodejs /usr/local/bin/node
# DO NOT CONFUSE electron-prebuilt package (correct) with electron package (wrong) 
$ sudo npm install -g electron-prebuilt
 
# then devtool 
$ sudo npm install -g devtool
 
# run devtool from the cmd line, debugging server.js
$ devtool server.js --watch 

Friday, July 1, 2016

nodejs Modules

For reference, the official documentation is
@ https://nodejs.org/api/modules.html

Darren de Ridder (https://twitter.com/73rhodes)
has an excellent summary presentation on github.io
Node.JS Module Patterns Using Simple Examples
@ https://darrenderidder.github.io/talks/ModulePatterns/#/

Saturday, April 30, 2016

Mark Down Markup Language

wikipedia:

Markdown is a lightweight markup language with plain text formatting syntax designed so that it can be converted to HTML and many other formats using a tool by the same name.[8][9] Markdown is often used to format readme files, for writing messages in online discussion forums, and to create rich text using a plain text editor.

PDF cheat-sheet: https://guides.github.com/pdfs/markdown-cheatsheet-online.pdf

end 



Friday, March 25, 2016

Open Source Queueing Systems


Top 5 Open Source AMQP (Advanced Message Queing Protocol) Implementations
https://www.rabbitmq.com/

- Rabbit MQ @ https://www.rabbitmq.com/
- Open AMQ @ http://www.openamq.org/
- Storm MQ @ http://stormmq.com/
- Apache QPID @ https://qpid.apache.org/
- RedHat Enterprise MRG @ https://access.redhat.com/products/red-hat-enterprise-mrg-realtime

Monday, March 21, 2016

steve wozniak

Bloomberg Business Week - youtube - https://www.youtube.com/watch?v=pJif4i9NRdI

Tuesday, February 2, 2016

Visual Studio - Bind 'Ctrl + w' to Close Current Window

Tools > Options > Environment > Keyboard

Show commands containing:  File.Close
Press shortcut keys:  'Ctrl + w'
Assign

Show commands containing:  Edit.SelectCurrentWord
Remove
OK

Friday, January 22, 2016

C# .NET Windows UAC - Check if User is in Admin Group

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Security.Principal;
using System.Text;
using System.Threading.Tasks;

namespace UACStatus
{
    ///
    /// 2011 David Moore
    /// http://www.davidmoore.info/blog/2011/06/20/how-to-check-if-the-current-user-is-an-administrator-even-if-uac-is-on/
    ///
    public class UACSecurity
    {
        [DllImport("advapi32.dll", SetLastError = true)]
        static extern bool GetTokenInformation(IntPtr tokenHandle, TokenInformationClass tokenInformationClass, IntPtr tokenInformation, int tokenInformationLength, out int returnLength);

        ///
        /// Passed to to specify what
        /// information about the token to return.
        ///
        enum TokenInformationClass
        {
            TokenUser = 1,
            TokenGroups,
            TokenPrivileges,
            TokenOwner,
            TokenPrimaryGroup,
            TokenDefaultDacl,
            TokenSource,
            TokenType,
            TokenImpersonationLevel,
            TokenStatistics,
            TokenRestrictedSids,
            TokenSessionId,
            TokenGroupsAndPrivileges,
            TokenSessionReference,
            TokenSandBoxInert,
            TokenAuditPolicy,
            TokenOrigin,
            TokenElevationType,
            TokenLinkedToken,
            TokenElevation,
            TokenHasRestrictions,
            TokenAccessInformation,
            TokenVirtualizationAllowed,
            TokenVirtualizationEnabled,
            TokenIntegrityLevel,
            TokenUiAccess,
            TokenMandatoryPolicy,
            TokenLogonSid,
            MaxTokenInfoClass
        }

        ///
        /// The elevation type for a user token.
        ///
        enum TokenElevationType
        {
            TokenElevationTypeDefault = 1,
            TokenElevationTypeFull,
            TokenElevationTypeLimited
        }

        public bool CurrentUserIsAdminRole()
        {
            var identity = WindowsIdentity.GetCurrent();
            if (identity == null) throw new InvalidOperationException("Couldn't get the current user identity");
            var principal = new WindowsPrincipal(identity);

            // Check if this user has the Administrator role. If they do, return immediately.
            // If UAC is on, and the process is not elevated, then this will actually return false.
            if (principal.IsInRole(WindowsBuiltInRole.Administrator)) return true;

            // If we're not running in Vista onwards, we don't have to worry about checking for UAC.
            if (Environment.OSVersion.Platform != PlatformID.Win32NT || Environment.OSVersion.Version.Major < 6)
            {
                // Operating system does not support UAC; skipping elevation check.
                return false;
            }

            int tokenInfLength = Marshal.SizeOf(typeof(int));
            IntPtr tokenInformation = Marshal.AllocHGlobal(tokenInfLength);

            try
            {
                var token = identity.Token;
                var result = GetTokenInformation(token, TokenInformationClass.TokenElevationType, tokenInformation, tokenInfLength, out tokenInfLength);

                if (!result)
                {
                    var exception = Marshal.GetExceptionForHR(Marshal.GetHRForLastWin32Error());
                    throw new InvalidOperationException("Couldn't get token information", exception);
                }

                var elevationType = (TokenElevationType)Marshal.ReadInt32(tokenInformation);

                switch (elevationType)
                {
                    case TokenElevationType.TokenElevationTypeDefault:
                        // TokenElevationTypeDefault - User is not using a split token, so they cannot elevate.
                        return false;
                    case TokenElevationType.TokenElevationTypeFull:
                        // TokenElevationTypeFull - User has a split token, and the process is running elevated. Assuming they're an administrator.
                        return true;
                    case TokenElevationType.TokenElevationTypeLimited:
                        // TokenElevationTypeLimited - User has a split token, but the process is not running elevated. Assuming they're an administrator.
                        return true;
                    default:
                        // Unknown token elevation type.
                        return false;
                }
            }
            finally
            {
                if (tokenInformation != IntPtr.Zero) Marshal.FreeHGlobal(tokenInformation);
            }
        }
    }
}

Wednesday, January 20, 2016

Visual Studio Build Variables

https://msdn.microsoft.com/en-us/library/c02as0cs.aspx
Macro
Description
$(RemoteMachine)
Set to the value of the Remote Machine property on the Debug property page. See Changing Project Settings for a C/C++ Debug Configuration for more information.
$(Configuration)
The name of the current project configuration (for example, "Debug").
$(Platform)
The name of current project platform (for example, "Win32").
$(ParentName)
(Deprecated.) Name of the item containing this project item. This will be the parent folder name, or project name.
$(RootNameSpace)
The namespace, if any, containing the application.
$(IntDir)
Path to the directory specified for intermediate files. If this is a relative path, intermediate files go to this path appended to the project directory. This path should have a trailing slash. This resolves to the value for theIntermediate Directory property. Do not use $(OutDir) to define this property.
$(OutDir)
Path to the output file directory. If this is a relative path, output files go to this path appended to the project directory. This path should have a trailing slash. This resolves to the value for the Output Directory property. Do not use $(IntDir) to define this property.
$(DevEnvDir)
The installation directory of Visual Studio (defined as drive + path); includes the trailing backslash '\'.
$(InputDir)
(Deprecated; migrated.) The directory of the input file (defined as drive + path); includes the trailing backslash '\'. If the project is the input, then this macro is equivalent to $(ProjectDir).
$(InputPath)
(Deprecated; migrated.) The absolute path name of the input file (defined as drive + path + base name + file extension). If the project is the input, then this macro is equivalent to $(ProjectPath).
$(InputName)
(Deprecated; migrated.) The base name of the input file. If the project is the input, then this macro is equivalent to$(ProjectName).
$(InputFileName)
(Deprecated; migrated.) The file name of the input file (defined as base name + file extension). If the project is the input, then this macro is equivalent to $(ProjectFileName).
$(InputExt)
(Deprecated; migrated.) The file extension of the input file. It includes the '.' before the file extension. If the project is the input, then this macro is equivalent to $(ProjectExt).
$(ProjectDir)
The directory of the project (defined as drive + path); includes the trailing backslash '\'.
$(ProjectPath)
The absolute path name of the project (defined as drive + path + base name + file extension).
$(ProjectName)
The base name of the project.
$(ProjectFileName)
The file name of the project (defined as base name + file extension).
$(ProjectExt)
The file extension of the project. It includes the '.' before the file extension.
$(SolutionDir)
The directory of the solution (defined as drive + path); includes the trailing backslash '\'.
$(SolutionPath)
The absolute path name of the solution (defined as drive + path + base name + file extension).
$(SolutionName)
The base name of the solution.
$(SolutionFileName)
The file name of the solution (defined as base name + file extension).
$(SolutionExt)
The file extension of the solution. It includes the '.' before the file extension.
$(TargetDir)
The directory of the primary output file for the build (defined as drive + path); includes the trailing backslash '\'.
$(TargetPath)
The absolute path name of the primary output file for the build (defined as drive + path + base name + file extension).
$(TargetName)
The base name of the primary output file for the build.
$(TargetFileName)
The file name of the primary output file for the build (defined as base name + file extension).
$(TargetExt)
The file extension of the primary output file for the build. It includes the '.' before the file extension.
$(VSInstallDir)
The directory into which you installed Visual Studio. 
This property contains the version of the targeted Visual Studio, which might be different that the host Visual Studio. For example, when building with $(PlatformToolset) = v110$(VSInstallDir) contains the path to the Visual Studio 2012 installation.
$(VCInstallDir)
The directory into which you installed Visual C++. 
This property contains the version of the targeted Visual C++, which might be different that the host Visual Studio. For example, when building with $(PlatformToolset) = v90$(VCInstallDir) contains the path to the Visual C++ 2008 installation.
$(FrameworkDir)
The directory into which the .NET Framework was installed.
$(FrameworkVersion)
The version of the .NET Framework used by Visual Studio. Combined with $(FrameworkDir), the full path to the version of the .NET Framework use by Visual Studio.
$(FrameworkSDKDir)
The directory into which you installed the .NET Framework. The .NET Framework could have been installed as part of Visual Studio or separately.
$(WebDeployPath)
The relative path from the web deployment root to where the project outputs belong. Returns the same value asRelativePath.
$(WebDeployRoot)
The absolute path to the location of . For example, c:\inetpub\wwwroot.
$(SafeParentName)
(Deprecated.) The name of the immediate parent in valid name format. For example, a form is the parent of a .resx file.
$(SafeInputName)
(Deprecated.) The name of the file as a valid class name, minus file extension.
$(SafeRootNamespace)
(Deprecated.) The namespace name in which the project wizards will add code. This namespace name will only contain characters that would be permitted in a valid C++ identifier.
$(FxCopDir)
The path to the fxcop.cmd file. The fxcop.cmd file is not installed with all Visual C++ editions.

Friday, January 15, 2016

Get Windows .DLL Information via The Command Line / Powershell

get public key using sn.exe = strong name util

"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\sn.exe" -Tp "path_to_dll"

get version info, from the powershell prompt

[System.Reflection.Assembly]::LoadFrom("path_to_dll").GetName().Version