Skip to content

Instantly share code, notes, and snippets.

@marcetcheverry
marcetcheverry / mapread.c
Created May 25, 2011 14:05
mmap and read/write string to file
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <unistd.h>
int main(int argc, const char *argv[])
{
@pasela
pasela / unicodeescape.vim
Created December 17, 2011 19:30
Escape/Unescape unicode string.
" unicodeescape.vim - Escape/Unescape unicode string.
function! UnicodeEscapeString(str)
let oldenc = &encoding
set encoding=utf-8
let escaped = substitute(a:str, '[^[:alnum:][:blank:][:cntrl:][:graph:]]', '\=printf("\\u%04x", char2nr(submatch(0)))', 'g')
let &encoding = oldenc
return escaped
endfunction
@earthgecko
earthgecko / bash.generate.random.alphanumeric.string.sh
Last active July 4, 2024 17:31
shell/bash generate random alphanumeric string
#!/bin/bash
# bash generate random alphanumeric string
#
# bash generate random 32 character alphanumeric string (upper and lowercase) and
NEW_UUID=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
# bash generate random 32 character alphanumeric string (lowercase only)
cat /dev/urandom | tr -dc 'a-z0-9' | fold -w 32 | head -n 1
@girvan
girvan / s3.php
Last active December 14, 2015 17:39
s3 service
<?php
define('S3_PATH', '/var/www/data/s3');
define('S3_DN', 's3.exammple.com');
function _s3_check($s3_filename)
{
$cmd = sprintf("ssh %s 'ls -al %s 2>/dev/null && echo 1;';"
,S3_DN, S3_PATH . '/' . $s3_filename);
$resp = shell_exec($cmd);
@mehcode
mehcode / install-pygtk.sh
Created August 7, 2013 09:49
Install pygtk inside of a virtualenv
# Ensure we're in a virtualenv.
if [ "$VIRTUAL_ENV" == "" ]
then
echo "ERROR: not in a virtual environment."
exit -1
fi
# Setup variables.
CACHE="/tmp/install-pygtk-$$"
@jbenet
jbenet / simple-git-branching-model.md
Last active June 17, 2024 14:53
a simple git branching model

a simple git branching model (written in 2013)

This is a very simple git workflow. It (and variants) is in use by many people. I settled on it after using it very effectively at Athena. GitHub does something similar; Zach Holman mentioned it in this talk.

Update: Woah, thanks for all the attention. Didn't expect this simple rant to get popular.

Virtual DOM and diffing algorithm

There was a [great article][1] about how react implements it's virtual DOM. There are some really interesting ideas in there but they are deeply buried in the implementation of the React framework.

However, it's possible to implement just the virtual DOM and diff algorithm on it's own as a set of independent modules.

@pkuczynski
pkuczynski / parse_yaml.sh
Last active June 15, 2024 20:30
Read YAML file from Bash script
#!/bin/sh
parse_yaml() {
local prefix=$2
local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @|tr @ '\034')
sed -ne "s|^\($s\)\($w\)$s:$s\"\(.*\)\"$s\$|\1$fs\2$fs\3|p" \
-e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $1 |
awk -F$fs '{
indent = length($1)/2;
vname[indent] = $2;
for (i in vname) {if (i > indent) {delete vname[i]}}
@kencharos
kencharos / StreamUtil.java
Created March 31, 2014 02:44
zip in java8
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.function.BiFunction;
import java.util.stream.LongStream;
import java.util.stream.Stream;
/**
*
*/
@danielecook
danielecook / LCR_region.sh
Last active March 7, 2017 08:24
Generate Low Complexity Region (LCR) bedfile of masked regions from UCSC repeatmasker data and its complement for use with bcftools
#!/bin/bash
wget 'http://hgdownload.soe.ucsc.edu/goldenPath/ce10/database/rmsk.txt.gz' -O LCR_rmsk.txt.gz
gunzip -kfc LCR_rmsk.txt.gz | grep 'Low_complexity' | cut -f 6,7,8 > LCR_ce10_rmsk.bed
rm LCR_rmsk.txt.gz
# Generate the set of regions complementary (e.g. NOT low complexity)
# Download c. elegans chromosome information
mysql --user=genome --host=genome-mysql.cse.ucsc.edu -A -e "select chrom, size from ce10.chromInfo" > ce10.genome
bedtools complement -i LCR_ce10_rmsk.bed -g ce10.genome | sort -k 1,1 -k2,2n > LCR_complement_ce10.bed