Skip to content

Instantly share code, notes, and snippets.

@kizzx2
kizzx2 / UBlog.html
Created February 26, 2012 13:58
Minimal single-file Backbone.js demo
<!DOCTYPE html>
<html>
<head>
<script src="require.js"></script>
<script>
require(['jquery', 'underscore', 'backbone'],
function($)
{
var UBlog = {};
@kizzx2
kizzx2 / r-test.vim
Last active October 8, 2015 07:48
Vim function to run individual test function in Ruby MiniTest
function! Rtest()
ruby <<END
line = $curbuf.line
fn = nil
if line =~ /^\s*test\s+["']([^"']+)["']\s+do/
fn = "test_#{$1.gsub(/ /, '_')}"
elsif line =~ /^\s*def\s+(test_.+)/
fn = $1
end
@kizzx2
kizzx2 / attach.rb
Created November 1, 2012 12:47
Attach debugger to arbitrary Ruby process. Almost working
require 'tempfile'
require 'debugger'
DEBUGGER_MONKEY_PATCH = <<'EOF'
module Debugger
class << self
def stop_remote
return unless @thread || @control_thread
@stopped = true
@kizzx2
kizzx2 / Rakefile
Created December 9, 2012 16:54
Rake task to easily package iOS static library into .framework bundle
# This assumes you have placed your public header files in the `Headers`
# directory in your output directory. You can satisfy that easily by creating a
# "Copy Files" build phase. See
# http://image.bayimg.com/9cf4804007f7a7b59505de345ad2bbc388499475.jpg
# Usage:
#
# 1. Change `PROJECT_NAME` below. E.g. if you have `Calculator.xcodeproj`, change it to `"Calculator"`
# 2. Put this beside your `.xcodeproj` file, then just run `rake`
@kizzx2
kizzx2 / mark-email.rb
Last active December 9, 2015 21:58
Markdown emails with syntax highlighting on each <pre> block
#!/usr/bin/env ruby
# encoding: UTF-8
require 'nokogiri'
require 'open3'
html = Open3.popen2('redcarpet') do |stdin, stdout|
stdin.write(STDIN.read)
stdin.close
@kizzx2
kizzx2 / post.rb
Last active June 26, 2021 12:14
A clean and elegant approach to partial object validation with Rails + Wicked wizards (using session to store the partial object)
class Post < ActiveRecord::Base
attr_accessible :body, :price, :title
validates_presence_of :title
validates_length_of :title, minimum: 10
validates_presence_of :body
validates_numericality_of :price, greater_than: 0
end
@kizzx2
kizzx2 / post.rb
Created February 6, 2013 14:53
A clean and elegant approach to partial object validation with Rails + Wicked wizards (store partial object in database)
class Post < ActiveRecord::Base
attr_accessible :body, :price, :title
validates_presence_of :title
validates_length_of :title, minimum: 10
validates_presence_of :body
validates_numericality_of :price, greater_than: 0
end
@kizzx2
kizzx2 / tmux-sync.sh
Last active April 11, 2024 14:33
Run multiple commands, and open them all in synchronized tmux panes
#!/bin/sh
#
# The MIT License (MIT)
#
# Copyright (c) 2013 Chris Yuen
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
@kizzx2
kizzx2 / fun.cpp
Last active March 29, 2022 04:12
Illustrative C++ Lua binding example/tutorial
// fun.cpp
// This is for Lua 5.2, for Lua 5.1, see https://gist.github.com/kizzx2/1594905
#include <lua.hpp>
#include <iostream>
#include <sstream>
class Foo
{
@kizzx2
kizzx2 / foo.js
Last active December 20, 2015 00:59
var docs = [];
for(var i = 0; i < 20000; i++) {
docs.push({rnd: _rand(), t: "2013-06-23", N:7*i, A:1, V:0, n:"1234"});
}
docs.sort(function(a, b) {
return a.rnd - b.rnd;
});
var t0 = Date.now();
db.foos.insert(docs);