Skip to content

Instantly share code, notes, and snippets.

@eagafonov
eagafonov / CMakeLists.txt
Created January 10, 2014 10:28
Minimal CMake file "Hello world"
# The name of our project is "HELLO". CMakeLists files in this project can
# refer to the root source directory of the project as ${HELLO_SOURCE_DIR} and
# to the root binary directory of the project as ${HELLO_BINARY_DIR}.
cmake_minimum_required (VERSION 2.8)
project (HELLO)
# Recurse into the "Hello" and "Demo" subdirectories. This does not actually
# cause another cmake executable to run. The same process will walk through
# the project's entire directory structure.
add_subdirectory (Hello)
@eagafonov
eagafonov / gist:8596834
Last active January 4, 2016 08:39
Some C++11 magic
#include <iostream>
#include <functional>
using namespace std;
std::function<int()> getProc() {
static int a = 0;
auto p1 = [&]() {
a++;
@eagafonov
eagafonov / config.mk
Created February 27, 2014 15:21
config.mk to build Artupilot for virt2real (https://github.com/eagafonov/v2r-ardupilot/tree/virt2real)
# Select 'mega' for the 1280 APM1, 'mega2560' otherwise
BOARD = V2R
# BOARD = LINUX
# HAL_BOARD determines default HAL target.
HAL_BOARD ?= HAL_BOARD_V2R
# HAL_BOARD ?= HAL_BOARD_LINUX
# The communication port used to communicate with the APM.
PORT = /dev/ttyACM0
#!/bin/sh -x
# 1. Add to ~/.bashrc[[ -f ".goenv" ]] && source .goenv
# 2. Put symbol link to this file named .goenv in some folder
# 3. start bash in this folder
# Path where GO is installed
GO_INSTALL_PATH=/opt/go
HERE=$(pwd)
@eagafonov
eagafonov / gist:eb9b5c77800911b1c229
Created February 11, 2015 10:52
Parse date per format
import java.text.SimpleDateFormat;
import java.util.Date;
import java.text.ParsePosition;
public class DateTimeTest {
public static void main(String[] args) {
// Create parser
SimpleDateFormat df = new SimpleDateFormat("yyyy-mm-dd");
@eagafonov
eagafonov / DateTimeTest.java
Last active August 29, 2015 14:15
Parse date per format
import java.text.SimpleDateFormat;
import java.util.Date;
import java.text.ParsePosition;
public class DateTimeTest {
public static void main(String[] args) {
// Create parser
SimpleDateFormat df = new SimpleDateFormat("yyyy-mm-dd");
@eagafonov
eagafonov / check_stun.sh
Created February 16, 2015 10:47
Dumb script to check that STUN server responds
#!/bin/sh
set -e
stun -v $1 2>&1 | grep MappedAddress | head -1 | wc -l
@eagafonov
eagafonov / check4dnc.sh
Created July 14, 2015 10:07
GIT hook helper to checks staged changes for 'DO NOT COMMIT' string
#!/bin/sh
set -e
# This GIT hook helper checks staged changes for 'DO NOT COMMIT' string
# Returns non-zero if found
# To install this check into .git/hooks/pre-commit
# just add line '/path/to/check-do-not-commit.sh || exit 1' >>BEFOR<< last line with 'exec git diff-index ...'
# The bottom of .git/hooks/pre-commit should looks something like this:
@eagafonov
eagafonov / htmldump.js
Last active September 29, 2015 13:50
jQuery plugin to dump HTML tree
// playground http://jsfiddle.net/1ssfjxu1/1/
$.fn.htmldump = function() {
function walk(element, callback) {
if (callback) {
callback.apply(element);
}
$(element).children('*:not(script)')
.each(function(i, child) {walk(child, callback)});
@eagafonov
eagafonov / savefile.js
Created December 14, 2015 09:12
Save a file from browser using File API (http://www.w3.org/TR/FileAPI/)
var saveData = (function () {
var a = document.createElement("a");
document.body.appendChild(a);
a.style = "display: none";
return function (data, fileName) {
var json = JSON.stringify(data),
blob = new Blob([json], {type: "octet/stream"}),
url = window.URL.createObjectURL(blob);
a.href = url;
a.download = fileName;