Skip to content

Instantly share code, notes, and snippets.

@danzimm
danzimm / Output.txt
Created May 17, 2017
Example output of caffe2 receiving a given signal in c++
View Output.txt
SIGABRT(6), Thread 3493194:
[0] ???+0x51aad878(0x7f7a51aad878) in /home/danzimm/oss/caffe2/build/caffe2/libCaffe2_CPU.so
[1] ???+0x51aadbbe(0x7f7a51aadbbe) in /home/danzimm/oss/caffe2/build/caffe2/libCaffe2_CPU.so
[2] ???+0x51aade72(0x7f7a51aade72) in /home/danzimm/oss/caffe2/build/caffe2/libCaffe2_CPU.so
[3] ???+0x510ca370(0x7f7a510ca370) in /lib64/libpthread.so.0
[4] raise+0x2b(0x7f7a510ca23b) in /lib64/libpthread.so.0
[5] ???+0x404fcf(0x404fcf) in caffe2/binaries/fatal_signal_test
[6] ???+0x40562d(0x40562d) in caffe2/binaries/fatal_signal_test
[7] fatalSignalTest_SIGABRT8_Test::TestBody()+0x73(0x405773) in caffe2/binaries/fatal_signal_test
[8] void testing::internal::HandleExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*)+0x33(0x7f7a5021b203) in /home/danzimm/oss/caffe2/build/third_party/googletest/googlemock/gtest/libgtest.so
@danzimm
danzimm / cowsay.py
Created Apr 17, 2017
Weechat cowsay plugin
View cowsay.py
import os
import subprocess
import weechat
rawCowfiles = subprocess.check_output("cowsay -l", shell=True)
cowfiles = [f for line in filter(lambda line: not line.startswith("Cow files in"), rawCowfiles.splitlines()) for f in line.split()]
ordCowfiles = "||".join(cowfiles)
weechat.prnt("", "Available cowfiles: " + str(cowfiles))
@danzimm
danzimm / msgSendGen.swift
Created Feb 16, 2017
Generate msgSend wrappers for swift, written in swift
View msgSendGen.swift
#!/usr/bin/env swift
import Foundation
extension Int {
var tabs: String {
return Array(count: self, repeatedValue: " ").joinWithSeparator("")
}
}
@danzimm
danzimm / currygen.swift
Created Feb 16, 2017
Generate curry functions for swift, written in swift
View currygen.swift
#!/usr/bin/env swift
import Foundation
infix operator <*> {
associativity left
precedence 120
}
func <*> <T: CollectionType, U: CollectionType, V where T.Generator.Element == ((U.Generator.Element) -> V)>(left: T, right: U) -> [V] {
@danzimm
danzimm / crash.c
Created Jan 2, 2017
Jump to a random x86_64 interrupt
View crash.c
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
void usage(const char* name) {
printf("Usage: %s [int code]\n", name);
exit(1);
}
void doInterrupt(uint8_t code) {
@danzimm
danzimm / hash_extension.cpp
Created Oct 12, 2016
std::hash extensions
View hash_extension.cpp
template<typename T, typename U>
struct std::hash<std::pair<T, U>> {
std::size_t operator()(std::pair<T, U> const& value) const {
std::size_t thash = std::hash<T>{}(value.first);
std::size_t uhash = std::hash<U>{}(value.second);
// See boost::hash_combine for this
return uhash ^ ( thash << 1 );
}
};
@danzimm
danzimm / helpers.hpp
Last active Sep 25, 2016
Objective-C++ object type helpers
View helpers.hpp
template<typename T>
struct remove_ownership {
using type = T;
};
template<typename T>
struct remove_ownership<__strong T> {
using type = T;
};
@danzimm
danzimm / Whoa.swift
Last active Aug 29, 2015
PlaygroundFun
View Whoa.swift
func +(a: NSAttributedString, b: NSAttributedString) -> NSAttributedString {
let muty = NSMutableAttributedString(attributedString: a)
muty.appendAttributedString(b)
return muty
}
extension String: CustomPlaygroundQuickLookable {
public func customPlaygroundQuickLook() -> PlaygroundQuickLook {
let colors: [UIColor] = [
.redColor(), .orangeColor(), .yellowColor(),
View download-file.js
'use strict';
/**
* MAC OSX ONLY
*/
// npm install request async
try{
var request = require('request');
var async = require('async');
var Notification = require('node-notifier');
@danzimm
danzimm / im.danz.dot-clipboard.plist
Created Sep 1, 2014
Drop something like this in ~/Library/LaunchAgents and you get dot-clipboard forevah ;D
View im.danz.dot-clipboard.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>im.danz.dot-clipboard</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/node</string>
<string>/usr/local/bin/dot-clipboard</string>