This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Xcode: Set version and build number from Git | |
# -------------------------------------------- | |
# | |
# This script sets the version number `CFBundleShortVersionString` to one of | |
# | |
# - `1.2.3` -- for the tagged commit `v1.2.3` or a hyphen-separated prerelease, | |
# e.g. `v1.2.3-alpha`, `v1.2.3-alpha.2`, `v1.2.3-beta`, `v1.2.3-rc`. | |
# - `1.2.3-7-gabc1234` -- at commit `abc1234`, 7 commits after `v1.2.3`, | |
# - `1.2.3-7-gabc1234-dirty` -- when there are uncommitted changes, or |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export _ps1_timer | |
function _ps1_timer_start { | |
# echo START | |
_ps1_timer=${_ps1_timer:-`gdate +%s%N 2> /dev/null || date +%s%N`}; | |
} | |
function _ps1_timer_stop { | |
# echo STOP | |
if [ -z "$_ps1_timer" ]; then |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Print the imported modules in green, then ">>> " on the following line. | |
:set prompt "\SOH\ESC[32m\STX%s\SOH\ESC[0m\STX\n\SOH\ESC[32;1m\STX>>>\SOH\ESC[0m\STX " | |
-- (Disclaimer: ghci doesn't currently support configuring the prompt on | |
-- continuation lines for multiline inputs, so you'll get something like | |
-- "Prelude|" instead of something convenient like a green "... ". Patches | |
-- welcome, I guess!) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[alias] | |
l50 = "!f () { git log --abbrev-commit --date=short --pretty=format:'%h%x00%cd%x00%s%x00%an%x00%d' $@ | gawk -F '\\0' '{ printf \"\\033[31m%s\\033[0m \\033[32m%s\\033[0m %-50s \\033[30;1m%s\\033[0m\\033[33m%s\\n\", $1, $2, gensub(/(.{49}).{2,}/, \"\\\\1…\",\"g\",$3), $4, $5 }' | less -R; }; f" | |
l80 = "!f () { git log --abbrev-commit --date=short --pretty=format:'%h%x00%cd%x00%s%x00%an%x00%d' $@ | gawk -F '\\0' '{ printf \"\\033[31m%s\\033[0m \\033[32m%s\\033[0m %-80s \\033[30;1m%s\\033[0m\\033[33m%s\\n\", $1, $2, gensub(/(.{79}).{2,}/, \"\\\\1…\",\"g\",$3), $4, $5 }' | less -R; }; f" | |
lg50 = "!f () { git log --graph --color=always --abbrev-commit --date=relative --pretty=format:'%x00%h%x00%s%x00%cd%x00%an%x00%d' $@ | gawk -F '\\0' '{ printf \"%s\\033[31m%s\\033[0m %-50s \\033[32m%14s\\033[0m \\033[30;1m%s\\033[0m\\033[33m%s\\n\", $1, $2, gensub(/(.{49}).{2,}/, \"\\\\1…\",\"g\",$3), $4, $5, $6 }' | less -R; }; f" | |
lg80 = "!f () { git log --graph --color=always --abbrev-commit --date=re |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Toggle this boolean to compare against stdlib: | |
#if true // Stdlib version | |
// Quick hack to avoid changing the AnyEquatable implementation below. | |
extension Equatable { typealias EqualSelf = Self } | |
#else // Modified version | |
protocol Equatable { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <boost/any.hpp> | |
#include <unordered_map> | |
#include <functional> | |
#include <iostream> | |
#include <vector> | |
struct type_info_hash { | |
std::size_t operator()(std::type_info const & t) const { | |
return t.hash_code(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
@interface NSObject (Cast) | |
+ (instancetype)cast:(id)object; | |
@end | |
@implementation NSObject (Cast) | |
+ (instancetype)cast:(id)object | |
{ | |
return [object isKindOfClass:self] ? object : nil; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn exchange! | |
"Atomically set the value of `atom` to `(apply f @atom args)`, | |
and return the value of `@atom` just before the assignment. | |
(See also: `clojure.core/swap!`)" | |
[atom f & args] | |
{:pre [(instance? clojure.lang.Atom atom)]} | |
(loop [oldval @atom] | |
(if (compare-and-set! atom oldval (apply f oldval args)) | |
oldval | |
(recur @atom)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(empty? (d/datoms db :aevt :user/id)) | |
;;=> false | |
(not-empty (d/datoms db :aevt :user/id)) | |
;;=> #<db$datoms$reify__3265 datomic.db$datoms$reify__3265@7939b07> | |
(seq (d/datoms db :aevt :user/id)) | |
;;=> (#Datum{:e 17592186046081 :a 70 :v "abc" :tx 13194139534976 :added true} ...) | |
(first (d/datoms db :aevt :user/id)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Here are a few tricks I've used with the trunk versions of clang and libc++ | |
// with C++11 compilation turned on. Some might be obvious, some not, but at | |
// least they are some kind of improvement over their C++03 counterparts. | |
// | |
// Public domain. | |
// ============================================================================= | |
// 1) Using variadic class templates recursively, like in the definitions for | |
// "add<T...>" here: |
NewerOlder