Skip to content

Instantly share code, notes, and snippets.

from datetime import datetime
import pytz
import tzlocal
utc_time_string = "2024-07-01T12:00:00"
utc_time = datetime.strptime(utc_time_string, "%Y-%m-%dT%H:%M:%S").replace(
tzinfo=pytz.utc
)
local_time = utc_time.astimezone(tzlocal.get_localzone())
@sharkdp
sharkdp / magic.rs
Last active December 10, 2022 20:26
A demo program to find processes at the other end of a pipe
// For background, see: https://unix.stackexchange.com/questions/405485/name-of-the-process-on-the-other-end-of-a-unix-pipe
use std::ffi::{OsStr, OsString};
use std::fs::{self, File};
use std::io::prelude::*;
use std::io::Result;
use std::os::unix::ffi::OsStrExt;
use std::path::Path;
#[derive(Debug, Clone, Copy)]
@sharkdp
sharkdp / obstgarten.py
Created May 26, 2022 18:48
Win rates for different "strategies" in the childrens game Obstgarten (orchard)
from abc import ABC, abstractmethod
from typing import List
from random import randint
from enum import Enum
Fruits = List[int]
NUM_FRUITS = 4
class PickFruit:
@sharkdp
sharkdp / todo.cpp
Created March 30, 2021 12:59
A todo() macro for C++, inspired by Rusts todo!()
#include <iostream>
struct todo_statement {
public:
todo_statement(const char* file, const int line)
: m_file(file), m_line(line) {}
template <typename T>
operator T() {
std::cerr << "Error: Remove todo() statement in " << m_file << ":" << m_line
@sharkdp
sharkdp / benchmark-just-exit.sh
Created December 12, 2020 09:38
just-exit benchmark
echo "int main() {}" > just-exit.c
gcc -O just-exit.c -o just-exit-c
echo "" > just-exit.py
echo "fn main() {}" > just-exit.rs
rustc -O just-exit.rs -o just-exit-rs
echo "" > just-exit.rb
# Configuration for Alacritty, the GPU enhanced terminal emulator
# Any items in the `env` entry below will be added as
# environment variables. Some entries may override variables
# set by alacritty it self.
env:
# TERM env customization.
#
# If this property is not set, alacritty will set it to xterm-256color.
// Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#!/usr/bin/python
import argparse
import json
import matplotlib.pyplot as plt
parser = argparse.ArgumentParser()
parser.add_argument("results", help="JSON file with benchmark results")
args = parser.parse_args()
#!/bin/bash
# the root directory for the search
base_path="$HOME" # CHANGE THIS
if ! which bench > /dev/null 2>&1; then
echo "'bench' does not seem to be installed."
echo "You can get it here: https://github.com/Gabriel439/bench"
exit 1
fi
#!/bin/bash
trap "tput reset; tput cnorm; exit" 2
clear
tput civis
lin=2
col=$(($(tput cols) / 2))
c=$((col-1))
color=0
tput setaf 2; tput bold