Skip to content

Instantly share code, notes, and snippets.

@topher6345
topher6345 / counter.asm
Last active August 29, 2015 14:11
ASM Counter
; COUNTER
JMP start
start:
CALL counter
counter:
POP D ; Avoid stack overflow
INC A ; A++
@topher6345
topher6345 / inline_css.rb
Created November 30, 2014 02:32
Inline CSS in Built Jekyll Project.
Dir[File.join('_site', '**', '*')].reject { |p| File.directory? p }
.reject { |filename| !filename[/\.html/] }
.each do |file|
main_css = File.read('_site/css/main.css')
old_contents = File.read(file)
new_contents = old_contents.gsub(
"<link href='css/main.css' rel='stylesheet'>",
"<style>#{main_css}</style>"
)
File.open(file, 'w') { |newfile| newfile.write(new_contents) }
@topher6345
topher6345 / jekyll_gzip.rb
Created November 30, 2014 02:30
GZIP all files in a built Jekyll Project.
require 'zlib'
Dir[File.join('_site', '**', '*')].reject { |p| File.directory? p }
.each do |oldfile|
old_file_text = File.read(oldfile)
open(oldfile, 'wb') do |file|
gzip = Zlib::GzipWriter.new(file)
gzip << old_file_text
gzip.close
end
@topher6345
topher6345 / uglify.rb
Created November 30, 2014 02:29
Uglify Javascripts in a Jekyll Project.
require 'uglifier'
Dir[File.join('_site', '**', '*')].reject { |p| File.directory? p }
.each do |file|
next unless file[/\.js/]
compressed = Uglifier.compile(
File.read(file)
)
File.open(file, 'w') { |newfile| newfile.write(compressed) }
puts "#{file} uglified."
@topher6345
topher6345 / main.md
Last active August 29, 2015 14:06
Execute rake task from cron job on raspberry pi

* * * * * cd /home/pi/Sites/testapp &amp;&amp; /home/pi/.rvm/bin/rvm all do bundle exec rake sendemail:send &gt;&gt; /home/pi/Sites/testapp/log/cronlog.txt

@topher6345
topher6345 / gist:f72e04668c32ab9df1eb
Last active August 29, 2015 14:05
Ruby OO helpers

Get all inherited objects and include'd mixins

User.ancestors

Get all methods that an object has

User.methods

FoodParser.methods.include?(:new) 
@topher6345
topher6345 / alphabetize.rb
Last active August 29, 2015 14:05
Alphabetize Yaml file
require 'yaml'
puts YAML.load_file(ARGV[0].to_s).sort
@topher6345
topher6345 / fizzbuzz.rb
Last active August 29, 2015 14:04
Everyone loves FizzBuzz
# functional but linter hates it
(1..100).map {|e| (e % 15).zero? ? "FizzBuzz": (e % 3).zero? ? "Fizz" : (e % 5).zero? ? "Buzz": e }.each {|e| puts e }
@topher6345
topher6345 / derivative.md
Last active August 29, 2015 14:04
Lisp - Derivative