Skip to content

Instantly share code, notes, and snippets.

@movitto
movitto / unmatched.rb
Created January 17, 2017 12:13
Unmatched Braces / Preprocessor Finder
#!/usr/bin/ruby
# search for unmatched '{' / '}' pairs and '#ifndef' / '#endif' pairs
# assuming that any given file should have fully matched sets of both
Dir.glob("src/**/*\.[h,cpp]").each { |src|
c = File.read(src)
ob = c.count('{')
cb = c.count('}')
od = c.count('#ifndef')
cd = c.count('#endif')
@movitto
movitto / lvm-parser.rb
Created March 30, 2016 01:30
LVM Parser & Block Reader
# LVM Parser & Block Reader
#
# Copyright (C) 2016 Red Hat Inc
require 'optparse'
require 'ostruct'
require 'binary_struct'
### constants
@movitto
movitto / db-dia.rb
Last active April 5, 2016 12:25
DB / Dia Diagram Comparison & Updater Tool
#!/usr/bin/ruby
# Read / write db related metadata to/from dia diagram
#
# Copyright (C) 2015-2016 - Red Hat Inc.
require 'zlib'
require 'nokogiri'
require 'optparse'
require 'active_record'
require 'active_support/core_ext/string'
@movitto
movitto / barber.ino
Last active September 26, 2015 01:55
Bitcoin Aware Barber's Pole
//// Bitcoin Barber Shop Pole
//// Author: Mo Morsi <mo@morsi.org>
//// Arduino Controller Sketch
////
//// License: MIT
//// For use at the Syracuse Innovators Guild (sig315.org)
#include <SPI.h>
#include <Ethernet.h>
@movitto
movitto / fsoup.rb
Created November 7, 2014 20:58
FileSystem Soup
# FSoup - filesystem soup
# Disk and File System Factory
#
# Licensed under the MIT license
# Copyright (C) 2014 Red Hat Inc.
$include_factories = true
module FSoup
module Util
@movitto
movitto / rels.rb
Created November 2, 2014 20:54
ReFS File Lister
#!/usr/bin/ruby
# ReFS File Lister
# Copyright (C) 2014 Red Hat Inc.
require 'optparse'
require 'colored'
FIRST_PAGE_ID = 0x1e
PAGE_SIZE = 0x4000
FIRST_PAGE_ADDRESS = FIRST_PAGE_ID * PAGE_SIZE
@movitto
movitto / resiliance.rb
Last active August 29, 2015 14:06
Ruby ReFS parser
#!/usr/bin/ruby
# resilience.rb - Ruby ReFS Parser
# Copyright (C) 2014 Red Hat Inc.
require 'optparse'
require 'colored'
FIRST_PAGE_ID = 0x1e
PAGE_SIZE = 0x4000
@movitto
movitto / ShaderParticles.js.diff
Last active January 4, 2016 01:39
Patch to squarefeet/ShaderParticleEngine adding 'spiral' emitter type
134a135,188
> /**
> * Create a new THREE.Vector3 instance and project it onto a random point
> * on a spiral (in the XY-plane) centered at `base` and with randomized radius.
> *
> * Spiral generated by rotating series of ellipses generated with the
> * specified skew in accordance with the density wave theory
> *
> * @param {THREE.Vector3} base
> * @param {Number} radius
@movitto
movitto / rubygem-json-prevalidate-conversion-classes.rb
Last active December 21, 2015 06:08
Workaround to security fix in rubygem-json commit #d0a62f3c fixing a situation which attacker could use the constant resolution mechanism in the json gem to subject the machine running it to a DoS attack. The fix involved disabling the conversion of json into ruby classes by default and recommending that the developer only enable it for validate…
require 'json'
class Class
class << self
attr_accessor :permitted_json_classes
end
def permit_json_create
Class.permitted_json_classes ||= []
unless Class.permitted_json_classes.include?(self.name)
@movitto
movitto / rubygem-json-validate-const-strings.rb
Last active December 21, 2015 06:08
Workaround to security fix in rubygem-json commit #d0a62f3c fixing a situation which attacker could use the constant resolution mechanism in the json gem to subject the machine running it to a DoS attack. The fix involved disabling the conversion of json into ruby classes by default and recommending that the developer only enable it for validate…
require 'json'
module JSON
class << self
def deep_const_get(path)
path.to_s.split(/::/).inject(Object) do |p, c|
case
when c.empty? then p
when p.constants.collect { |c| c.to_s }.include?(c)
then p.const_get(c)