Skip to content

Instantly share code, notes, and snippets.

@thearchitect
thearchitect / deref.rs
Created July 15, 2015 03:49
Golang like defers for Rust
// http://stackoverflow.com/a/29963675/983835
struct ScopeCall<F: FnOnce()> {
c: Option<F>
}
impl<F: FnOnce()> Drop for ScopeCall<F> {
fn drop(&mut self) {
self.c.take().unwrap()()
}
}
#!/bin/bash
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
echo $DIR
package main
import (
"log"
"net"
"time"
)
func perr(err error) {
if err != nil {
#include <opencv2/opencv.hpp>
#include <opencv2/calib3d/calib3d.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
#include <sstream>
#include <string>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>
package main
import (
"bytes"
"fmt"
"os"
"strings"
"github.com/jmoiron/sqlx"
_ "github.com/mattn/go-sqlite3"
# nixos-rebuild switch
building Nix...
building the system configuration...
updating GRUB 2 menu...
activating the configuration...
setting up /etc...
# add this to configuration.nix
virtualisation = {
libvirtd = {
{ config, lib, pkgs, ... }:
let
cfg = {
hostName = "zion";
ceph = {
enable = true;
publicIP = "127.0.0.1";
privateIP = "127.0.0.1";
@thearchitect
thearchitect / ffmpeg-cheatsheet.md
Created September 11, 2018 06:50 — forked from nickkraakman/ffmpeg-cheatsheet.md
FFmpeg cheat sheet for 360 video

FFmpeg Cheat Sheet for 360º video

Brought to you by Headjack

 
FFmpeg is one of the most powerful tools for video transcoding and manipulation, but it's fairly complex and confusing to use. That's why I decided to create this cheat sheet which shows some of the most often used commands.

 
Let's start with some basics:

  • ffmpeg calls the FFmpeg application in the command line window, could also be the full path to the FFmpeg binary or .exe file
@thearchitect
thearchitect / scan.sh
Created October 21, 2018 13:09 — forked from kirkins/scan.sh
Second version of script to turn nmcli into a json object
#!/usr/bin/env bash
#
# Scan availible wifi networks
# https://unix.stackexchange.com/questions/399222/jq-parse-colon-separated-value-pairs
# TODO see if you can pipe this directly into jq
nmcli_output=$(nmcli --mode multiline dev wifi)
# set all variables from nmcli
network=$(echo "$nmcli_output" | grep SSID: \
@thearchitect
thearchitect / create-hotspot.md
Created October 21, 2018 13:09 — forked from narate/create-hotspot.md
Create Wi-Fi Hotspot on Linux using nmcli

Create a Wi-Fi hotspot on Linux using nmcli

Original post : https://unix.stackexchange.com/a/310699

nmcli con add type wifi ifname wlan0 con-name Hostspot autoconnect yes ssid Hostspot
nmcli con modify Hostspot 802-11-wireless.mode ap 802-11-wireless.band bg ipv4.method shared
nmcli con modify Hostspot wifi-sec.key-mgmt wpa-psk
nmcli con modify Hostspot wifi-sec.psk "veryveryhardpassword1234"