Wikipedia

Search results

10 February 2023

Resource constrained VM appliance for testing

When you create a new virtual machine in VirtualBox, you can specify the amount of RAM and number of virtual CPU cores that the virtual machine can use. You can also specify the size of the virtual disk, which determines the maximum amount of disk space available to the virtual machine.

Here are the steps to create a resource-limited virtual machine in VirtualBox:

  1. Launch VirtualBox and click the "New" button to create a new virtual machine.
  2. Give the virtual machine a name and select the type and version of the operating system you want to install.
  3. In the "System" section, click the "Processor" tab and set the number of virtual CPU cores to 2.
  4. In the "System" section, click the "Motherboard" tab and set the amount of RAM to the desired amount.
  5. In the "Storage" section, click the "Create a virtual hard disk now" button and select the size of the virtual disk.
  6. Click the "Create" button to create the virtual machine.
  7. Start the virtual machine and install the operating system.

After you have created the virtual machine, you can monitor its resource usage to make sure that it is not exceeding the specified limits. 

08 February 2023

Ethereum: hex-encoding function ABI calls

Delegatecall is a feature in Solidity, the programming language used to write smart contracts on the Ethereum blockchain, that allows a contract to call another contract's code and use its storage. Essentially, delegatecall enables one contract to reuse code from another contract, and the storage of the calling contract will be used as if it was the storage of the called contract.

Delegatecall was hacked before in an exploit known as the "re-entrancy attack." In this type of attack, a malicious contract could call another contract's code multiple times in a single transaction, effectively re-entering the code and taking advantage of the storage of the called contract. This could lead to the malicious contract being able to steal funds from the called contract's storage before the called contract had a chance to update its storage to reflect the intended outcome of the transaction.

To mitigate these types of attacks, it is important to properly handle re-entrancy in smart contract code and to follow best practices for secure contract development. 

09 September 2022

Oracle VBox server config on NAT

So you want a flexible general-purpose VM with the latest Ubuntu LTS? Right now it's Ubuntu 22, so these may not apply in the future.

These instructions assume that NAT is the default network selection/configuration in Virtualbox.


1) add your user to visudo

sudo visudo

# in visudo add your user to a new line

user ALL=(ALL) NOPASSWD:ALL

2) configure netplan

sudo ip a

# determine if networkd or network-manager is running, it's your renderer

# by default networkd will be running on a fresh Ubuntu 22 LTS install

# acquire your network identifier (eth0, enp0s3, etc.)

network:

    version: 2

    renderer: networkd

    ethernets:

        eth0:

            addresses:

                - 10.0.2.23/24

            nameservers:

                addresses: [8.8.8.8, 8.8.4.4]

            routes:

                - to: default

                  via: 10.0.2.2


# then apply changes

sudo netplan apply

3) configure port forwarding

- In VirtualBox VM Settings > Network > Advanced set your port forwarding rules:


- Verify you can SSH in to your box, in Terminal it's with:

% ssh -p 2222 ubuntu@127.0.0.1

4) install guest additions dependencies

sudo apt update

sudo apt install -y virtualbox-guest-additions-iso virtualbox-guest-utils

5) create a shared folder

- In VirtualBox VM Settings > Shared Folders add your folder:


6) clone your machine

Restart/reboot your VM, verify everything's working then make a full clone!

11 February 2021

Sort directories by size in OSX

 In the Terminal application we'll be using the du command.



Let's specify depth as one so to avoid listing files and subdirectories, and the output in gigabytes. I know this particular folder is roughly 9 gigabytes overweight, and I'm looking for a > 5g whale.

Before that, let's pipe it to a sort operation to list directories by size in descending order with sort. This will take the -n option to sort by number and -r to list in reverse (descending) order.


Found it!





31 August 2020

Establishment Media

The bias from news and political shows, including John Oliver and Trevor Noah, are completely one sided in an eery chorus that holds an eery pitch on one wavelength.

What's going on is absolutely insane. These people promote GoFundMe donations for white supremacist, bolshevik and/or neonazi, serial pedophiles, yet fail to mention their carrying of guns during riots, nor the murders they cause.

This was starkly voiced during the time of Mr. Dorn's murder. However, the establishment media, with all infinite possibilities of having different voices and opinions (tunes), continues their chorus. It's been a recent symphony during the past 4 years Nancy Pelosi has been continuing to drive war and other questionable expenditures, and without said establishment media scrutinizing in any appreciable manner.

09 July 2020

Collage




To Show just how much in common countries have with one another.


21 April 2020

Network load performance between Starlette and Flask with urllib3, requests, and httpx clients

Flask and Starlette performance with urllib3, requests, and httpx

Source code available at https://github.com/aug2uag/starlette-flask-benchmark

The purpose of this benchmark was to evaluate the performance difference under load for a Flask and Starlette microframework with various popular HTTP clients.

These benchmark results were from 1000 cycles.

Results

Flask @ 1000 cycles (testing smaller JSON response)
urllib3:     6.009076181
requests:    8.310135888
httpx:       14.922275728
Flask @ 1000 cycles (testing larger text response)
urllib3:     6.489965677
requests:    7.959935096000001
httpx:       15.216326602
Starlette @ 1000 cycles (testing smaller JSON response)
urllib3:     6.489965677
requests:    7.959935096000001
httpx:       15.216326602
Starlette @ 1000 cycles (testing larger text response)
urllib3:     0.861392250999998
requests:    7.092012402999998
httpx:       12.933335759999999
HTTP libraries
Across the board, the httpx library underperformed relative to requests and urllib3. This might be because the httpx.get method is not benefiting from its async capabilities. The most efficient library of the three was consistently urllib3, followed by the requests library.

The size difference in the request body in this experiment had little or no effect, and indicates the difference in the request bodies was nominal.
Frameworks
Both Flask and Starlette are similar in implementation. Flask is more focused on delivering a full-stack experience, while Starlette is organized to be more biased towards headless services.

The performance of Starlette was modestly more good relative to the requests library. However, Starlette was significantly more performant with urllib3.


Discussion


The urllib3 results for Starlette may be indicating failure, although the server logs looked Ok-- the performance of urllib3 with Starlette is simply unbelievable. Starlette and Python 3 are optimized with subroutines, which may explain the dramatic differences between Flask and Starlette in their performance with urllib3 in case it is working. In that case there are clear multithreading capabilities at work that are stratespherically advantageous to utilize in high performance network I/O applications written in Python. Whereas Flask utilizes WGSI, Starlette implements ASGI that seems to be on its way for taking over Python internet gateways.

Therefore, Starlette with ASGI has superior advantages over Flask for microframework architectures.

08 November 2019

Global Constants in Rust

It's really straight forward.

static WORLD: &'static str = "Foo";
static NUMBA: i32 = 143;

fn main() {
    // Access constant in the main thread
    if NUMBA > 0 {
        println!("Hello {}", WORLD);
    }
}

outputs:

$ ./target/debug/js_stack
Hello Foo

17 October 2019

OSX broken pip and virtualenv after brew update

Working on a new project and needed to download some new brew packages that ended up breaking my virtualenv.

This is how I got it back to speed:


xcode-select --install
rm '/usr/local/bin/pip'
# or 
# mv /usr/local/bin/pip /usr/local/bin/pip.old

sudo /usr/bin/easy_install pip
sudo pip install virtualenv --upgrade

06 October 2019

Newton Raphson method to solve roots of higher-degree equations

Roots of High-Degree Equations

Equations can be polynomials, radicals, trigonometric, logarithmic, and other.

Simplest example is the quadratic function. More complex equations will often require numerical methods to solve.


Newton Raphson Method algorithm:

- similar to Simple Iteration except it handles the equation as a function, not a rearrangement
- first step is to put the equation as a function
- second step is to calculate the first derivative of the function
- third step is to iterate as the simple iteration method

This method is an optimization of the simple iteration method.


for example:

'''
for equation:
x^3 - x^2 + 7 = 10
x^3 - x^2 - 3 = 0

derivative
3x^2 - 2x = 0

Newton Raphson equation:

y = x - (x^3 - x^2 - 3) / (3x^2 - 2x)

'''

x = 2 # initial guess, derive multiple roots with different guesses
for i in range(100):
y = x - (x^3 - x^2 - 3) / (3x^2 - 2x)
if x == y: # or within tolerable range
break
x = y

# y now approximates the value of the root





Simple iteration method to solve roots of higher-degree equations

Equations of higher-degree equations can be polynomials, radicals, trigonometric, logarithmic, and other.

Simplest example is the quadratic function. More complex equations will often require numerical methods to solve.


Simple Iterations Method Algorithm:

- based on trial and error, values are substituted until root is obtained
- first step is to REARRANGE the equation to isolate the variable to the left side of the equation
- second step is to ASSUME an initial trial value for the first iteration
- third step is to SUBSTITUTE the value in the equation and solve
- fourth step is to REPLACE the value if the value does not solve the equation else BREAK
- fifth step is to REPEAT the third and fourth steps with the NEW VALUE of the equation


'''
for equation:
x^3 - x^2 + 7 = 10
x(x^2 - x) = 3
x = 3 / (x^2 - x)
'''

def tolerable_range(x, y, tolerance=0.001):
  pass
  # can be difference: abs(x, y) < tolerance
  # can be analysis of convergence 
  #(i.e. difference from previous value is nominal)

def check_divergence(x, y):
  pass
  # if divergence exists, solution cannot be solved
  # example implementation:
  # https://gist.github.com/zhiyzuo/f80e2b1cfb493a5711330d271a228a3d

x = 2 # initial guess
for i in range(100):
y = 3 / (x^2 - x) # new value
if x == y: # or within tolerable range
break
x = y

# y should now approximates the value of the root




Numerical Computing Categories and Methods

Roots of High Degree Equations
* Simple iteration method
* Newton-Raphson's method
* Bisection method

Interpolation and Curve Fitting
* Lagrange's method
* Newton's method
* Linear regression (fitting with straight line)
* Fitting with polynomial curve

Numerical Differentiation
* Finite differences method

Numerical Integration
* Trapezoidal rule
* Simpson's 1/3 rule
* Simpson's 3/8 rule
* Double integrations

Systems of Linear Equations
* Gauss elimination method
* Jacobi's method
* Gauss-Seidel's model

Ordinary Differential Equations
* Euler's method
* Second order Runge-Kutta's method
* Fourth order Runge-Kutta's method
* Higher-order ordinary differential equations

05 August 2019

List of Machine Learning algorithms


  • Almeida Pineda Recurrent Backpropagation
  • Backpropagation
  • Bootstrap Aggregating
  • CN2 Algorithm
  • Constructing Skill Trees
  • Dehaene Changeux Model
  • Diffusion Map
  • Dominance-Based Rough Set Approach
  • Dynamic Time Warping
  • Error-Driven Learning
  • Evolutionary Multimodal Optimization
  • Expectation Maximization Algorithm
  • FastICA
  • Forward Backward Algorithm
  • GeneRec
  • Genetic Algorithm for Rule Set Production
  • Growing Self-Organizing Map
  • HEXQ
  • Hyper Basis Function Network
  • IDistance
  • K-Nearest Neighbors Algorithm
  • Kernel Methods for Vector Output
  • Kernel Principal Component Analysis
  • Leabra
  • Learning to Learn
  • Linde Buzo Gray Algorithm
  • Local Outlier Factor
  • LogitBoost
  • Loss Functions for Classification
  • Manifold Alignment
  • Minimum Redundancy Feature Selection
  • Multiple Kernel Learning
  • Non-Negative Matrix Factorization
  • Prefrontal Cortex Basal Ganglia Working Memory
  • Primary Value Learned Value  Model
  • Q-Learning
  • Quadratic Unconstrained Binary Optimization
  • Query Level Feature
  • Quickprop
  • Radial Basis Function Network
  • Randomized Weighted Majority Algorithm
  • Reinforcement Learning
  • Rprop
  • Semi-supervised Learning
  • Skill Chaining
  • Sparse PCA
  • State-Action-Reward-State-Action
  • Stochastic Gradient Descent
  • Supervised Learning
  • T-Distributed Stochastic Neighbor Embedding
  • Temporal Difference Learning
  • Transduction
  • Unsupervised Learning
  • Wake-Sleep Algorithm
  • Weighted Majority Algorithm

29 April 2019

How to remove a large file from commit history in git

I had committed a headless Chromium module. The purpose of committing modules for me in late stage projects is to make sure they exist, who knows what could happen later. Nevermind it's a module, this may have well been an errant zip file or anything preventing size-limited transfers.

This method will remove any file from any commit in history.


$ git filter-branch --tree-filter 'rm -rf node_modules/pdf-puppeteer' HEAD
$ # or 'rm -f $FILENAME'

20 April 2019

CentOS sshd security helpers

list all unique IPs that failed login

egrep "Failed|Failure" /var/log/secure| grep -Po "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+" | sort | uniq -c



clear logs without interruption

cat /dev/null &gt; /var/log/secure



logs not collecting, erroneous empty of log directory

systemctl status rsyslog.service
systemctl status sshd.service

systemctl reload rsyslog.service
systemctl restart rsyslog.service

07 April 2019

Find and block failed SSH logins on CentOS

Got a problem with others trying to brute force the root password on your box?


I'm not running vsftpd, yet it's a similar process. My concern is limited to third-parties trying to access my box with SSH.
This is what I did:
Tecmint showed me how to grep the IPs:
# egrep "Failed|Failure" /var/log/secure
Apr  7 03:42:13 67 sshd[4868]: Failed password for root from 186.233.231.44 port 56075 ssh2
Apr  7 03:45:19 67 sshd[4871]: Failed password for root from 38.140.192.165 port 52138 ssh2
Apr  7 03:47:16 67 sshd[4874]: Failed password for root from 35.221.157.112 port 36306 ssh2
Apr  7 03:49:01 67 sshd[4877]: Failed password for root from 153.127.193.168 port 40604 ssh2
Apr  7 03:50:54 67 sshd[4881]: Failed password for root from 89.109.54.214 port 52268 ssh2
Apr  7 04:01:07 67 sshd[4900]: Failed password for root from 14.63.192.249 port 37507 ssh2
Apr  7 04:04:49 67 sshd[4905]: Failed password for root from 41.228.165.225 port 35462 ssh2
Apr  7 04:05:40 67 sshd[4909]: Failed password for root from 195.142.122.126 port 42548 ssh2
Apr  7 04:16:17 67 sshd[4914]: Failed password for root from 103.120.224.3 port 51416 ssh2
Apr  7 04:26:00 67 sshd[4919]: Failed password for root from 139.59.79.56 port 40074 ssh2
Apr  7 04:37:27 67 sshd[4925]: Failed password for root from 103.27.236.2 port 60528 ssh2
Apr  7 04:44:33 67 sshd[4968]: Failed password for root from 18.214.68.139 port 60896 ssh2
Apr  7 04:53:24 67 sshd[4991]: Failed password for root from 193.36.184.175 port 41408 ssh2
Apr  7 04:56:09 67 sshd[4995]: Failed password for root from 1.250.62.223 port 59052 ssh2
Apr  7 05:00:45 67 sshd[4998]: Failed password for root from 183.82.63.212 port 43840 ssh2
Apr  7 05:05:41 67 sshd[5016]: Failed password for root from 186.103.146.148 port 55982 ssh2
Apr  7 05:10:14 67 sshd[5038]: Failed password for root from 68.183.4.19 port 34894 ssh2

From there I updated my /etc/hosts.deny file to the following:
# /etc/hosts.deny
#
# hosts.deny    This file contains access rules which are used to
#               deny connections to network services that either use
#               the tcp_wrappers library or that have been
#               started through a tcp_wrappers-enabled xinetd.
#
#               The rules in this file can also be set up in
#               /etc/hosts.allow with a 'deny' option instead.
#
#               See 'man 5 hosts_options' and 'man 5 hosts_access'
#               for information on rule syntax.
#               See 'man tcpd' for information on tcp_wrappers
#
sshd: 186.233.231.44
sshd: 38.140.192.165
sshd: 35.221.157.112
sshd: 153.127.193.168
sshd: 89.109.54.214
sshd: 14.63.192.249
sshd: 41.228.165.225
sshd: 195.142.122.126
sshd: 103.120.224.3
sshd: 139.59.79.56
sshd: 103.27.236.2
sshd: 18.214.68.139
sshd: 193.36.184.175
sshd: 1.250.62.223
sshd: 183.82.63.212
sshd: 186.103.146.148
sshd: 68.183.4.19

Just let systemd know it needs to update changes, and voila. It's done.
# systemctl restart sshd

18 January 2019

Deno, the new paradigm in writing full stack applications with Javascript

Deno is a new language paradigm. It’s a frontier where intelligent design decisions intersect with the bleeding edge of technology, and backed by a great community of open source contributors.

I’ve had the fortune of spending time with some of the contributors that helped guide my learning that I would like to share with you here.

Building Deno


It’s not just about cargo build, be sure to run tools/setup.py, update submodules, and run tools/build.py — these are explained much more well in the references below.

Flatbuffers in Deno


The primary benefit of Deno is although V8 exists in the runtime it’s abstracted away from end-users. Whereas Node was weighed down by having to directly interact with V8, Deno placed substantial consideration and effort to avoid having developers and contributors rely on interacting with V8, which benefits in a variety of ways:

  • no longer having to deal with the subtle mishandlings that developers fear when it comes to using C++ 
  • no longer having to know and interact with the inner workings of a very large code base that exists in V8
  • leveraging the power of Rust’s benefits for resource management, concurrency, and parallelism

There’s also the issue of implementing best practices, and Flatbuffers enters the space here. Similar to Protobuf in that message parsing can be serialized and deserialized across a variety of languages, Flatbuffers can consume much less memory than Protocol Buffers, and work much more fast and smart.

This is only a sampling of what makes Deno exciting, and I haven’t even scratched the surface yet.

Check out the Flatbuffer declarations in src/msg.fbs

Essentially, the Typescript frontend will serialize messages to a Rust backend that’s managed by the Tokio framework (https://github.com/tokio-rs/tokio). The Rust backend deserializes the message, performs the task, serializes the response, and sends it back to the Typescript.

Navigating Deno


Open src/main.rs and proceed to navigate from there. One point to note is that the standard library exists as a submodule that can be found in the denoland at Github (https://github.com/denoland/).

I hope you check it out for yourself. Deno’s looking forward to a bright future, and it’s just getting started!

Resources:

Denolib Guide, a guide to Deno Core: https://github.com/denolib/guide
Awesome Deno, list of things related to Deno: https://github.com/denolib/awesome-deno
Guide to V8 for base familiarity: https://denolib.github.io/v8-docs/

07 August 2018

mongoexport Unrecognized field 'snapshot'

Try to get your data out of Mongo and you may find yourself butting heads with

Unrecognized field 'snapshot' 


You should know there are options to skip including `snapshot` in your export query, my guess is this applies to dumps also.



https://github.com/mongodb/mongo-tools/blob/master/mongoexport/mongoexport.go


To get around this error, pass in the flag:

# mongoexport  --forceTableScan -d db_name -c collection_name > my_export.json

16 January 2018

Error type 3: Activity class does not exist

This happens when you do the following
  • connect your device/emulator
  • run the app from Android Studio (AS)
  • use/test the app and uninstall it from the device while it is still connected to your computer
  • try to run the app again from AS
AS thinks you still have the app in your device.
tl;dr - To resolve this issue for connected devices you can uninstall with ADB:
$ adb shell pm list packages
package:com.foo.foo

$ adb uninstall com.foo.foo
Success

Run app from AS again after uninstalling with ADB.

29 April 2016

Part 2: React in Electron

The ability to utilize next-gen building platforms without headache-free style


What headache? Are you a f**##$ idiot?!

There's no bigger headache for me than to exercise hours for build tools, and non-trivial development pipelines at the inception of a project.


React is a library who's intention is to simplify the development of user facing applications; and built by Facebook (Thanks Facebook!).

(Oh yeah, it uses Javascript.. That is pretty cool.)

RE: React, play well with Electron

    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/react/15.0.1/react.js"></script>
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/react/15.0.1/react-dom.js"></script>
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.8.1/axios.min.js"></script>
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0-alpha1/jquery.min.js"></script>
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.23/browser.min.js"></script>

dependencies necessary for React to play with Electron, plus axios


Let's get some React to integrate!

Check out this awesome project at CodePen!

ok, plugging it in, you should have something similar to the project in this repo!