Skip to content

Instantly share code, notes, and snippets.

View hjc's full-sized avatar

Hayden Chudy hjc

  • Mobile, AL
  • 03:52 (UTC -05:00)
View GitHub Profile
@hjc
hjc / add_to_assoc_ordered+numeric.php
Last active October 2, 2015 01:57
PHP: Add a key to an associative array and keep it's key ordering intact and sequential
/**
* Implements add_to_assoc_numeric
*
* Goal of this function is to allow us to modify an associative, numeric array
* (one that uses string numbers as keys, so there is no 0,1,2,3 ordering, but
* rather the ordering is based on when the keys were inserted [they are treated
* like other string keys]). If we modify this array using array_unshift or
* array_shift, we destory this associative, numeric structure (each key is
* destroyed and the array is simply renumbered, with ints, from 0 to num_elems),
* which we don't want. This function will allow us to insert a new value anywhere
@hjc
hjc / Fixnum_DateTime_Extensions.rb
Last active December 10, 2015 10:08
Simple extension of Fixnum to help with manipulating dates and times.
class Fixnum
def seconds
self
end
def minutes
self * 60
end
def hours
self * 60 * 60
end
@hjc
hjc / analyzer.rb
Created January 4, 2013 06:36
Simple Ruby Text Analyzer. Grabs simple document metrics from a text file, such as sentence count, word count, average words per sentence, etc.
#
# TEXT ANALYZER
# BY: Hayden Chudy
#
# basic setup for text analysis
stopwords = %w{the a by on for of are with just but and to the my I has some in}
lines = File.readlines(ARGV[0])
line_count = lines.size
text = lines.join
@hjc
hjc / oo_example.rb
Created January 8, 2013 08:31
A simple script that shows how Ruby's basic OO concepts work and some common errors.
# Simple example of basic object oriented concepts and how they work in Ruby
#
# AUTHOR: HAYDEN CHUDY
# First is instance and class variable example
# parent class, keep track of the count of all its children
class Shape
# count class variable. Keeps count of all shapes we have made, in general
# On Virtual Box?
# Ensure your networking type is bridged interface or this will fail
sudo vim /etc/network/interfaces
# comment (#) out all lines that are there and add this to the bottom (however, replace
# the * in the address with whatever you want the static IP to be, e.g., my goal is a
# static IP of: 192.168.1.140, so the address line should be: address 192.168.1.140):
auto lo eth0
@hjc
hjc / autoFocus.js
Created June 18, 2013 14:27
Simple Knockout Binding Handler to enable auto focusing fields (i.e. when one field gets max input, jump to the other).
/**
* This binding has required parameters and should be an object, they are:
*
* observable - the observable we want to look at and evaluate to see if we
* should change focus
*
* evaluator - a function to determine if we should change focus. It should
* return true whenever we want to change focus and false otherwise, see
* below for how to add extra arguments onto the function. Any function can
* be used as long as you can provide the correct scope for it from the HTML
@hjc
hjc / bools.php
Created June 25, 2013 23:36
A small and simple array to convert any and all truthy/falsey values into a hard true or false, in PHP.
<?php
//I don't play this mismatched boolean logic bullshit, its true or
// false, never 1 or 0
$bool_replaces = [
'0' => false,
"1" => true,
false => false,
true => true,
0 => false,
1 => true,
@hjc
hjc / gist:6496375
Last active December 22, 2015 15:59
SSH config that tries to stop some of the NSA horseshit.
Host *
ServerAliveInterval 10
IdentitiesOnly yes
Cipher blowfish
Ciphers blowfish-cbc
AskPassGUI no
CheckHostIP yes
Compression no
ForwardAgent no
ForwardX11 no
@hjc
hjc / id_rsa.pub
Created September 9, 2013 16:16
Public key
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAvfyNPxR68k0zfNOXIHMipMwPqHie3JBzoyusrZHlDC8O0CEjP3iDppVZrfMgRJlEB4EhZcXKb45Mc7LeJd4aLOK7//GzG46p98+8rg0ursBlX5iL0zDJUn42M7a2hLWuRiB1DcIuyeQNp8fux0N4ur7HizDLtnUk20xsKfV6L55OsMszC0nTV+CW2hmKUkWbxer339u87duie0iE57cs/WyTZDiLeWZJQ4pOUpR95nu0dqUdgU1nnPxQmSI2bnsQ+9TqwSqvoXaZTpG0vUX6PzNYaLHuCOCA5XFPnNVVEkAjGf5Py8Om1YH/cAZh2o7cc0ZV9D5sYljapBnKRSH4Aw== hjc1710@gmail.com
@hjc
hjc / no_screensaver.sh
Created May 6, 2014 18:49
NO DAMN SCREENSAVERS
no-screensaver () {
COUNTER=0;
while [ $COUNTER -ne "-1" ]; do
xdotool mousemove $COUNTER 0
COUNTER=$(echo "$COUNTER + 5" | bc)
if [ $COUNTER -eq "255" ]; then
COUNTER=0
fi
sleep 7m;
done