Skip to content

Instantly share code, notes, and snippets.

View dacur's full-sized avatar

David Curtis dacur

  • Raleigh, North Carolina
View GitHub Profile
@dacur
dacur / 0_reuse_code.js
Created June 10, 2014 22:50
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
// Load the SDK asynchronously
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
window.fbAsyncInit = function() {
@dacur
dacur / background-image.css
Created June 12, 2014 12:47
Creating a full-screen, scalable, responsive background image with CSS.
html {
height: 100%;
background: url(bg.jpg) no-repeat center center;
background-size: cover;
}
@dacur
dacur / statuses_controller.rb
Created June 12, 2014 13:00
Using logger to debug in Rails. You can include logger statements in controllers and models. The example below will inspect each status element and display all information in the console (log). This can help you determine what is going on at certain points in your application.
def index
logger.debug @statuses.inspect
end
@dacur
dacur / autogrow.js
Created June 13, 2014 16:14
Autogrow.js allows a textbox to grow in size vertically instead of populating a scroll bar and hiding text while you continue to type. Example below is used in conjunction with Bootstrap and AJAX. The last few lines of code reset the box size each time "submit" button is clicked; otherwise, the text box remains the last (larger) size after click…
(function($){
//pass in just the context as a $(obj) or a settings JS object
$.fn.autogrow = function(opts) {
var that = $(this).css({overflow: 'hidden', resize: 'none'}) //prevent scrollies
, selector = that.selector
, defaults = {
context: $(document) //what to wire events to
, animate: true //if you want the size change to animate
, speed: 200 //speed of animation
, fixMinHeight: true //if you don't want the box to shrink below its initial size
@dacur
dacur / kill_rails_server_command
Created June 18, 2014 21:33
How to kill an instance of rails server that is running. Useful when you get the error message that says that address localhost:3000 is being used somewhere else (i.e. the rails server did not shut down properly). http://stackoverflow.com/questions/4473229/rails-server-says-port-already-used-how-to-kill-that-process
//On any command line:
lsof -wni tp:3000
//You will see a column labeled "PID". Get that number.
kill -9 PID#HERE //e.g. kill -9 704
//If this fails, RESTART machine => has worked before
@dacur
dacur / remove_dir.txt
Created June 24, 2014 14:34
Remove a folder (directory) and all associated files within the folder.
rm -rf testapp
@dacur
dacur / vagrant_provision
Created June 26, 2014 14:10
Vagrant is already provisioned error when trying to run "vagrant up". Just run "vagrant ssh" and it will start the machine.
vagrant ssh
@dacur
dacur / employees.js
Created July 4, 2014 20:38
Dynamically add JSON elements to HTML using jQuery.
$(document).ready(function () {
$.getJSON('../data/employees.json', function (data) {
var statusHTML = '<ul class="bulleted">';
$.each(data,function (index, employee) {
if (employee.inoffice === true) {
statusHTML +='<li class="in">';
} else {
statusHTML +='<li class="out">';
}
statusHTML += employee.name + '</li>';
@dacur
dacur / button_selected.js
Created July 5, 2014 17:11
Highlighting a button when clicked with CSS and jQuery.
$(document).ready(function () {
$('button').click(function () {
$("button").removeClass("selected"); //make sure all other
//buttons aren't highlighted
$(this).addClass("selected"); //then highlight clicked button
});
}); // end ready