Skip to content

Instantly share code, notes, and snippets.

View larsch's full-sized avatar

Lars Christensen larsch

View GitHub Profile
@larsch
larsch / gist:140038
Created July 3, 2009 09:58
Treetop parser for Lua objects (limited)
LUAOBJECT_GRAMMAR = %q{
grammar LuaObject
rule luaobj
space value space { def to_ruby; value.to_ruby; end }
end
rule value
nil / float / number / string / table / boolean
end
@larsch
larsch / gist:185242
Created September 11, 2009 11:38
AutoHotkey script for window positioning like on Windows 7
;;
;; Mimic Windows7 window positions using Win+Up/Left/Right
;; Not tested with multiple monitors
;;
#up::
WinRestore A
WinMaximize A
return
@larsch
larsch / gist:571837
Created September 9, 2010 13:12
Detect the hosts IP address
require 'socket'
def local_ip
orig, Socket.do_not_reverse_lookup = Socket.do_not_reverse_lookup, true
UDPSocket.open do |s|
s.connect '8.8.8.8', 1
s.addr.last
end
ensure
Socket.do_not_reverse_lookup = orig
end
@larsch
larsch / PrecompiledHeader.cmake
Last active March 12, 2022 10:49
cmake module for setting up precompiled headers (MSVC & GCC)
# Function for setting up precompiled headers. Usage:
#
# add_library/executable(target
# pchheader.c pchheader.cpp pchheader.h)
#
# add_precompiled_header(target pchheader.h
# [FORCEINCLUDE]
# [SOURCE_C pchheader.c]
# [SOURCE_CXX pchheader.cpp])
#
@larsch
larsch / gmail_spam_stat.rb
Created September 20, 2010 18:59
Show daily statistic of spam on GMail account
require 'net/imap'
require 'open-uri'
if not File.exist?('cacert.pem')
puts "Downloading CA certificates"
open('http://curl.haxx.se/ca/cacert.pem') do |f|
File.open('cacert.pem', 'wb') { |of| of << f.read }
end
end
cert = File.expand_path('cacert.pem')
# Net::IMAP.debug = true
@larsch
larsch / which.rb
Last active December 23, 2015 19:39
Portable which
def which(file)
exts = [""] + (ENV["PATHEXT"]||"").split(File::PATH_SEPARATOR)
ENV["PATH"].split(File::PATH_SEPARATOR).map do |path|
exts.map do |ext|
filepath = File.join(path, file + ext)
defined?(File::ALT_SEPARATOR) && File::ALT_SEPARATOR && filepath.tr!(File::SEPARATOR, File::ALT_SEPARATOR)
filepath if File.exist?(filepath)
end
end.flatten.compact.first
end
@larsch
larsch / build_clang
Last active September 20, 2017 18:48
Download and build CLang 3.3
#!/bin/sh -ex
wget -nc http://llvm.org/releases/3.3/cfe-3.3.src.tar.gz
wget -nc http://llvm.org/releases/3.3/llvm-3.3.src.tar.gz
wget -nc http://llvm.org/releases/3.3/compiler-rt-3.3.src.tar.gz
wget -nc http://llvm.org/releases/3.3/clang-tools-extra-3.3.src.tar.gz
rm -rf llvm
mkdir -p llvm
tar xfz llvm-3.3.src.tar.gz -C llvm --strip-components=1
mkdir -p llvm/tools/clang
tar xfz cfe-3.3.src.tar.gz -C llvm/tools/clang --strip-components=1
#!/bin/sh -ex
wget -N http://llvm.org/releases/3.4/llvm-3.4.src.tar.gz
wget -N http://llvm.org/releases/3.4/clang-3.4.src.tar.gz
wget -N http://llvm.org/releases/3.4/clang-tools-extra-3.4.src.tar.gz
wget -N http://llvm.org/releases/3.4/compiler-rt-3.4.src.tar.gz
mkdir -p llvm
tar xfz llvm-3.4.src.tar.gz -C llvm --strip-components=1
mkdir -p llvm/tools/clang
tar xfz clang-3.4.src.tar.gz -C llvm/tools/clang --strip-components=1
mkdir -p llvm/tools/clang/tools/extra
@larsch
larsch / cmakevs.rb
Last active August 29, 2015 13:57
Run CMake while closing Visual Studio Solution
#!/usr/bin/env ruby
#
# Script that makes updating Visual Studio Solutions from CMakeLists'
# easier, by closing the solution via COM and automatically re-running
# CMake in the corresponding build directory, then reopening and
# building the solution.
#
# Simply run 'cmakevs.rb' from the command line, and it will find an
# instance of Visual Studio and detect the open solution and re-run
# CMake.
#!/usr/bin/env ruby
#
# b - a cmake convinience tool
#
# Runs build commands (e.g. cmake --build ., ctest, etc) in the
# corresponding build directory, from the source directory. For
# example, this command automatically starts a build in the associated
# build directory:
#
# c:\source\git\repo> b