Skip to content

Instantly share code, notes, and snippets.

View nicolasnoble's full-sized avatar
😪
I may be slow to respond.

Nicolas Noble nicolasnoble

😪
I may be slow to respond.
View GitHub Profile
@nicolasnoble
nicolasnoble / build-md-drives-data.sh
Created October 26, 2022 16:41
Script to easily display Linux raid S.M.A.R.T. status
#!/bin/bash
if [ -z "$1" ] ; then
dev=/dev/md0
else
dev=$1
fi
mdadm --detail $dev |
awk ' h == 1 { print $0; } /Number.*Major.*Minor.*RaidDevice.*State/ { h = 1; } ' |
@nicolasnoble
nicolasnoble / testme.c
Created September 16, 2022 04:48
Weird Lua garbage collector behavior.
#include <stdio.h>
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
static int outergc(lua_State *L) {
void * n = lua_touserdata(L, lua_upvalueindex(1));
void * o = lua_touserdata(L, -1);
printf("Outer gc called on %p with upvalue = %p\n", o, n);
@nicolasnoble
nicolasnoble / sector-prober.c
Created March 24, 2021 18:01
Sector prober
#include <stdint.h>
#include <stdio.h>
static inline uint8_t from_BCD(uint8_t x) { return ((x & 0x0f) + ((x & 0xf0) >> 4) * 10); }
static inline uint32_t from_MSF(uint8_t m, uint8_t s, uint8_t f) {
return (from_BCD(m) * 60 + from_BCD(s)) * 75 + from_BCD(f);
}
static void probe_sector(const uint8_t* sector, unsigned expected_lba) {
// do we have a sync pattern?
@nicolasnoble
nicolasnoble / WORKSPACE
Created August 10, 2020 21:51
Empty WORKSPACE file for grpc
workspace(name = "grpc_example")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "com_github_grpc_grpc",
sha256 = "bbc8f020f4e85ec029b047fab939b8c81f3d67254b5c724e1003a2bc49ddd123",
strip_prefix = "grpc-d8f4928fa779f6005a7fe55a176bdb373b0f910f",
urls = ["https://github.com/grpc/grpc/archive/d8f4928fa779f6005a7fe55a176bdb373b0f910f.tar.gz"],
)
'use strict'
const {promisify} = require('util')
const download = promisify(require('download-git-repo'))
const fs = require('fs')
const glob = promisify(require('glob'))
const yaml = require('js-yaml')
const data = []
class DiscreteCos {
public:
DiscreteCos() { generate(); }
static const unsigned int DC_2PI = 2048;
static const unsigned int DC_PI = 1024;
static const unsigned int DC_PI2 = 512;
int32_t cos(unsigned int t) {
t %= DC_2PI;
int32_t r;
class DiscreteCos {
public:
DiscreteCos() { generate(); }
static const unsigned int DC_2PI = 2048;
static const unsigned int DC_PI = 1024;
static const unsigned int DC_PI2 = 512;
int32_t cos(unsigned int t) {
t %= DC_2PI;
int32_t r;
#define NOMINMAX
#define _CRT_SECURE_NO_WARNINGS
#ifdef _WIN32
#define WIN32LEANANDMEAN
#include <windows.h>
#endif
#include <assert.h>
#include <ctype.h>
#include <stdint.h>
const github = require('octonode')
const repoName = /* repository name */
const client = github.client(/* user token */)
const repo = client.repo(repoName)
async function migrateAll() {
let page = 1
while (true) {
const prsResult = await repo.prsAsync({page: page, state: 'open'})
@nicolasnoble
nicolasnoble / gen-data.c
Created September 3, 2018 03:49
Generate random, yet compressible data.
static void gen_pre_buf(uint8_t * pre_buf, uint8_t (*get_byte)(void *), void * opaque) {
int i;
memset(pre_buf, 0, 1024);
for (i = 0; i < 256; i++) {
pre_buf[i + 256] = i;
pre_buf[i * 2 + 512] = i;
}