Skip to content

Instantly share code, notes, and snippets.

@sanmai
sanmai / merge_dna_files.rb
Created August 15, 2022 02:54 — forked from plashchynski/merge_dna_files.rb
Tool to merge 23andme and Ancestory.com raw dna files
#!/usr/bin/ruby
#
# Usage:
# ruby ./merge_dna_files.rb file,file1,file2... > merged_file.txt
#
# Example:
# ruby ./merge_dna_files.rb AncestryDNA.txt genome_John_Doe_v4_Full_20170428065226.txt > merged_raw.txt
#
# Supports 23andMe, AncestryDNA, and Genes for Good 23andMe compatible file formats.
# The result will be in 23andMe file format.
@sanmai
sanmai / Count Code lines.sh
Created October 5, 2020 05:16 — forked from amitchhajer/Count Code lines
Count number of code lines in git repository per user
git ls-files | xargs -n1 git blame --line-porcelain | sed -n 's/^author //p' | sort -f | uniq -ic | sort -nr
@sanmai
sanmai / WP REST API Controller Class.php
Last active September 25, 2020 08:14 — forked from JMWebDevelopment/WP REST API Controller Class
This is the base WP REST API Controller class
<?php class Sports_Bench_Team_REST_Controller extends WP_REST_Controller {
/**
* Register the routes for the objects of the controller.
*/
public function register_routes() {
$namespace = 'sportsbench';
$base = 'teams';
register_rest_route( $namespace, '/' . $base, array(
array(
@sanmai
sanmai / isset_vs_array_key_exists.php
Last active March 20, 2020 03:16 — forked from alcaeus/in_array_vs_isset_vs_array_key_exists.php
Performance comparision: isset vs. array_key_exists
<?php
function testPerformance($name, Closure $closure, $runs)
{
$start = microtime(true);
for (; $runs > 0; $runs--)
{
$_ = $closure();
}
$end = microtime(true);
@sanmai
sanmai / dropbox_ext4.c
Created August 15, 2018 07:34 — forked from dimaryaz/dropbox_ext4.c
Dropbox ext4 hack
/*
* dropbox_ext4.c
*
* Compile like this:
* gcc -shared -fPIC -ldl -o libdropbox_ext4.so dropbox_ext4.c
*
* Run Dropbox like this:
* LD_PRELOAD=./libdropbox_ext4.so ~/.dropbox-dist/dropboxd
*/
@sanmai
sanmai / startswith_benchmark.php
Last active June 7, 2016 07:32 — forked from mnpenner/startswith_benchmark.php
Various StartsWith implementations
<?php
/*
Run with all available processing power:
sudo nice -n -20 php startswith_benchmark.php | sort -h
Running with PHP 7.0.7-3 gives:
1.6±0.0014 msec - strncmp_startswith_shortcut
@sanmai
sanmai / prepare-commit-msg.sh
Last active December 23, 2015 08:28 — forked from bartoszmajsak/prepare-commit-msg.sh
Leaves as is any commit message other than for new commits.
#!/bin/bash
if [[ "$2" == "message" || -z "$2" ]]; then
BRANCH_NAME=$(git branch 2>/dev/null | grep -e ^* | tr -d ' *')
if [[ -n "$BRANCH_NAME" && "$BRANCH_NAME" != "master" ]]; then
echo "$BRANCH_NAME: $2 $(cat $1)" > $1
fi
fi