Wikipedia

Search results

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/