Skip to content

Instantly share code, notes, and snippets.

@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 / c++_has_member.cpp
Created April 20, 2011 16:27
C++ compile time detection of member variable with SFINAE
#include <iostream>
struct Foo
{
int one;
};
struct Bar
{
char one;
@kizzx2
kizzx2 / k3d-tiller.sh
Last active February 18, 2020 06:49
Setting up k3d with Helm/Tiller 2
# Optionally delete the existing cluster first if you have it
# k3d d
# Work around "pods being evicted" issue
# https://github.com/rancher/k3d/issues/133
k3d c \
--server-arg '--kubelet-arg=eviction-hard=imagefs.available<1%,nodefs.available<1%' \
--server-arg '--kubelet-arg=eviction-minimum-reclaim=imagefs.available=1%,nodefs.available=1%'
# Wait until the base system nodes are running
:root {
--side-bar-bg-color: #fafafa;
--control-text-color: #777;
}
@include-when-export url(https://fonts.loli.net/css?family=Open+Sans:400italic,700italic,700,400&subset=latin,latin-ext);
@font-face {
font-family: 'Open Sans';
font-style: normal;
call rpcnotify(1, 'Gui', 'Font', 'Fira Code 22')
let s:fontsize = 22
function! AdjustFontSize(amount)
let s:fontsize = s:fontsize+a:amount
call rpcnotify(1, 'Gui', 'Font', 'Fira Code ' . s:fontsize)
endfunction
noremap <c-+> :call AdjustFontSize(1)<CR>
noremap <c--> :call AdjustFontSize(-1)<CR>
@kizzx2
kizzx2 / start-ss.sh
Last active July 17, 2018 10:35
Simple script to start Shadowsocks + GFWList and configures OS X system preferences to use it
#!/bin/sh
# Simple script to start Shadowsocks + GFWList and configures
# OS X system preferences to use it
if [[ $(id -u) -ne 0 ]]
then
sudo sh $0
exit
fi
@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 / orientationchanged.js
Created June 16, 2017 02:12
Get the correct window.innerHeight for 'orientationchanged' event
// Wait until innerheight changes, for max 120 frames
function orientationChanged() {
const timeout = 120;
return new window.Promise(function(resolve) {
const go = (i, height0) => {
window.innerHeight != height0 || i >= timeout ?
resolve() :
window.requestAnimationFrame(() => go(i + 1, height0));
};
go(0, window.innerHeight);
@kizzx2
kizzx2 / 03-rabbitmq-input.conf
Last active May 27, 2017 16:32
A docker-compose set up that has nginx -> ELK through RabbitMQ
input {
rabbitmq {
host => "rabbitmq"
exchange => "logstash"
exchange_type => "direct"
key => "logstash"
durable => true
}
}
# Server sending file
server$ socat -u FILE:test.dat TCP-LISTEN:9876,reuseaddr
client$ socat -u TCP:127.0.0.1:9876 OPEN:out.dat,creat
# Server receiving file
server$ socat -u TCP-LISTEN:9876,reuseaddr OPEN:out.txt,creat && cat out.txt
client$ socat -u FILE:test.txt TCP:127.0.0.1:9876