Skip to content

Instantly share code, notes, and snippets.

@at1as
at1as / bits.erl
Last active February 22, 2017 06:32
Assignment #1 Functional Programming in Erlang
-module(bits).
-export([bits/1, bitsNoTailRecursion/1, startTests/0]).
%% Functional Programming in Erlang
%% Kent University
%% 21 February 2017
%% Exercise 1 : Summing the Bits
%%
@at1as
at1as / facetime_kill.sh
Created December 5, 2016 05:30
Kill FaceTime app after X seconds
#!/bin/bash
# Usage : ./facetime_kill.sh 10
# Accepts 1 argument : a number of seconds before stopping app
if [[ $1 ]]
then
echo "Killing Facetime in ${1} seconds"
i=$1
@at1as
at1as / oxford_comma
Created July 4, 2016 03:26
Add oxford comma to script
jason$ echo "a, b, c and d. e, f, g, and h" | sed 's/\([^,]\)\(\ and\)/\1\,\2/g'
> a, b, c, and d. e, f, g, and h
@at1as
at1as / valid_ssn.sh
Created June 12, 2016 03:29
Generate a valid Social Security Number
#!/bin/bash
# Generate a valid Social Security Number
function generate() {
SSN=""
valid=0
for i in {1..9}; do
DIGIT=$[RANDOM%9+1]

Keybase proof

I hereby claim:

  • I am at1as on github.
  • I am willems (https://keybase.io/willems) on keybase.
  • I have a public key ASBJanSm1SKbTunlyBBTt_3BFB8mjHGMiLPmvpjFRO9Zlwo

To claim this, I am signing this object:

# A Natural Sort Algorithm in one line
ITEMS = %W(item1 item2 item11 item1 item20 item3 hello other_item other_item7 item)
TRAILING_NUM = /[0-9]*\Z/
natural_sorted = ITEMS.sort.chunk{ |y| y.gsub(TRAILING_NUM, '') }.to_a.map{ |k_v| k_v[1] }.each{ |x| x.sort_by!{ |z| z.scan(TRAILING_NUM).first.to_i }}.flatten
puts natural_sorted
# => ["hello", "item", "item1", "item1", "item2", "item3", "item11", "item20", "other_item", "other_item7"]

Plain Text Password

jason$ PASSWORD="Passw0rD"

Hashed password using md5

Safer: If someone has access to the database, they cannot see the passwords in plaintext and must run them through a hashing algorithm

jason$ echo $PASSWORD | md5
c0e49fa492cf94f8a9eab8b8166f271b
@at1as
at1as / deobfuscate.js
Last active August 29, 2015 14:26
Federal Election Deobfuscater
/* Paste into your browser console to replace all instances in FaceBook of big 3 Canadian political parties
with "Big Government Party" and their leaders with "Big Government Politician" */
function traverseDOM(node, func) {
func(node);
node = node.firstChild;
while (node) {
traverseDOM(node, func);
node = node.nextSibling;
}
@at1as
at1as / gist:c8f58e7f5d2370ca7067
Created July 16, 2015 17:52
Rails Basic Commands

Create Controller

  • rails generate controller Users new

Generate Model (also creates a migration)

  • rails generate model User name:string email:string

Create Migration

@at1as
at1as / gist:dc3a29d3b68f45d42857
Created June 11, 2015 16:53
Find Necessary Ruby Method for Desired Output
#!/usr/bin/env ruby
## Find necessary method for desired result
## entering:
## jason$ method_find.rb "HELLO" "hello"
## returns:
## HELLO.downcase == hello
## HELLO.swapcase == hello