Skip to content

Instantly share code, notes, and snippets.

View larsch's full-sized avatar

Lars Christensen larsch

View GitHub Profile
cmake_minimum_required(VERSION 2.8.11)
# Specify the project name. Not required for subprojects, but it
# will create a dingbat.sln for Visual Studio, which will only
# contain the dingbat project and its dependencies.
project(dingbat)
# Create variables with source and header files. Nice to have if we
# need them as arguments to custom macros.
set(sources dingbat.cpp)
option(WITH_VLD "With Visual Leak Detection" OFF)
if(WITH_VLD AND MSVC)
message("Enabling Visual Leak Detector")
find_library(VLD vld
HINTS "c:/Program Files (x86)/Visual Leak Detector/lib/Win32" "c:/Program Files/Visual Leak Detector/lib/Win32")
find_file(VLD_H vld.h
HINTS "c:/Program Files (x86)/Visual Leak Detector/include" "c:/Program Files/Visual Leak Detector/include")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /FIwinsock2.h")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \"/FI${VLD_H}\"")
get_filename_component(VLD_LIBRARY_DIR "${VLD}" PATH)
@larsch
larsch / human_size.rb
Created September 22, 2014 04:02
Number to human file size conversion (IEC units)
def human_size(n)
return "0 B" if n.zero?
sizes = %w{B KiB MiB GiB TiB PiB EiB ZiB YiB}
x = (Math.log(n) / Math.log(1024)).floor
n = n / (1024.0 ** x)
n = n.round(2)
n = n.to_i if n.round == n
"#{n} #{sizes[x]}"
end
@larsch
larsch / create-arch-image-raspberry-pi-2.sh
Last active March 11, 2024 13:55
Shell script that creates a Arch Linux image for the Raspberry Pi 2. Downloads the latest distribution from archlinuxarm.org and creates the flash filesystems including boot partition. Partitions are aligned for typical SD cards and ext filesystem tuned accordingly.
#!/bin/sh -ex
losetup /dev/loop0 && exit 1 || true
image=arch-linux-$(date +%Y%m%d).img
wget -q -N http://archlinuxarm.org/os/ArchLinuxARM-rpi-2-latest.tar.gz
truncate -s 1G $image
losetup /dev/loop0 $image
parted -s /dev/loop0 mklabel msdos
parted -s /dev/loop0 unit s mkpart primary fat32 -- 1 65535
parted -s /dev/loop0 set 1 boot on
parted -s /dev/loop0 unit s mkpart primary ext2 -- 65536 -1
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
void* thread_routine(void* param) {
printf("I'm running\n");
}
#define CP(x) \
{ int r = (x); \
  1. Partion the disk
parted /dev/sda
mklabel gpt
mkpart ext2 1 3
set 1 bios_grub on
mkpart ext2 3 131
mkpart ext4 131 -1
  1. Create the file systems

Update package index and upgrade all installed packaged

pacman -Syu

(S = sync, y = update, u = upgrade installed)

Install packages from AUR:

#!/bin/sh -ex
sudo pacman -Sy base-devel --needed --noconfirm
curl -O https://aur.archlinux.org/packages/pa/package-query/package-query.tar.gz
tar xfz package-query.tar.gz -C /tmp
pushd /tmp/package-query
makepkg --noconfirm -sf
sudo pacman -U --noconfirm package-query-*.pkg.tar.xz
popd
curl -O https://aur.archlinux.org/packages/ya/yaourt/yaourt.tar.gz
tar xfz yaourt.tar.gz -C /tmp
#!/bin/sh -ex
sudo pacman --needed --noconfirm -S base-devel
curl -LO https://github.com/larsch/libbcm2835-aur/archive/v1.42-1.tar.gz
tar xfz v1.42-1.tar.gz
cd libbcm2835-aur-1.42-1
makepkg -sf
sudo pacman --noconfirm -U libbcm2835*.pkg.tar.xz
curl -LO https://aur.archlinux.org/packages/ra/raspi-off-button/raspi-off-button.tar.gz
@larsch
larsch / list-installed-arch.sh
Last active December 26, 2016 14:46
List packaged installed in Arch Linux (except base/base-devel)
comm -23 <(pacman -Qq|sort) <(pacman -Qqg base base-devel|xargs -n1 pactree -ul|sort -u)