Skip to content

Instantly share code, notes, and snippets.

View piqueen314's full-sized avatar

Cece Hedrick piqueen314

View GitHub Profile
@piqueen314
piqueen314 / rotate_lines.vim
Created July 3, 2016 20:00 — forked from anonymous/rotate_lines.vim
Vim rotating lines "screensaver"
" Press \r to start rotating lines and <C-c> (Control+c) to stop.
function! s:RotateString(string)
let split_string = split(a:string, '\zs')
return join(split_string[-1:] + split_string[:-2], '')
endfunction
function! s:RotateLine(line, leading_whitespace, trailing_whitespace)
return substitute(
\ a:line,
@piqueen314
piqueen314 / g8
Created December 11, 2015 06:37
Write a function that splits an array (first argument) into groups the length of size (second argument) and returns them as a multidimensional array.
// Bonfire: Chunky Monkey
// Author: @piqueen314
// Challenge: http://www.freecodecamp.com/challenges/bonfire-chunky-monkey
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function chunk(arr, size) {
var newArr = [];
for (var i=0; i < arr.length; i+=size)
newArr.push(arr.slice(i,i+size));
return newArr;
@piqueen314
piqueen314 / g7
Created December 11, 2015 05:43
Truncate a string (first argument) if it is longer than the given maximum string length (second argument). Return the truncated string with a "..." ending.
// Bonfire: Truncate a string
// Author: @piqueen314
// Challenge: http://www.freecodecamp.com/challenges/bonfire-truncate-a-string
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function truncate(str, num) {
// Clear out that junk in your trunk
if(num <=3)
{
return str.slice(0,num)+"...";
@piqueen314
piqueen314 / gist6
Created December 11, 2015 05:24
Repeat a given string (first argument) n times (second argument). Return an empty string if n is a negative number.
// Bonfire: Repeat a string repeat a string
// Author: @piqueen314
// Challenge: http://www.freecodecamp.com/challenges/bonfire-repeat-a-string-repeat-a-string
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function repeat(str, num) {
// repeat after me
var newStr="";
for(var i=0; i<num; i++){
newStr=newStr.concat(str);
@piqueen314
piqueen314 / gist5
Created December 11, 2015 05:00
Check if a string (first argument) ends with the given target string (second argument).
// Bonfire: Confirm the Ending
// Author: @piqueen314
// Challenge: http://www.freecodecamp.com/challenges/bonfire-confirm-the-ending
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function end(str, target) {
// "Never give up and good luck will find you."
// -- Falcor
lenStr=str.length;
lenTar=target.length;
@piqueen314
piqueen314 / gist 4
Created December 11, 2015 02:41
Return an array consisting of the largest number from each provided sub-array. For simplicity, the provided array will contain exactly 4 sub-arrays.
// Bonfire: Return Largest Numbers in Arrays
// Author: @piqueen314
// Challenge: http://www.freecodecamp.com/challenges/bonfire-return-largest-numbers-in-arrays
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function largestOfFour(arr) {
// You can do this!
var newArr=[];
@piqueen314
piqueen314 / gist4
Created December 11, 2015 02:28
Return the provided string with the first letter of each word capitalized. Make sure the rest of the word is in lower case.
// Bonfire: Title Case a Sentence
// Author: @piqueen314
// Challenge: http://www.freecodecamp.com/challenges/bonfire-title-case-a-sentence
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function titleCase(str) {
var words=str.split(" ");
for(var i=0; i<words.length; i++)
{
words[i]=words[i].toLowerCase();
@piqueen314
piqueen314 / gist3
Created December 11, 2015 01:43
Return the length of the longest word in the provided sentence.
// Bonfire: Find the Longest Word in a String
// Author: @piqueen314
// Challenge: http://www.freecodecamp.com/challenges/bonfire-find-the-longest-word-in-a-string
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function findLongestWord(str) {
var words=str.split(" ");
var max=0;
for (var i=0; i < words.length; i++)
{
@piqueen314
piqueen314 / gist2
Created December 11, 2015 01:37
Return true if the given string is a palindrome. Otherwise, return false.
// Bonfire: Check for Palindromes
// Author: @piqueen314
// Challenge: http://www.freecodecamp.com/challenges/bonfire-check-for-palindromes
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function palindrome(str) {
// Good luck!
str=str.toLowerCase();
str=str.replace(/\W/g,"").replace(/[_]/g,"");
@piqueen314
piqueen314 / gist:e8a3351ef1ae1e5b0a17
Created December 11, 2015 00:44
Return the factorial of the provided integer.
// Bonfire: Factorialize a Number
// Author: @piqueen314
// Challenge: http://www.freecodecamp.com/challenges/bonfire-factorialize-a-number
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function factorialize(num) {
var fac=1;
if (num ===0){
return fac;
}