In short, a decorator takes in a function, adds some functionality and returns it. This feature in Python is very similar to what is in Ruby. You open up a class and add feature to it - monkey patching. Python has an interesting feature called decorators to add functionality to an existing code. This is … Continue reading Python Decorators
Computing
*args and **kwargs in Python
In Python, there are two special symbols that you can use when defining functions to allow them to take in a variable number of arguments. The syntax is to use the symbol * to take in a variable number of arguments; by convention, it is often used with the word args. What *args allows you … Continue reading *args and **kwargs in Python
Captcha if you can: how you’ve been training AI for years without realising it
All those little visual puzzles add up to AI advances Congratulations are in order. You, yes you, dear reader, have been part of something incredible. Thanks to your hard work, millions of books containing pretty much the sum-total of human knowledge have been successfully digitised, saving their texts for future generations. All because of you. … Continue reading Captcha if you can: how you’ve been training AI for years without realising it
MJIT: A Method Based Just-in-time Compiler for Ruby
Those of you who are already familiar with JITs and how they work might want to skip directly to the interview, the rest of us are going to hang out for a minute and learn about how things presently work in Ruby, and what it is exactly that the MJIT would change. How does a … Continue reading MJIT: A Method Based Just-in-time Compiler for Ruby
What’s the difference between using “let” and “var” to declare a variable in JavaScript?
ECMAScript 6 introduced the let statement. The difference is scoping. var is scoped to the nearest function block and let is scoped to the nearest enclosing block, which can be smaller than a function block. Both are global if outside any block. Also, variables declared with let are not accessible before they are declared in … Continue reading What’s the difference between using “let” and “var” to declare a variable in JavaScript?
Making async http requests with python-aiohttp
In this post I’d like to test limits of python aiohttp and check its performance in terms of requests per minute. Everyone knows that asynchronous code performs better when applied to network operations, but it’s still interesting to check this assumption and understand how exactly it is better and why it’s is better. I’m going … Continue reading Making async http requests with python-aiohttp
Embracing Change: Rails 5.1 Adopts Yarn, Webpack, and the JS Ecosystem
For many years, Ruby on Rails has been the go-to framework for startups, micropreneurs, SMBs, and really for anyone who needed to build and launch a tool quickly. With its opinionated, convention over configuration approach, and Heroku’s brilliant git push to deploy feature, Ruby on Rails made every other solution look barbaric by comparison. But … Continue reading Embracing Change: Rails 5.1 Adopts Yarn, Webpack, and the JS Ecosystem
A short summary of centrality in graph theory
A short summary of mathematics of networks (in particular, centrality). In graph theory and network analysis, indicators of centrality identify the most important vertices within a graph. Applications include identifying the most influential person(s) in a social network, key infrastructure nodes in the Internet or urban networks, and super-spreaders of disease. Centrality concepts were first … Continue reading A short summary of centrality in graph theory
How to rename all files in a folder using Python
let's assume the folder is user_data, relative to the current working directory (where the Python script is in). The code below was tested on Windows. import os for filename in os.listdir("./user_data"): # print(filename) cwd = os.path.dirname(os.path.abspath(__file__)) + '\\user_data\\' if filename.split('.')[1] == 'jpg': new_filename = filename.split('.')[0] + '_search' + '.jpg' print(new_filename) … Continue reading How to rename all files in a folder using Python
class << self in Ruby
First, the class << foo syntax opens up foo's singleton class (eigenclass). This allows you to customize the behavior of methods called on that specific object. a = 'foo' class << a def inspect '"bar"' end end a.inspect # => "bar" a = 'foo' # new object, new singleton class a.inspect # => "foo" ow, … Continue reading class << self in Ruby