let mut block_buffer_ref = CMSampleBufferGetDataBuffer(self);
let layout = alloc::Layout::from_size_align(buffer_size, 16).unwrap();
let audio_buffer_list_ptr = alloc::alloc(layout);
let result = CMSampleBufferGetAudioBufferListWithRetainedBlockBuffer(
self,
null_mut(),
audio_buffer_list_ptr as _,
buffer_size,
null_mut(),
null_mut(),
kCMSampleBufferFlag_AudioBufferList_Assure16ByteAlignment,
&mut block_buffer_ref,
);
CFRelease(block_buffer_ref as _);
if result != 0 {
panic!()
}
let audio_buffer_list_ptr = audio_buffer_list_ptr as *mut AudioBufferList;
let audio_buffer_list = unsafe { *audio_buffer_list_ptr };
let number_buffers = audio_buffer_list.number_buffers;
let mut buffers = Vec::new();
for i in 0..audio_buffer_list.number_buffers {
let audio_buffer = audio_buffer_list.buffers[i as usize];
buffers.push(CopiedAudioBuffer {
number_channels: number_buffers,
data: unsafe {
std::slice::from_raw_parts(audio_buffer.data, audio_buffer.data_bytes_size as usize)
}.to_vec(),
});
}
buffers
import java.io.BufferedReader
import java.io.InputStreamReader
class WindowNameCollector {
data class WindowState(val processName: String, val processId: String, val bundleId: String, val windowName: String)
fun getWindowStateList(): List<WindowState> {
val windowListString = getWindowListString()
return parseWindowState(windowListString)
}
private fun parseWindowState(input: String): List<WindowState> {
// Regex pattern for matching the input string.
val pattern = """Process: '(.+?)', PID: '(.+?)', Bundle ID: '(.+?)', Window: '(.+?)'""".toRegex(RegexOption.DOT_MATCHES_ALL)
// Try to find a match in the input string.
val matchResults = pattern.findAll(input)
return matchResults.map { matchResult ->
val (processName, processId, bundleId, windowName) = matchResult.destructured
WindowState(processName, processId, bundleId, windowName)
}.toList()
}
private fun getWindowListString(): String {
val script = """
tell application "System Events"
set procs to processes
set results to ""
repeat with proc in procs
if exists (window 1 of proc) then
repeat with w in windows of proc
set results to results & "Process: '" & name of proc & "', PID: '" & unix id of proc & "', Bundle ID: '" & bundle identifier of proc & "', Window: '" & name of w & "'\n"
end repeat
end if
end repeat
return results
end tell
""".trimIndent()
val pb = ProcessBuilder("osascript", "-e", script)
val p = pb.start()
val lines = BufferedReader(InputStreamReader(p.inputStream)).use { reader ->
reader.readText()
}
val exitStatus = p.waitFor() // Wait for the process to finish.
if (exitStatus != 0) {
throw RuntimeException("Failed to execute osascript. Exit status: $exitStatus")
}
return lines
}
}
import java.text.NumberFormat
import java.util.Locale
fun main() {
val number = 1000000
val formattedNumber = NumberFormat.getNumberInstance(Locale.getDefault()).format(number)
println(formattedNumber) // 結果: 1,000,000
}
import toml
import os
import re
from collections import defaultdict
def scan_files(root_dir):
usage_counts = defaultdict(int)
for subdir, _, files in os.walk(root_dir):
for file in files:
if file.endswith('.gradle.kts'):
with open(os.path.join(subdir, file), 'r') as f:
content = f.read()
for match in re.finditer(r'libs\.([a-zA-Z0-9._-]+)', content):
library = match.group(1).replace('.', '-')
usage_counts[library] += 1
return usage_counts
def main():
# TOML ファイルを読み込む
with open('gradle/libraries.versions.toml', 'r') as f:
toml_data = toml.load(f)
libraries = toml_data['libraries']
usage_counts = scan_files('.')
# すべてのライブラリに対して使用状況をチェックする
for library in libraries.keys():
usage_count = usage_counts[library]
unused_indicator = ' (*)' if usage_count == 0 else ''
print(f'{usage_count} {library}{unused_indicator}')
if __name__ == "__main__":
main()
%use lets-plot
val max = 1000000
val rates = mutableListOf<Double>()
var nabeatsu = 0
for (i in 0..max) {
if (i % 3 == 0 || i.toString().contains('3')) {
nabeatsu += 1
}
val r = nabeatsu.toDouble() / i.toDouble()
if (r.isInfinite()) {
rates.add(1.0)
} else {
rates.add(r)
}
}
val data = mapOf(
"x" to 0..max,
"nabeatsu-rate" to rates
)
var p = letsPlot(data)
p += geomLine() { x = "x"; y = "nabeatsu-rate" }
p + ggsize(700, 350)
import os
import sys
import subprocess
import difflib
import zipfile
import subprocess
import tempfile
from pathlib import Path
def get_git_commit_hash(directory):
"""Return the latest git commit hash of the specified directory."""
try:
commit_hash = subprocess.check_output(['git', '-C', directory, 'rev-parse', 'HEAD']).decode('utf-8').strip()
return commit_hash
except subprocess.CalledProcessError:
print(f"Error: Failed to retrieve git commit hash for {directory}")
sys.exit(1)
def get_jar_files(directory):
"""Return a list of jar files in the specified directory."""
basedir = Path(directory)
return [f.relative_to(basedir) for f in basedir.rglob("*.jar") if f.is_file()]
def are_jars_identical(jar1_path, jar2_path):
"""Check if the contents of the two JAR files are identical and display unified diff for .html files if they're different."""
def is_binary(content):
"""Determine if the given content is binary."""
return b'\x00' in content
def get_javap_output(class_file_path):
"""Get the bytecode dump using javap."""
try:
output = subprocess.check_output(['javap', '-verbose', '-c', class_file_path], stderr=subprocess.STDOUT)
return output.decode('utf-8')
except subprocess.CalledProcessError as e:
return str(e)
with zipfile.ZipFile(jar1_path, 'r') as jar1, zipfile.ZipFile(jar2_path, 'r') as jar2:
jar1_files = set(jar1.namelist())
jar2_files = set(jar2.namelist())
if jar1_files != jar2_files:
return False, "File lists are different"
for file_name in sorted(jar1_files):
with jar1.open(file_name) as file1, jar2.open(file_name) as file2:
file1_contents = file1.read()
file2_contents = file2.read()
if file1_contents != file2_contents:
# If the files are .html and not binary, display the unified diff
if file_name.endswith('.class'):
# If the files are .class files, get the javap output and compare
with tempfile.NamedTemporaryFile(suffix='.class', delete=True) as tmp1, tempfile.NamedTemporaryFile(suffix='.class', delete=True) as tmp2:
tmp1.write(file1_contents)
tmp2.write(file2_contents)
tmp1.flush()
tmp2.flush()
javap_output1 = get_javap_output(tmp1.name)
javap_output2 = get_javap_output(tmp2.name)
diff = difflib.unified_diff(
javap_output1.splitlines(),
javap_output2.splitlines(),
fromfile=f"{jar1_path}/{file_name}",
tofile=f"{jar2_path}/{file_name}"
)
return False, file_name + "\n" + "\n".join(diff)
elif file_name.endswith('.html') and not is_binary(file1_contents) and not is_binary(file2_contents):
diff = difflib.unified_diff(
file1_contents.decode().splitlines(),
file2_contents.decode().splitlines(),
fromfile=f"{jar1_path}/{file_name}",
tofile=f"{jar2_path}/{file_name}"
)
return False, "\n".join(diff)
return False, f"File contents are different: {file_name}"
return True, ""
def main():
if len(sys.argv) != 3:
print("Usage: script_name directory1 directory2")
sys.exit(1)
dir1, dir2 = sys.argv[1], sys.argv[2]
# Display git commit hashes for both directories
commit_hash_dir1 = get_git_commit_hash(dir1)
commit_hash_dir2 = get_git_commit_hash(dir2)
print(f"Git commit hash for directory 1: {dir1} {commit_hash_dir1}")
print(f"Git commit hash for directory 2: {dir2} {commit_hash_dir2}\n\n\n")
jar_files_dir1 = set(get_jar_files(dir1))
jar_files_dir2 = set(get_jar_files(dir2))
common_jar_files = jar_files_dir1.intersection(jar_files_dir2)
for jar_file in common_jar_files:
if "-sources.jar" in str(jar_file):
continue
file1_path = os.path.join(dir1, jar_file)
file2_path = os.path.join(dir2, jar_file)
is_same, reason = are_jars_identical(file1_path, file2_path)
if not is_same:
print(f"## {jar_file} has different contents.")
print(reason)
print("\n\n")
else:
#print(f"{jar_file} has the same contents.")
pass
# Report files only in directory 1
unique_files_dir1 = jar_files_dir1 - common_jar_files
for jar_file in unique_files_dir1:
print(f"{jar_file} exists only in directory 1.")
# Report files only in directory 2
unique_files_dir2 = jar_files_dir2 - common_jar_files
for jar_file in unique_files_dir2:
print(f"{jar_file} exists only in directory 2.")
if __name__ == "__main__":
main()