Skip to content

Instantly share code, notes, and snippets.

View enfiskutensykkel's full-sized avatar

Jonas Markussen enfiskutensykkel

View GitHub Profile
@enfiskutensykkel
enfiskutensykkel / reverse.c
Last active December 7, 2017 15:17
Read all words in a file (separated by space, tab or newline), find the longest 10 words, reverse them and print them out alphabetically.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifndef NUM_WORDS
#define NUM_WORDS 10
#endif
#ifndef CHUNK_SIZE
@enfiskutensykkel
enfiskutensykkel / reboot.py
Created July 18, 2017 16:20
Trigger a powercycle for SV1108IPPOW
#!/usr/bin/env python
import requests
from datetime import datetime as dt
import time
import re
ipaddr = '192.168.0.1'
#ipaddr = '192.168.0.60'
now = dt.utcnow()
#include <iostream>
#include <string>
#include <iterator>
#include <vector>
template <typename T>
struct reversed
{
T& iterable;
#!/bin/bash
max=20
prefix=$1
unique=$$-$(date +%s | base64)
askpass=./sshpass-${unique}
run_command() {
DISPLAY=nothing:0 SSH_ASKPASS=${askpass} setsid ssh -oStrictHostKeyChecking=no -t ${superuser}@$1 "$2" 2> /dev/null
}
@enfiskutensykkel
enfiskutensykkel / simd_shift.c
Created November 28, 2017 12:06
Shift array using SSE intrinsics
#include <tmmintrin.h>
#include <stdio.h>
#include <stdint.h>
#include <stddef.h>
#include <time.h>
static uint64_t current_time()
{
struct timespec ts;
#include <stddef.h>
#include <stdlib.h>
#include <stdio.h>
struct __attribute__((packed)) class_object
{
// TODO* handle
void *super;
void (*destructor)(void*, void*);
@enfiskutensykkel
enfiskutensykkel / Fizzbuzz.js
Last active December 31, 2017 14:07
Functional FizzBuzz in JavaScript
Array.prototype.append = function (element) {
this.push(element);
return this;
};
range = (length) => {
return (function range() {
if (this.length < length) {
this.push(this.length);
#include <type_traits>
template <typename T, typename = std::enable_if_t<std::is_compound_v<T>>>
constexpr T sum(const T& v) noexcept
{
return v;
}
@enfiskutensykkel
enfiskutensykkel / bandwidth.cu
Created May 24, 2019 16:17
Simple program for measuring GPU bandwidth
#include <cuda.h>
#include <stdexcept>
#include <string>
#include <vector>
#include <memory>
#include <cstdint>
#include <cstdio>
#include <unistd.h>
using error = std::runtime_error;
@enfiskutensykkel
enfiskutensykkel / Makefile
Last active June 20, 2019 09:58
Makefile Sieve of Eratosthenes
### List operators
slice = $(wordlist 2,$(words $1),$1)
replicate = $(if $(call eq,$(words $4),$1),$3,$(call replicate,$1,$2,$3 $2,$(words $4) $4))
rotate = $(call slice,$1) $(firstword $1)
map = $(if $2,$(call map,$1,$(call slice,$2),$3,$4 $(call $1,$3,$(firstword $2),$4)),$4)
fold = $(if $2,$(call fold,$1,$(call slice,$2),$(call $1,$3,$(firstword $2))),$3)
zip = $(if $2,$(call zip,$1,$(call slice,$2),$(call rotate,$3),$4 $(call $1,$(firstword $2),$(firstword $3))),$4)
### Arithmetic operators
inc = $(words $(call replicate,$1,_) _)