Skip to content

Instantly share code, notes, and snippets.

View imos's full-sized avatar

Kentaro IMAJO imos

View GitHub Profile
@imos
imos / memory_leak.rs
Last active July 17, 2023 11:54
Memory leak in Rust (Create circular reference using Arc/Mutex)
use std::sync::{Arc, Mutex};
struct Data{ data: Option<Arc<Mutex<Data>>> }
fn main() {
for _ in 0..5000000 {
let val = Arc::new(Mutex::new(Data{
data: Some(Arc::new(Mutex::new(Data { data: None })))
}));
let mut child = Arc::new(Mutex::new(Data{ data: None }));
@imos
imos / mutex.cpp
Created October 10, 2016 19:32
Benchmark for std::mutex
#include <math.h>
#include <stdint.h>
#include <sys/time.h>
#include <atomic>
#include <functional>
#include <map>
#include <mutex>
#include <string>
#include <thread>
@imos
imos / measure-gpu-memory-usage.py
Last active May 9, 2019 00:35
Measure GPU memory usage
#!/usr/bin/env python3
# Usage: measure-gpu-memory-usage.py command args...
import cupy
import subprocess
import sys
initial_memory = None
for device_id in range(cupy.cuda.runtime.getDeviceCount()):
cupy.cuda.runtime.setDevice(device_id)
@imos
imos / install.sh
Last active November 10, 2016 16:57
Install Docker
#!/bin/bash
# Usage:
# curl 'https://gist.githubusercontent.com/imos/38e242d1cc3a8db06d90f3368f4a3fa8/raw/install.sh' | bash
set -e -u
################################################################################
# 1. Docker のインストール
################################################################################
if ! which docker; then
@imos
imos / correlation.php
Created March 27, 2016 07:49
日経平均相関計算
<?php
date_default_timezone_set('UTC');
function Parse($file, $shift = 0) {
$data = explode("\n", trim(str_replace(
["\r\n", "\r"], "\n", file_get_contents($file))));
array_shift($data);
$output = [];
foreach ($data as $row) {
@imos
imos / correlation.php
Created March 25, 2016 17:34
日経平均相関計算
<?php
date_default_timezone_set('UTC');
function Parse($file, $shift = 0) {
$data = explode("\n", trim(str_replace(
["\r\n", "\r"], "\n", file_get_contents($file))));
array_shift($data);
$output = [];
foreach ($data as $row) {
@imos
imos / sslh.docker
Last active August 29, 2015 14:02
Makefile and Dockerfile for sslh
FROM ubuntu:14.04
MAINTAINER Kentaro Imajo <docker@imoz.jp>
RUN apt-get update -qq && apt-get -y install sslh
ENTRYPOINT sslh -f -u root -p 0.0.0.0:443 --ssh ${MASTER_HOST}:22 --ssl ${MASTER_HOST}:10443
EXPOSE 443