Skip to content

Instantly share code, notes, and snippets.

@baniol
baniol / adduser.sh
Last active March 28, 2024 17:55
Create a new user in osx, mac, terminal, bash
#!/bin/bash
# =========================
# Add User OS X Interactive Command Line
# =========================
# http://superuser.com/questions/202814/what-is-an-equivalent-of-the-adduser-command-on-mac-os-x
getHiddenUserUid()
{
local __UIDS=$(dscl . -list /Users UniqueID | awk '{print $2}' | sort -ugr)
@baniol
baniol / canvas_animation.html
Created March 29, 2014 09:54
basic canvas animation, javascript, requestAnimationFrame, solar system
<html>
<head>
<style type="text/css">
/*canvas{ width: 300px; height: 300px;}*/
</style>
</head>
<body>
<canvas id="canvas" width="300" height="300"></canvas>
@baniol
baniol / bubbletea.go
Created December 2, 2022 15:44
basic structure for bubbletea
package main
import (
"fmt"
tea "github.com/charmbracelet/bubbletea"
"os"
)
func main() {
@baniol
baniol / keybindings.json
Last active November 10, 2022 19:19
Toggle inlay hints vsc
{
"key": "alt+f", // key to press to activate command
"command": "settings.cycle", // `settings.cycle` is the command that's actually being run, from the extension `hoovercj.vscode-settings-cycler`
"when": "editorTextFocus && editorLangId == 'rust'", // this keybinding is only active when (editor is in focus) and (the language is `rust`)
"args": { // these are the arguments passed to `settings.cycle`
"id": "rust-toggle-inlay-hints", // must be unique
"overrideWorkspaceSettings": true,
"values": [ // Note: use the same settings in each values object
{
"rust-analyzer.inlayHints.enable": false // sets the inlay hints off
@baniol
baniol / mongodb_backup.md
Last active August 15, 2022 18:58
MongoDB automatic backup

Maintaining even a small mongodb application in production requires regular backups of remotely stored data. MongoDB gives you three ways to acomplish it. In this post I'm using monogodump command for creating a backup and mongorestore for recreating the data. The purpose of this writing is to provide a simple way of periodic database dumps from a remote server to a Dropbox cloud storage.

Remember that for using mongodump you have to have a mongod process running.

Dumping a database

Suppose that you want make a backup of your books database.

To create a dump use mongodump -d books -o which will result in a book folder containing bson files with all collections.

@baniol
baniol / centos_vb.md
Last active July 19, 2021 22:20
Centos on Mac with Virtual Box

If you want to learn how to administer a Linux server or have a need to test your application on a specific Linux distribution, a good point of start is to virtualize it locally using VirtualBox. This post explains how get CentOS up and running on OS X. Our goal here is to install minimal Linux server and access it for administration via ssh from your Host operating system. We will also enable the Guest system to act like a web server.

If you don't have VirtualBox already go to download page and install it.

To get an image of CentOS go here and choose the version you want (I went for 6.5) by clicking on x86_64 then pick one of the mirror servers for downloading the desired image (my choice was CentOS-6.5-x86_64-minimal.iso).

Instalation steps.

Run VirtualBox

  • Clik New.
@baniol
baniol / transform.js
Created May 18, 2014 17:14
nodejs stream transform, uppercase
var Transform = require('stream').Transform;
/// Server:
var server = require('net').createServer();
function onConnection(socket) {
/// Create the transform stream:
var uppercase = new Transform({
@baniol
baniol / 03-async-api.md
Last active January 16, 2019 08:35
React/Redux async api requests

React Redux Walkthrough, part 3

Asynchronous API requests

So far, our application gets data from a hardcoded collection passed as a default state to the employees reducer function. However, for most of the web applications data should be loaded asyncronously from a remote server. The goal of this part is to provide this functionality with proper unit tests.

The application source code

switch to the 03-asyn-api branch and run npm install.

@baniol
baniol / 01-introduction.md
Last active January 16, 2019 08:35
React-Redux general architecture

React-Redux Walkthrough

Introduction to the series

The purpose of this series is to provide a reader with an insight into the data flow in Redux applications and how React components fit into it. To illustrate the Redux architecture we will build a simple application - a list of employees filterable by position.

Each part of the series is going to have a separate branch in the repository.

We'll start with a simple static data collection, progressively adding features and tools such as unit tests, async API calls, debugging tools routing and middleware.

@baniol
baniol / 02-unit-testing.md
Last active January 16, 2019 08:35
React/Redux unit testing

React Redux Walkthrough, part 2

Unit testing

I the first part of the series we learned what are the main React/Redux building blocks and how they interact to provide an easy to read and consistent data flow. Before we go further with the development it's a good time to take a step back and see how we can test the code written so far.

The code for the application can be found here - checkout to the 02-unit-testing branch and run npm install.

Note a few changes in the package.json file: