Skip to content

Instantly share code, notes, and snippets.

View drhuffman12's full-sized avatar

Daniel Huffman drhuffman12

View GitHub Profile
@drhuffman12
drhuffman12 / gnuroot_wheezy86_to_jessie_jruby
Last active August 29, 2015 14:07
Upgrade gnuroot wheezy on android x86 to jessie and add Java, JRuby, Android SDK, and Ruboto gem
#
apt-get update | apt-get upgrade
# Install ant and dependancies. [Ignore errors about "libjli.so" missing; it appears to be a soft vs hard float java issue. We will replace Java in a later step.]
apt-get install ant -y
# Download Oracle Jdk 8 for Linux 32bit from: http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
# ... The download should be a file like: jdk-8u20-linux-i586.tar.gz
@drhuffman12
drhuffman12 / gnuroot_wheezyx_to_jessie_jruby
Last active February 6, 2018 05:54
Upgrade gnuroot wheezyX on android ARM to jessie and add java and jruby
# Download Oracle Jdk 8 for Linux 32bit from:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-arm-downloads-2187472.html
# ... The download should be a file like: jdk-8u33-linux-arm-vfp-hflt.tar.gz
# Download JRuby from: http://www.jruby.org/download
# ... The download should be a file like: jruby-bin-1.7.18.tar.gz, jruby-bin-9.0.0.0.pre1.tar.gz
# Install 'GNURoot' and 'GNURoot Wheezy x86' from app store, see:
# [gnuroot app](https://play.google.com/store/apps/details?id=champion.gnuroot&hl=en)
# [gnuroot repo](https://github.com/corbinlc)
@drhuffman12
drhuffman12 / av_splitter.rb
Last active August 29, 2015 14:08
Convert and split an audio/video file into 5 minute intervals of the specified target format and compression quality.
#!/usr/bin/ruby
# FILENAME: av_splitter.rb
#
# DESCRIPTION: Convert and split an audio/video file into 5 minute intervals of the specified target format and compression quality.
#
# USAGE:
# Put your audio/video files into the "in" sub-folder, then run the 'audio_splitter.rb' ruby script w/syntax:
# ruby -s audio_splitter.rb <format_out> '<bit_rate_info>' <debug_level>
#
@drhuffman12
drhuffman12 / sample_objs.rb
Last active August 29, 2015 14:10
Simple Object-oriented example in Ruby
# Official site for the Ruby language: "https://www.ruby-lang.org/"
class C1
attr :a, :b
def initialize(a)
@a = a
end
def self.hi
puts 'hello world'
@drhuffman12
drhuffman12 / pw_from_console.rb
Last active August 29, 2015 14:12
Get password from console via Java and JRuby
# GIST: "pw_from_console.rb" under "https://gist.github.com/drhuffman12"
# If you're dealing with a Java character array (such as password characters that you read from the console), you can convert it to a JRuby string with the following Ruby code:
jconsole = Java::java.lang.System.console()
password = jconsole.readPassword()
ruby_string = ''
password.to_a.each {|c| ruby_string << c.chr}
# .. do something with 'password' variable ..
puts "password_chars: #{password_chars.inspect}"
@drhuffman12
drhuffman12 / gem-fetch-dependencies.rb
Last active April 12, 2018 12:40 — forked from Milly/gem-fetch-dependencies
Extend 'gem fetch' command. Fetch all dependencies. Handles OS (Windows vs non-Windows) and Ruby Platform (JRuby vs Ruby).
#!/usr/bin/ruby
=begin
## USAGE:
# Ruby:
ruby gem-fetch-dependencies.rb fetch <gem_name> --dependencies
# JRuby:
jruby gem-fetch-dependencies.rb fetch <gem_name> --dependencies
=begin
https://gist.github.com/drhuffman12/a5ad839b71e8ca334a2a
Problem statement:
Create a class named PalindromeDetector. Within that class, implement a
static function named GetPalindromeYears that takes a start and end date as parameters and
returns a distinct set of Dates in chronological order(inclusive of start and end dates)
that, when formatted as MMddyyyy, are palindromes.
@drhuffman12
drhuffman12 / rvm_proj_new.sh
Last active September 9, 2016 17:56
Helper script to create a Ruby app folder (w/ a '.versions.conf' file) and configure RVM
#!/usr/bin/env bash
me="$(basename "$(test -L "$0" && readlink "$0" || echo "$0")")"
# echo $me
if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ] || [ -z "$4" ]
then
echo
echo 'To create a Ruby app folder and configure it for RVM usage, use the following syntax:'
echo
echo ' bash --login './$me 'PROJ_ROOT PROJ_NAME PROJ_RUBY_VER PROJ_GEMSET_NAME'
echo
@drhuffman12
drhuffman12 / test_fiber_d_loops.cr
Last active September 28, 2016 11:22
Benchmark threads (Conclusion: best is either loops or fibers, depending on use case; threads are problematic, tending to either lock or crash the app)
require "benchmark"
require "big"
# def fib(n : BigInt)
# n < 2 ? n : fib(n-1) + fib(n-2)
# end
struct BigInt
def add!(other : BigInt) : BigInt
LibGMP.add(self, self, other)
@drhuffman12
drhuffman12 / po2.rb
Created October 17, 2016 20:36
Check if numbers are power of 2
# based on http://stackoverflow.com/questions/29718767/check-if-array-elements-are-power-of-two
require 'benchmark'
class Po2
def self.via_to_s(n)
(n.to_s(2) =~ /^10*$/) ? 0 : 1 # faster for more than about 100 numbers
end
def self.via_log(n)