Skip to content

Instantly share code, notes, and snippets.

@yiding
yiding / xmonad-dzen.hs
Created February 22, 2014 22:30
XMonad dzen loghook that respawns dzen when screen size changes
{-# LANGUAGE FlexibleContexts #-}
import XMonad
import Control.Monad.Reader (asks)
import Control.Concurrent.MVar (MVar, newMVar, modifyMVar)
import XMonad.Actions.GridSelect (goToSelected, defaultGSConfig)
import XMonad.Util.EZConfig (additionalKeys)
import XMonad.Hooks.DynamicLog (PP(..), dzenPP, dynamicLogWithPP)
import XMonad.Util.Run (spawnPipe)
import System.IO (Handle, IOMode(WriteMode), hPutStrLn, hClose, openFile)
@yiding
yiding / patch.diff
Created April 22, 2014 23:35
topgit-0.9 patch for homebrew
diff --git a/Makefile b/Makefile
index 3ce39a5..2926f9e 100644
--- a/Makefile
+++ b/Makefile
@@ -3,7 +3,7 @@ bindir := $(prefix)/bin
cmddir := $(prefix)/libexec/topgit
sharedir := $(prefix)/share/topgit
hooksdir := $(cmddir)/hooks
-
+sed := gsed
@yiding
yiding / osx-man-xcode.md
Last active October 29, 2022 18:20
Man pages on OSX + Xcode Developer tools

OSX's man utility has custom patches to allow finding man pages from installed Xcode SDKs.

#ifdef __APPLE__
	xcselect_manpaths *xcp;
	const char *path;
	unsigned i, count;

	// TODO: pass something for sdkname
	xcp = xcselect_get_manpaths(NULL);
@yiding
yiding / gist:0c6779fbca92282ce7a1
Created June 9, 2014 23:53
phabricator basic stgit compatibility
diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
index ba7adb4..8c4031c 100644
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -157,6 +157,7 @@ phutil_register_library_map(array(
'ArcanistSpellingDefaultData' => 'lint/linter/spelling/ArcanistSpellingDefaultData.php',
'ArcanistSpellingLinter' => 'lint/linter/ArcanistSpellingLinter.php',
'ArcanistSpellingLinterTestCase' => 'lint/linter/__tests__/ArcanistSpellingLinterTestCase.php',
+ 'ArcanistStgitAPI' => 'repository/api/ArcanistStgitAPI.php',
'ArcanistSubversionAPI' => 'repository/api/ArcanistSubversionAPI.php',
@yiding
yiding / imapfilter_phabricator.lua
Created June 25, 2014 00:17
Imapfilter function to move all notifications related to phabricator notifications to a different folder
function pruneCommittedDiffs(mailbox, dest_mailbox)
diff_set = mailbox:contain_subject('[Differential]')
committed_diff_set = diff_set:contain_field('X-Phabricator-Mail-Tags', '<differential-committed>')
for _, message in ipairs(committed_diff_set) do
mmbox, uid = table.unpack(message)
rev_key = string.gsub(mmbox[uid]:fetch_field('In-Reply-To'), 'In%-Reply%-To: ', '')
all_diff_msgs = diff_set:contain_field('In-Reply-To', rev_key) + diff_set:contain_field('Message-ID', rev_key)
all_diff_msgs:move_messages(dest_mailbox)
end
end
@yiding
yiding / gist:1bfe9bbf5187a6ff6f34
Created June 30, 2014 19:03
WebRTC native, forcing ports to be allocated in a certain range.
class PortAllocatorFactoryWrapper : public PortAllocatorFactory {
public:
PortAllocatorFactoryWrapper(talk_base::Thread* worker_thread, int minPort, int maxPort)
: PortAllocatorFactory(worker_thread), minPort_(minPort), maxPort_(maxPort) {}
virtual cricket::PortAllocator *CreatePortAllocator(
const std::vector<StunConfiguration> &stun,
const std::vector<TurnConfiguration> &turn) override {
auto allocator = PortAllocatorFactory::CreatePortAllocator(stun, turn);
allocator->SetPortRange(minPort_, maxPort_);
@yiding
yiding / SLF0Parser.hs
Created July 10, 2014 22:33
Xcode SLF0 serialization format parser (used in xcactivitylog)
{-# LANGUAGE OverloadedStrings #-}
{-|
Tokenizer for SLF0 serialization format, used by Xcode to, at the very least,
encode some log files.
For example, `.xcactivitylog` logs are gzipped files of this format,
serializing some objc classes which represent the build log.
This class tokenizes the raw byte stream into a flat list of tokens. The actual
@yiding
yiding / hoogle.sh
Created July 11, 2014 02:20
Generate local hoogle instance based on installed packages, uses ninja to build
#!/bin/bash
cd $(dirname $0)
OUTDIR=_out
mkdir -p $OUTDIR
OUTNINJA=$OUTDIR/build.ninja
cat << EOF > $OUTNINJA
rule ln
@yiding
yiding / args_with_clang.cpp
Created September 4, 2014 02:03
Trivially parsing clang command line args with clang itself.
#include <llvm/Option/ArgList.h>
#include <llvm/Option/Arg.h>
#include <clang/Driver/Options.h>
#include <llvm/Option/OptTable.h>
#include <llvm/Support/raw_ostream.h>
#include <memory>
using namespace llvm;
@yiding
yiding / flow.vim
Created March 23, 2015 22:15
syntastic checker for flow
" requires vim-flow: https://github.com/facebook/vim-flow/
" put this in a syntax_checkers/ directory, such as:
" .vim/bundle/flowtype/syntax_checkers/javascript/flow.vim
if exists("g:loaded_syntastic_javascript_flow_checker")
finish
endif
let g:loaded_syntastic_javascript_flow_checker = 1
let s:save_cpo = &cpo