Skip to content

Instantly share code, notes, and snippets.

@nixpulvis
nixpulvis / triangle.scss
Created January 30, 2014 19:57
Make some pretty triangles.
@mixin triangle($size, $color, $direction) {
width: 0;
height: 0;
@if $direction == 'up' {
border-left: $size solid transparent;
border-right: $size solid transparent;
border-bottom: $size solid $color;
} @elseif $direction == 'down' {
border-left: $size solid transparent;
@nixpulvis
nixpulvis / exceptions.rb
Created February 19, 2014 20:03
Add pundit authorization to Rails exception logic.
module ActionDispatch
class ExceptionWrapper
@@rescue_responses.merge!('Pundit::NotAuthorizedError' => :forbidden)
end
end
@nixpulvis
nixpulvis / palindate.rb
Last active August 29, 2015 13:58
Palindates!
require 'date'
def palindate?(date)
padded_month = "%02d" % date.month
padded_day = "%02d" % date.day
both_pad = "#{padded_month}#{padded_day}#{date.year}"
month_pad = "#{padded_month}#{date.day}#{date.year}"
day_pad = "#{date.month}#{padded_day}#{date.year}"
@nixpulvis
nixpulvis / simple_cookie_session.rb
Last active August 29, 2015 14:01
Simplistic Cookie Session
@nixpulvis
nixpulvis / contiguous_2d_matrix.c
Last active August 29, 2015 14:01
Contiguous 2D Matrix C99
int main(int argc, char **argv) {
size_t rows = atoi(argv[1]);
size_t columns = atoi(argv[2]);
/* This is really cool!!! */
int (*matrix)[columns] = malloc(sizeof(*matrix) * rows);
if (matrix) {
matrix[0][0] = 13;
matrix[1][0] = 1;
@nixpulvis
nixpulvis / cfg.rb
Last active August 29, 2015 14:02
Scalar register propagation.
require 'pp'
class BasicBlock
include Enumerable
attr_accessor :instructions, :children
def initialize(&block)
@instructions = []
@children = []
@nixpulvis
nixpulvis / unused_define.rb
Created August 18, 2014 21:30
Simple unused #define finder.
#!/usr/bin/env ruby
require 'pp'
if ARGV[0]
# Collect defines.
defines = {}
Dir.glob("#{ARGV[0]}/**/*.{c,h}") do |path|
File.open(path, "r") do |file|
@nixpulvis
nixpulvis / lambda_fib.rkt
Created October 12, 2014 21:16
Lambda Fibonacci
;; Credit Eli Barzilay
(λ(f)(λ
(x)(((x(λ(
x)(λ(x y)y)
)(λ(x y)x))(
x(λ(x)(λ(x y)
y))(λ(x y
)x))(((
x(λ(p)(
;; A macro that defines a PDA language
(define-syntax pushdown
(syntax-rules (: ->)
[(pushdown init-state end-state
[state : (input-stream input-stack -> new-state new-stack) ...]
...)
(lambda (string)
(: state : (Listof Token) (Listof Token) -> Boolean)
...
(define (state stream stack)
<?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>ANSIBrightBlackColor</key>
<data>
YnBsaXN0MDDUAQIDBAUGFRZYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
AAGGoKMHCA9VJG51bGzTCQoLDA0OVU5TUkdCXE5TQ29sb3JTcGFjZVYkY2xhc3NPECcw
LjQ1ODgyMzU2MTcgMC40NDMxMzcyODgxIDAuMzY4NjI3NDU4OAAQAoAC0hAREhNaJGNs
YXNzbmFtZVgkY2xhc3Nlc1dOU0NvbG9yohIUWE5TT2JqZWN0XxAPTlNLZXllZEFyY2hp