Christians and Computer Programming

I’ve been thinking about writing a blog entry about this topic but never could get to it. What does the Bible say about computer programming? Can Christians be programmers? If yes, how should we be writing code?

This is a very interesting topic and many developers out there who are Christians are wondering what the Bible says about programming. I will attempt to bring up a few verses from the Scriptures that will help us understand what and how we should be coding.

Do Everything For The Lord

The Bible clearly states that we should be doing everything for God’s glory – whatever it may be.

“And whatsoever ye do in word or code, do all in the name of the Lord Jesus, giving thanks to God and the Father by him.” – Colossians 3:17

Notice how I substituted the word “deed” with “code”. Deeds are the works that we do and for us programmers that means our coding. We should be striving to do everything in the name of Jesus – all for His Glory.

Give Our Best to God

Let’s say that you were making something for your wife. Would you do it carelessly without paying attention to details? No. You would sit down, plan and work on it careful so it turns out very good. How much more we should be striving to give our best to God when writing code!

“And whatsoever ye do, do it heartily, as to the Lord, and not unto men; Knowing that of the Lord ye shall receive the reward of the inheritance: for ye serve the Lord Christ.” – Colossians 3:23-24

We need to be writing code “heartily” – as to the Lord. We are not trying to impress men. We are trying to praise and serve our God with our talents.

Excel At What We Do

Giving our best can only go so far. When you don’t have much you can’t give much. This means that we need to be constantly growing and improving ourselves and what we do.

“Do you see a man who excels in his work? He will stand before kings; He will not stand before unknown men.” – Proverbs 22:29

The majority of people deceive themselves into thinking that maturity and growth will come with time. That is a big myth. We need to intentionally work on ourselves. We need to research, experiment and improve what we are good at. God gave us a brain for a reason, He wants us to use it wisely and grow in our strengths.

So let us go serve the Lord with the talents He gave us and daily working on ourselves and our skills to give only the best to God.

Ruby – Phone Number to Word Combinations

I was recently looking for a phone-number-to-words Ruby solution but could not find one. I could not even find a good algorithm in any language. This told me that I needed to write one to share with others. The following code lets you convert a phone number to possible word(s) combinations using a dictionary.

Please feel free to comment with feedback or improvements.


require 'csv'

# This class provides methods for converting phone numbers 
# to possible word matches.
#
# How to use this file:
# => ruby phone_number_converter.rb -n NUMBER
# => ruby phone_number_converter.rb -f NUMBER_FILE
# => ruby phone_number_converter.rb -n NUMBER -d DICTIONARY_FILE
# => ruby phone_number_converter.rb -f NUMBER_FILE -d DICTIONARY_FILE
#
class PhoneNumberConverter
  attr_accessor :number, :number_file, :dictionary_file

  class << self
    # This method provides all the number-to-letters
    # options for conversions.
    #
    # @return [Hash]
    def keypad
      {
        '1' => %w{1},
        '2' => %w{A B C},
        '3' => %w{D E F},
        '4' => %w{G H I},
        '5' => %w{J K L},
        '6' => %w{M N O},
        '7' => %w{P Q R S},
        '8' => %w{T U V},
        '9' => %w{W X Y Z}
      }
    end

    # This method extracts all the options provided in 
    # the command and assigns them to class variables.
    def extract_options
      ARGV.each_with_index do |arg,index|
        following_arg = ARGV[index + 1].to_s
        case arg
        when '-n'
          @number = following_arg
        when '-f'
          @number_file = following_arg
        when '-d'
          @dictionary_file = following_arg
        end
      end
    end

    # This method parses a provided dictionary file and returns
    # an array of words or returns the default dictionary array.
    #
    # @return [Array]
    def dictionary
      if @dictionary_file
        CSV.read(@dictionary_file).flatten
      else
        %w{use ruby}
      end.map(&:downcase)
    end

    # This method generates a list of phone numbers from a specified
    # file or uses one number provided in the command.
    #
    # @return [Array]
    def numbers
      if @number_file
        CSV.read(@number_file).flatten
      else
        [@number]
      end.map{|n| clean_number(n) }
    end

    # This method cleans the provided phone number.
    #
    # @param [String] number
    #  The provided phone number.
    #
    # @return [String]
    def clean_number(number)
      number.gsub(/\D/, '').strip
    end

    # This method returns an array of digits from
    # the provided number.
    #
    # @param [String] number
    #  The provided phone number.
    #
    # @return [Array]
    def array_of_numbers(number)
      number.to_s.split(//)
    end

    # This method generates all the possible partitions
    # from the provided phone number.
    #
    # [1,2,3,4] => [[[1],[2,3,4]],[[1,2],[3,4]],[[1],[2,3,4]]] ...
    #
    # @param [Array] arr_nums
    #  An array of digits from the phone number.
    #
    # @return [Array]
    def partitions(arr_nums)
      (0...arr_nums.length)
      .flat_map{|i| (1...arr_nums.length).to_a.combination(i).to_a }
      .map{|cut| i = -1; arr_nums.slice_before{cut.include?(i += 1)}.to_a }
    end

    # This method generates all the possible word(s) matches
    # for the provided number and dictionary.
    #
    # @return [Array]
    def permutations
      extract_options

      numbers.collect do |phone_number|
        partitions = partitions(array_of_numbers(phone_number))
        partitions.map do |partition| 
          partition.map do |numbers|
            numbers.map do |number|
              keypad[number]
            end.inject(&:product).map do |perms| 
              numbers.one? ? perms : perms.join
            end.select do |word| 
              dictionary.include?(word.downcase) || word.length == 1
            end.collect do |word|
              dictionary.include?(word.downcase) ? word : keypad.select{|k,v| v.include?(word) }.first[0]
            end
          end.inject(&:product).collect do |word_option| 
            word_option.is_a?(Array) ? word_option.join('-') : word_option
          end
        end.reject(&:empty?).flatten.reject do |word_option| 
          word_option.length < array_of_numbers(phone_number).length || word_option =~ /[0-9]-[0-9]/
        end.uniq
      end
    end
  end
end

permutations = PhoneNumberConverter::permutations

permutations.each do |phone_number|
  puts phone_number
end

Thanks to sawa for helping out with a part of it.

Rails Routes – Dynamic Controller or Module

I was recently looking for a solution to call the correct controller depending on other data (the user that is being viewed). If the user is an admin, call one controller. If the user is a regular user, call another controller. You could redirect to the correct controllers but it’s not elegant. You could also have the controller (or module) directly in the URL but that does not look pretty.

Since there is no Rails way of doing it (and probably not the best thing to do), here is a possible solution that will probably work:


get 'users/:id', to: 'admin/users#show', constraints: lambda { |request| 
  id = request.fullpath.gsub('/users/','').to_i
  User.find_by_id(id).admin?
}

get 'users/:id', to: 'regular/users#show', constraints: lambda { |request| 
  id = request.fullpath.gsub('/users/','').to_i
  !User.find(id).admin?
}

Thanks to kardeiz for the help. Again, this is just a possible solution that can be revised and improved until someone comes up with a Rails way of doing this.

RSpec – Reusing examples

A good practice while writing RSpec tests is to reuse similar examples to make the tests DRYer and easier to read and understand.

Create a shared_examples_for block with all the reused examples and include the block with it_behaves_like where you want to use the similar examples.


describe ".trigger_action"
  let(:subject) { User.trigger_action }

  shared_examples_for "email_sent" do
    it "sends an email" do
      expect(ActionMailer::Base.deliveries).not_to be_empty
    end
  end

  context "when valid" do
    it "is true" do
      expect(subject).to be_true
    end

    it_behaves_like "email_sent"
  end

  context "when invalid" do
    it "is false" do
      expect(subject).to be_false
    end

    it_behaves_like "email_sent"
  end
end

ATEM Wireless Tally Light

Wireless Tally Light System – Compatible with Blackmagic ATEM

If you have used the ATEM production switchers long enough you probably noticed that it’s missing a wireless tally light option. That’s no longer the case.

KvitkoIT has engineered and released a wireless tally light system for ATEM switchers which can be ordered or done as a DIY. The kit comes with a transmitter (which connects to the same network as the switcher using a Cat5 cable) and multiple receivers (which attach to your cameras using a hot shoe mount). This is all wireless so no wires are required between the transmitter and receivers.

The kit is Arduino-based so it’s fully customizable.

Check out the ATEM Wireless Tally Light Kit at KvitkoIT.

Arduino Clap Switch

Made a clap switch using Arduino. First experiment with this microcontroller. Works pretty well.

The switch that I used for the lamp can be found in Wal Mart. I opened it up, took the switch out and soldered an electric wire to the same location where the switch was.

Here it is in Wal Mart:
http://www.walmart.com/ip/GE-15-Amp-Polarized-Tap-with-Switch-White/16677117

Here is what mine looks like (used to look like that, I cleaned it up a bit):
photo (5)

The code for the Arduino clap switch is below. Some values will probably need to be adjusted depending on the environment. For example, the sound sensor was getting higher values in my office than in my bedroom. Have fun!


/*
	Arduino Clap Switch
	Artem Kalinchuk
	
	The THRESHOLD, SOUND_SAMPLE_LENGTH, 
	CLAP_DURATION_WINDOW, and CLAPS_FOR_TRIGGER are
	all adjustable values and will probably need to be 
	adjusted depending on your environment.
*/

const int SOUND_SENSOR = A0; //pin for the Grove Sound Sensor
const int LAMP_RELAY = 2; //pin for the Grove Relay
const int THRESHOLD = 400; //the sound level that will be treated as a 'clap'
const int SOUND_SAMPLE_LENGTH = 200; //the amount of ms to wait before determining to turn off/on
const int CLAP_DURATION_WINDOW = 1500; //the amount of ms max to make the number of claps specified (ms)
const int CLAPS_FOR_TRIGGER = 2; //the number of claps for the relay to trigger

//kind of used the same way as 'delay' but does not pause code.
//I use this because I have multiple 'delays' running in my original code.
//this 'delay' will make sure the relay does not switch on and off to fast.
//The current time is set to 1000 ms min (in code below)
unsigned long lastLampRelayLoop = 0;
int soundSensorReading = 0;
int soundLength = 0;
int previousSoundLength = 0;
int soundSampleLength = SOUND_SAMPLE_LENGTH;
int clapDurationWindow = CLAP_DURATION_WINDOW;
int currentClaps = 0;
int relayState = LOW;

void setup() {
  pinMode(LAMP_RELAY, OUTPUT);
}

void loop() {
  soundSensorReading = analogRead(SOUND_SENSOR);

  if (soundSensorReading >= THRESHOLD) { 
    soundLength++;
  } else {
    if (soundLength > 1) {
      previousSoundLength = soundLength;
    }

    soundLength = 0;
  }

  if (soundSampleLength == SOUND_SAMPLE_LENGTH) {
    soundSampleLength = 0;

    if (previousSoundLength > 1) { 
      clapDurationWindow = 0;
      currentClaps++;

      if (currentClaps == CLAPS_FOR_TRIGGER) {
        relayState = !relayState;

        if (millis()-lastLampRelayLoop >= 1000) {
          digitalWrite(LAMP_RELAY, relayState);
          lastLampRelayLoop = millis();
        }
      }

      previousSoundLength = 0;
    }
  }

  if (clapDurationWindow >= CLAP_DURATION_WINDOW) {
    currentClaps = 0; 
  }

  if (clapDurationWindow <= CLAP_DURATION_WINDOW) {
    clapDurationWindow++;
  }

  if (soundSampleLength < SOUND_SAMPLE_LENGTH) {
    soundSampleLength++; 
  }

  delay(1);
}

Free Group Text Messaging :: Church, youth everyone else

Many small organizations, churches and youth groups cannot afford the high priced group messaging services that many companies offer. Telefio Messaging offers a free group messaging service for small youth groups and churches.

Telefio is really nice because it has all the features that you need to notify your subscribers/members and the really cool thing about it is that it’s totally free. You can see how it works at http://telefio.com/how_it_works. I would recommend it to youth leaders, church leaders, small groups, ministry groups, worship groups or just anyone that needs a cheap (or free) group messaging service to keep in touch with his or her group.

Free youth group sms messaging

Youth Groups use Telefio Messaging to reach out via SMS

SMS Marketing and Group Messaging are widely used services by many businesses. But businesses are not the only ones that can benefit from such valuable and effective services.

The First Russian Baptist Church youth of Mount Crawford, Virginia is a youth group who has been using a group messaging service for a few years now and can’t live without it!

With 180 members, the FRBC youth pastor still manages to keep in touch with each one of them and keep everyone on the same page about current events and activities.

There are many group messaging options out there but “Telefio has to be the best group messaging service, they just understand youth leaders.” says Artem, a helper in the youth group. Telefio Messaging was created specifically for youth and church groups.

Pete Tkachuk, former FRBC youth leader, says he loves the service. “[Telefio] is a low cost … communication service that’s very user friendly and provides robust tools for managing teams…” Pete signed up for the service about 2 years ago.

You can read more about the youth group on their web page at molodezh.com (Light in the darkness).

Are you using SMS to increase awareness about your ministry? Telefio Messaging,www.telefio.com, might be your answer.