CyberSpy

Rantings from a guy with way too much free time

Program the Esp32 with ESP-IDF on Mac OS X

2019-01-23 programming Rob Baruch
Programming the ESP32 on your Mac! Go out and buy yourself a cheap little ESP32 SoC and follow these basic instructions to setup your development environment on your Mac. If you want to do some advanced C-programming to control your ESP32, this is for you. If you’d rather use Arduino and play with simple sketches then this is not for you – google how to use Arduino and off you go! Continue reading

Julia Intro

2018-11-07 programming
Juliaet, Wherefore art thou? As Yoda once said… > YAPL - yet another programming language. Learn something new, you must. Why Learn Julia? Julia was designed from the beginning for high performance. Julia programs compile to efficient native code for multiple platforms via LLVM. As such, it’s an interesting programming language to take a look at as it’s a serious contender for certain classes of programming problems; most notibly, scientific and data-centric analysis. Continue reading

OCaml OpenGL - Get into Gear!

2018-03-13 programming Rob Baruch
OCaml and OpenGL - Getting our Functional Programming into Gear! In my blog post for this day, I thought I’d take a look at the OCaml OpenGL library, lablgl. If you’re not already familair with openGL, I strongly suggest that you take a look at one of the tutorials available online. One that I found to be very informative; although written in c++, is opengl-tutorial. Nonetheless, in this post, we’ll look at some simple, and not so simple examples written in OCaml. Continue reading

Let's Get Funky with the Camel

2018-02-09 programming Rob Baruch
How many ways can we get Fun(ky) In any programming paradigm, it’s critical to understand how we write functions - be they traditional imperative , anonymous , recursive, or functional. In this post, I will break down the different types of functions that you can write in OCaml. Let’s start by examining the imperative function. Here’s a simple function that prints out the phrase Hello World! $n$ times, once on each line, and returns the value $n$ as its result. Continue reading

OCaml Hello World and more

2018-02-06 programming Rob Baruch
Well Hello There! As tradition has it, every new programming language experience must begin with the basic Hello World. Let’s walk the the basics of how to set up our development environment specifically for OCaml and demonstrate how to compile our basic program. Warming up our Environment Of course we could just use our vanilla editor to enter our OCaml programs, but a more efficient work environment leverages an extensible editor that is aware of our programming language. Continue reading

Recursion Revisited

Recursion, from more than one point-of-view.

A common programming idiom in computer science is solving a problem by self-reference, also known as recursion. In this post, we look at two different implementations of the same problem.

Solve a recursive problem in two different programming language paradigms

Let’s look at the solution to a simple problem, compute $f(x)=e^{x}$.

We will illustrate two separate solutions - one in a procedural language (python), and the other in a functional language (elixir).

Let’s start off with the functional language. Were does recursion come into play?

We define the function $f(x)=e^x$ as the infinite sum, $\text{ }f(x) = \sum_{n=0}^\infty{\frac{x^n}{n!}}$

In our solution below, we define two separate recursive functions, exp/2 and fac/1. What’s interesting to note here is how each of these functions has two separate definitions. This is an aspect of programming in elixir that elegantly uses pattern-matching to return different results depending upon the input. Our two functions nicely dovetail into the base-case and recursive case of a recursive algorithm.

For example, looking at exp/2, the first function definition returns 1 for any value of x (as indicated by the _ preceding the variable) and returns 1. This is the mathematical equivalent of $x^0=1\text{ for any }x$.

The second definition of exp/2 is the recursive case. for any value of $n\gt0$. Moreover, we define exp(x, n) as $\frac{e^x}{n!}$ + exp(x, n-1).

Similarly for the definition of fac/1 we see two definitions; one for $n=0$ and another for all values of $n\gt0$.

Continue reading

Visualizing the News: Grab your PILlow

2017-11-12 python programming
A Picture’s Worth a Gazillion Bits newsapi This weekend, I tripped over a neat news REST-ful api called newsapi. Grab an API key and you’re off to the races. There are tons of live headlines - News API can provide headlines from 70 worldwide sources. There are basically two api endpoints: GET https://newsapi.org/v1/articles GET https://newsapi.org/v1/sources Register for an account and generate an api-key and let’s get started. Accessing the API with Python newsapi can easily be accessed using a browser since the REST-ful method used is a GET method. Continue reading
Older posts