Skip to content

Instantly share code, notes, and snippets.

@theKAKAN
theKAKAN / getDirection.js
Created February 14, 2021 17:09
Convert degrees or angles to cardinal direction
function getDirection( angle ){
// We divide it into 16 sections
let directions = ["N","NNE","NE","ENE","E",
"ESE", "SE", "SSE","S",
"SSW","SW","WSW","W",
"WNW","NW","NNW" ];
// This means, every 360 / 16 degree, there's a section change
// So, in our case, every 22.5 degree, there's a section change
// In order to get the correct section, we just need to divide
let section = parseInt( angle/22.5 + 0.5 );
@drernie
drernie / csvtomap.go
Created March 10, 2017 22:48
Golang Convert CSV Records to Dictionaries using Header Row as Keys
// CSVToMap takes a reader and returns an array of dictionaries, using the header row as the keys
func CSVToMap(reader io.Reader) []map[string]string {
r := csv.NewReader(reader)
rows := []map[string]string{}
var header []string
for {
record, err := r.Read()
if err == io.EOF {
break
}
@edro15
edro15 / SynchNTPtoGPS.md
Created February 13, 2018 16:45
[How To] Synchronize NTP server to a GPS/PPS source

So, I want to have a GPS Receiver driving a PPS (pulse-per-second) signal to the NTP server for a highly accurate time reference service.

Introduction

There are at least a couple of ways to propagate the PPS signal to the ntpd (NTP daemon) service, plus some variants in each case. However, the GPS device must be seen as a device that sources two different types of data:

  • the absolute date and time, and
  • the 1Hz clock signal (PPS).

The first one provides the complete information (incl. date and time) about when now is, but with poor accuracy because data is sent over the serial port and then encoded using a specific protocol such as NMEA (National Marine Electronics Association). PPS provides instead a very accurate clock but without any reference to absolute time.

@geohot
geohot / hip.py
Created November 25, 2023 23:28
Wrapper for HIP
# -*- coding: utf-8 -*-
#
# TARGET arch is: ['-D__HIP_PLATFORM_AMD__', '-I/opt/rocm/include']
# WORD_SIZE is: 8
# POINTER_SIZE is: 8
# LONGDOUBLE_SIZE is: 16
#
import ctypes
[55883.721977] amdgpu: map VA 0x702eae9d2000 - 0x702eae9d3000 in entry 0000000072d2b750
[55883.721996] amdgpu: INC mapping count 1
[55883.722133] kfd kfd: amdgpu: ioctl cmd 0xc0184b0c (#0xc), arg 0x7ffe16172bef
[55883.722238] gmc_v11_0_process_interrupt: 6 callbacks suppressed
[55883.722250] amdgpu 0000:c3:00.0: amdgpu: [gfxhub] page fault (src_id:0 ring:24 vmid:8 pasid:32774, for process python3 pid 356134 thread python3 pid 356134)
[55883.722343] amdgpu 0000:c3:00.0: amdgpu: in page starting at address 0x00000000aabbc000 from client 10
[55883.722391] amdgpu 0000:c3:00.0: amdgpu: GCVM_L2_PROTECTION_FAULT_STATUS:0x00800A30
[55883.722429] amdgpu 0000:c3:00.0: amdgpu: Faulty UTCL2 client ID: CPC (0x5)
[55883.722466] amdgpu 0000:c3:00.0: amdgpu: MORE_FAULTS: 0x0
[55883.722497] amdgpu 0000:c3:00.0: amdgpu: WALKER_ERROR: 0x0
@geohot
geohot / llm.c
Last active April 26, 2024 12:54
Outputted llm.c from tinygrad
#include <stdlib.h>
#include <stdbool.h>
#include <tgmath.h>
#define max(x,y) ((x>y)?x:y)
#define half __fp16
void E_(int* data0) {
int val0 = data0[0];
data0[0] = (val0+1);
}
@Steveplays28
Steveplays28 / distant_horizons_shader_compatibility_information.md
Last active April 26, 2024 12:53
Distant Horizons shader compatibility info

Distant Horizons shader compatibility information

Distant Horizons v2.0.0 (and up) shader compatibility information.

v2

Prerequisites

  • Iris v1.7.0 or higher, or Oculus v1.6.15aDH or higher
  • Distant Horizons v2.0.2a or higher
@ardakazanci
ardakazanci / Bar.kt
Created April 24, 2024 15:49
Bar with JetpackCompose
data class BarDataM(val value: Float, val label: String)
@Composable
fun BarChartComponent(
bars: List<BarDataM>,
barWidth: Dp,
spaceBetweenBars: Dp,
animateChart: Boolean
) {
var selectedBar by remember { mutableIntStateOf(-1) }
@Xunnamius
Xunnamius / cloudflare.conf
Last active April 26, 2024 12:52
Fail2ban action.d for Cloudflare meant to replace the version that ships with fail2ban currently. This updated version of the action uses Cloudflare's 2023 v4 API (free tier WAF + free tier WAF lists) to ban hostile IPs.
# This version works with CF WAF (using zone rulesets) and obsoletes previous
# versions. This works will all CF account types. This action depends on curl
# and jp and will add/remove IPs from the $known_hostile_ips list. Creating the
# WAF rules need only be done once per zone. Creating the list need only be done
# once per account.
#
# Author: Bernard Dickens III (Xunnamius)
#
# Inspired by work from: Mike Rushton
# https://github.com/fail2ban/fail2ban/blob/master/config/action.d/cloudflare.conf
@mccutchen
mccutchen / github-graphql-examples.md
Last active April 26, 2024 12:51
A couple of ways to look up a GitHub pull request via the v4 GraphQL API

GitHub GraphQL API v4 Examples

Here are two queries that look up information about a pull request via GitHub's GraphQL API v4. The first looks up a pull request by number, the second looks up a pull request by ref (i.e. commit hash, branch name, tag name).

Why tho

While it is trivial to use the RESTful v3 API to look up a pull request by number, the GraphQL API is the only way to do the same thing for an arbitrary reference in a single HTTP request.

These took a bit of trial and error in the GitHub's GraphQL Explorer and various support threads to get right, so I'm putting them up here for posterity.