Skip to content

Instantly share code, notes, and snippets.

@yohhoy
yohhoy / problem3.rs
Last active August 29, 2015 14:22
Problem 3, "Five programming problems every Software Engineer should be able to solve in less than 1 hour"
// Problem 3 - https://blog.svpino.com/2015/05/07/five-programming-problems-every-software-engineer-should-be-able-to-solve-in-less-than-1-hour
// https://play.rust-lang.org/
use std::ops::Add;
use std::fmt::{Debug, Formatter, Error};
#[derive(Clone)]
struct MyUint(Vec<u8>);
impl Add for MyUint {
@yohhoy
yohhoy / problem5.rs
Last active August 29, 2015 14:22
Problem 5, "Five programming problems every Software Engineer should be able to solve in less than 1 hour"
// Problem 5 - https://blog.svpino.com/2015/05/07/five-programming-problems-every-software-engineer-should-be-able-to-solve-in-less-than-1-hour
// https://play.rust-lang.org/
#[derive(Copy,Clone)]
enum Op {
Concat = 0,
Plus,
Minus
}
@yohhoy
yohhoy / problem4.rs
Last active August 29, 2015 14:22
Problem 4, "Five programming problems every Software Engineer should be able to solve in less than 1 hour"
// Problem 4 - https://blog.svpino.com/2015/05/07/five-programming-problems-every-software-engineer-should-be-able-to-solve-in-less-than-1-hour
// https://play.rust-lang.org/
fn solve(list: &[u32]) -> String {
let mut list = list.iter()
.map(|&n| n.to_string())
.collect::<Vec<String>>();
list.sort_by(|a,b| {
format!("{:=<10}", b).cmp(&format!("{:=<10}", a))
// Ex) [420, 42, 423] --> "42=" > "423" > "420"
@yohhoy
yohhoy / qsort.rs
Created June 11, 2015 14:59
quick sort
fn quicksort<T: Ord>(mut lst: Vec<T>) -> Vec<T> {
if let Some(pivot) = lst.pop() {
let (less, more): (Vec<_>, Vec<_>) = lst.into_iter().partition(|x| x < &pivot);
let mut res = quicksort(less);
res.push(pivot);
res.extend(quicksort(more));
return res;
} else {
vec![]
}
@yohhoy
yohhoy / tsv_ios.cpp
Last active September 28, 2015 09:03
#include <locale>
#include <string>
#include <sstream>
#include <iostream>
#include <vector>
struct tsv_ctype : std::ctype<char> {
static const mask* make_table()
{
static std::vector<mask> lut(classic_table(), classic_table() + table_size);
@yohhoy
yohhoy / takumi-nick.go
Last active October 28, 2021 13:47
Nickname generator for TAKUMI
//
// Nickname generator for TAKUMI
//
package main
import (
"bufio"
"fmt"
"math/rand"
"net/http"
<!DOCTYPE html>
<html>
<head>
<title>WebGL</title>
<style type="text/css">
<!--
#c { background-color: #eee; }
//-->
</style>
<script id="vs" type="x-shader/x-vertex">
@yohhoy
yohhoy / hex2bin.py
Created October 29, 2015 06:40
convert from hex text to binary
#!/usr/bin/env python3
import sys
import struct
if len(sys.argv) != 3:
print("Usage: {} <source> <target>".format(sys.argv[0]))
quit()
with open(sys.argv[1]) as f:
hex = f.read()
@yohhoy
yohhoy / mt_cline.hpp
Last active November 8, 2015 06:01
multithread-safe alternative cout/wcout stream (line outputter)
/*
* mt_cline.hpp - multithread-safe alternative cout/wcout stream (line outputter)
*
* (C) Copyright yohhoy 2015.
* Distributed under the Boost Software License, Version 1.0.
* (See copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#include <iostream>
#include <mutex>
#include <string>
@yohhoy
yohhoy / Makefile.template
Last active November 14, 2015 07:37
Makefile template for MacOS/brew
DEBUG?=1
SRCS=$(wildcard *.cpp)
OBJS=$(SRCS:.cpp=.o)
DEPENDS=Makefile.depends
BOOST_PATH=$(shell brew --prefix boost)
CXXFLAGS=-std=c++14 -W -Wall -I$(BOOST_PATH)
LDFLAGS=-L$(BOOST_PATH)/lib