Skip to content

Instantly share code, notes, and snippets.

View alastairparagas's full-sized avatar

Alastair Paragas alastairparagas

View GitHub Profile
@alastairparagas
alastairparagas / app.css
Last active August 29, 2015 13:57
Worship Jesus Fellowship Mobile App - Powered with Ionic Framework and Phonegap Cordova
.side-menu-buttons a{ text-align:center; color:#555; }
.align-center{
text-align:center;
}
img{
width:100%;
height:auto;
}
@alastairparagas
alastairparagas / Database-Filesystem Cleaner
Created July 20, 2014 04:30
Looks for file locations stored in the database and if there are files in the filesystem that do not exist in the database, they are deleted. At the end of execution, an array of images that were found in the database but not in the filesystem are var_dumped.
<?php
$connect = mysqli_connect("localhost", "root", "", "r8m3");
$query = mysqli_query($connect, "SELECT * FROM images");
$images = array();
while($result = mysqli_fetch_assoc($query)){
$images[] = $result["id"];
}
@alastairparagas
alastairparagas / HackReactorJsTest.js
Last active August 29, 2015 14:04
Hack Reactor Interview History
each([1, 2, 3], function (val) {
console.log(val);
});
// 1
// 2
// 3
var each = function (array, callback) {
// Including array.length as variable declaration to "cache" it
@alastairparagas
alastairparagas / imagecrop-example.php
Last active August 29, 2015 14:05
Image Crop that sets the the image's new width and height based on the ratio of the x/y coordinates when using some Javascript image cropping tool.
<?php
$image = $inputs['image'];
/*
When I refer to the "front-end image", I mean the uploaded version of the image you see
in jCrop/cropping screen in the webpage of the site, NOT the actual file.
Omitted variable declarations:
@alastairparagas
alastairparagas / q-all-promises
Created August 23, 2014 15:19
Example of Q all Promise Gist
(function (window) {
'use strict';
var angular = window.angular;
angular.module('myhonorsCitizenship').factory('CitizenshipService', ['FirebaseIO', 'UserService', 'FirebaseCollection', '$q', 'EventService', function (FirebaseIO, UserService, FirebaseCollection, $q, EventService) {
var citizenshipFactory = {
@alastairparagas
alastairparagas / Javascript
Last active August 29, 2015 14:11
Javascript Fundamentals
(function() {
var pElements = document.getElementsByTagName("p"); //NodeList
var pElement = document.getElementById("foo");
}());
@alastairparagas
alastairparagas / cracklePop.php
Created March 2, 2015 03:20
Crackle Pop - Factorization
<?php
// In PHP, variables are function-scoped. Use call_user_func to prevent global pollution.
call_user_func(
function() {
for ($i=1; $i<101; $i++) {
// Reset variables every loop as PHP variables are function scoped, not block scoped.
$divisibleBy3 = false;
@alastairparagas
alastairparagas / countingBitString.js
Last active August 29, 2015 14:17
Amount of bitstrings that are of length 10 and that do not contain "11". There are 144 such possibilities.
/*
Written by: Alastair Paragas
Run the program by copy/pasting this code to http://repl.it/languages/JavaScript.
This program finds how many bitstrings of length 10 does not contain a set of two consecutive 1s
*/
(function (window) {
'use strict';
var binaryRepresentation,
@alastairparagas
alastairparagas / fibonacci.js
Last active August 29, 2015 14:19
Fibonacci Sequence Adder Game in Javascript. Got bored while doing homework so I wrote this in ~10 minutes. F12 on your browser, copy the code, paste it in that window that shows up (called a Developer Console) and play along!
// Function scoped - prevent global namespace pollution
(function (window) {
'use strict';
// Bootstraps our Fibonacci program
function runProgram() {
/*
Recursive function with two base cases:
First 2 terms of Fibonacci sequence are 0 and 1.
@alastairparagas
alastairparagas / events.js
Created May 6, 2015 18:52
Listing elements of a Firebase node to a page
(function (window) {
'use strict';
var FirebaseRef = new window.Firebase("firebase-url-here"),
document = window.document;
FirebaseRef.on("value", function (eventsSnapshot) {
var events = eventsSnapshot.val(),
eventsListed = {},
eventsDateSorted = [],