Skip to content

Instantly share code, notes, and snippets.

@tomykaira
tomykaira / .vimrc
Created July 16, 2015 07:23
Simple vimrc for strict coding rule
au BufWinEnter COMMIT_EDITMSG setlocal tw=75
au BufWinEnter COMMIT_EDITMSG let w:g1=matchadd('ErrorMsg', '\%1l\%51v.\+', -1)
au BufWinEnter COMMIT_EDITMSG let w:g2=matchadd('ErrorMsg', '\%76v.\+', -1)
au BufWinEnter * let w:m2=matchadd('ErrorMsg', '\%80v.\+', -1)
@tomykaira
tomykaira / subpatch.sh
Created July 10, 2015 06:55
save and apply patches for git submodules
#!/bin/sh -e
separator="----8<----8<----8<----8<----"
function make_chunk {
cd $1
if ! git diff --exit-code --ignore-submodules --quiet; then
echo "${PWD#$root}/"
git --no-pager diff --no-color --ignore-submodules
echo "$separator"
@tomykaira
tomykaira / white_balance.cpp
Last active June 1, 2023 08:46
Simplest white balance in OpenCV
// The MIT License (MIT)
// Copyright (c) 2015 tomykaira
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CON
function pp () {
export PREVIOUS_PP_ARGS="$*"
pgrep -lfa $*
}
function pk () {
if [ $# -eq 0 ]; then
pgrep -lf $PREVIOUS_PP_ARGS | awk '{print $1}' | xargs kill
else
pgrep -lf $PREVIOUS_PP_ARGS | sed "$1q;d" | awk '{print $1}' | xargs kill
package com.example.android;
import org.junit.runners.model.InitializationError;
import org.robolectric.AndroidManifest;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.res.DrawableNode;
import org.robolectric.res.OverlayResourceLoader;
import org.robolectric.res.PackageResourceLoader;
import org.robolectric.res.ResName;
import org.robolectric.res.ResourceLoader;
@tomykaira
tomykaira / guzzle.php
Created January 7, 2015 10:57
Set user-agent in guzzle. client->setDefaultOption('headers/User-Agent', 'foo'); does not work for user-agent.
<?php
require 'vendor/autoload.php';
use Guzzle\Service\Client;
// Create a client with a base URL
$client = new Client('http://requestb.in/1ivmkhd1');
$client->setUserAgent('myuseragent');
// Send a request to https://github.com/notifications
$response = $client->get('')->send();
@tomykaira
tomykaira / elapsed_time.js
Created December 23, 2014 04:14
Measure elapsed time in JS (node.js etc)
times = 1000000;
console.time('global');
for (i = 0; i < times; ++i) {
// do something
}
console.timeEnd('global');
@tomykaira
tomykaira / elapsed.py
Created December 22, 2014 16:41
Measure elapsed time in python
import time
import itertools
import gc
gc.disable()
start = time.time()
for i in itertools.repeat(None, 10000):
# do something
@tomykaira
tomykaira / Bean.java
Created December 9, 2014 11:35
Custom deserializer example in Jackson
class Bean {
@JsonDeserialize(using=RrDeserializer.class)
public final Object rr;
public static class RrDeserializer extends JsonDeserializer<Object> implements ResolvableDeserializer {
JsonDeserializer<Object> sampleRefResponseDeserializer;
@Override
public Object deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
JsonToken token = jp.getCurrentToken();
@tomykaira
tomykaira / chrono_elapsed.cpp
Created November 16, 2014 06:32
Measure elapsed time in C++
#include <chrono>
#include <iostream>
auto start = std::chrono::high_resolution_clock::now();
// do something
auto end = std::chrono::high_resolution_clock::now();
std::cout << std::chrono::duration_cast<std::chrono::microseconds>(end - start).count() << std::endl;