This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <ruby.h> | |
#include <sstream> | |
#include <string> | |
class StringIO { | |
private: | |
std::ostringstream oss; | |
public: | |
StringIO() = default; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template <typename T, size_t BitsetSize> | |
std::vector<T> bitsetToVector(const std::bitset<BitsetSize>& bitset, size_t bitsPerElement = sizeof(T) * 8) { | |
static_assert(std::is_unsigned<T>::value, "Output vector type must be an unsigned integer type."); | |
static_assert(BitsetSize % (sizeof(T) * 8) == 0, "Bitset size must be a multiple of the element size."); | |
size_t numElements = BitsetSize / bitsPerElement; // Calculate number of elements in the output vector | |
std::vector<T> result(numElements); | |
for (size_t i = 0; i < numElements; ++i) { | |
T value = 0; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Shim for Rails 6.1 to ease upgrading to 7.1 | |
return if defined? ActiveSupport::BroadcastLogger | |
module ActiveSupport | |
class BroadcastLogger < SimpleDelegator | |
def initialize(*loggers) | |
logger = loggers.shift | |
super(logger) | |
loggers.each { |l| logger.extend(ActiveSupport::Logger.broadcast(l)) } | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import os | |
def generate_header_file(input_file): | |
# Read binary data from input file | |
with open(input_file, "rb") as f: | |
data = f.read() | |
# Create header file name |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Controller } from '@hotwired/stimulus' | |
import { TempusDominus } from '@eonasdan/tempus-dominus' | |
// Connects to data-controller="datetime" | |
export default class extends Controller { | |
connect() { | |
this.element.classList.add('bg-white') | |
this.element.setAttribute('readonly', true) | |
this.widget = new TempusDominus(this.element, { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'digest' | |
all = Hash.new | |
Dir["*.jpg"].each do |file| | |
md5 = Digest::MD5.hexdigest(IO.read(file)) | |
ary = all.fetch(md5, []) | |
ary << file | |
all[md5] = ary |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def sha512_base64(string) | |
# Compute SHA-512 digest in binary form | |
digest = OpenSSL::Digest::SHA512.digest(string) | |
# Encode the binary digest in base64 | |
base64_encoded = Base64.strict_encode64(digest) | |
"sha512-#{base64_encoded}" | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Chart from 'stimulus-chartjs' | |
// Connects to data-controller="async-chart" | |
export default class extends Chart { | |
static values = { | |
url: String | |
} | |
connect() { | |
fetch(this.urlValue) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ExternalApiRuntime | |
extend ActiveSupport::Concern | |
module ClassMethods | |
def log_process_action(payload) | |
messages = super | |
api_runtime = payload[:api_runtime] | |
messages << (format('ExternalAPI: %.1fms', api_runtime.to_f)) if api_runtime | |
messages | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Controller } from '@hotwired/stimulus' | |
import { TempusDominus } from '@eonasdan/tempus-dominus' | |
function findParentBySelector(element, selector) { | |
while (element && element.parentElement) { | |
if (element.parentElement.matches(selector)) { | |
return element.parentElement; | |
} | |
element = element.parentElement; | |
} |
NewerOlder