Skip to content

Instantly share code, notes, and snippets.

View detournemint's full-sized avatar
📻
On Air

detournemint

📻
On Air
View GitHub Profile
@detournemint
detournemint / gist:8531239
Created January 20, 2014 23:08
LCD ruby quiz solution
def lcd(num, size)
horizontal = Proc.new do |n|
a = []
a << " "
a << ("-" * n)
a << " "
end
vertical = Proc.new do |n|
a = []
@detournemint
detournemint / Exercise 1
Created February 14, 2014 01:58
Solutions to Metaprogramming In Ruby
$results = []
$results << class A
def initialize
@a = 11
@@a = 22
a = 33
end
@a = 1
@@a = 2
@detournemint
detournemint / gist:9357590
Last active August 29, 2015 13:57
Explanation of This in Javascript
This is set when function is called
This also depends on HOW it is called. Not how it is defined.
Examples =
constructor => this = new object ({})
var test = new Test();
method => this = receiver (test)
<div id="steps">
<h1> Steps </h1>
<h3>Step 1:</h3><label>Title: <input type='text' name='steps[1][title]'></label><label>Summary:<textarea name='steps[1][summary]'></textarea></label>
<label>Step Image: <input type="file" name="recipe[recipe_image]" accept="image/*" /></label> #thisone doesn't work
</div>
<label>Step Image: <input type="file" name="recipe[recipe_image]" accept="image/*" /></label> # this one works
@detournemint
detournemint / gist:bd4c558bca1ecf9a7bbf
Last active August 29, 2015 14:02
Javascript Button Handling
:javascript
$('.disconnect').click(function(event){
event.preventDefault();
var url = event.currentTarget.href
var isGood = confirm("Are You Sure?")
if(isGood){
$.ajax({
type:"POST",
url: url,
success: function(){
@detournemint
detournemint / index.js
Created October 3, 2014 16:55
Ajax Pagination using the Pagination from Will Paginate
$(document).ready(function() {
$('.datepicker').datepicker();
$(".tablesorter").tablesorter();
var submit = document.getElementById("submit-button");
submit.onclick = getCalendarAppointments;
$(".pagination").on("click", 'a', function(event){
event.preventDefault();
@detournemint
detournemint / gist:fbc75d110bc9948ab802
Created January 31, 2015 00:32
Ajax call to set a model attribute in coffeescript from ember.js
$.ajax
url: "http://10.0.0.75:8080/packages/" +model.get('id')+"/apk/analytics/selectors"
headers:
Authorization: 'Basic ' + Cookies.utils.readCookie('spch')
success: (response) ->
model.set("selectors", $.map response.selectors, (val) -> val['selector_type'])
error: () ->
console.log "error"
var deleteAllGroupMembers = (function () {
var deleteAllGroupMembers = {};
// the facebook ids of the users that will not be removed.
// IMPORTANT: add your own facebook id here so that the script will not remove yourself!
var excludedFbIds = ['77000939']; // make sure each id is a string!
var usersToDeleteQueue = [];
var scriptEnabled = false;
var processing = false;
deleteAllGroupMembers.start = function() {
@detournemint
detournemint / keybase.md
Created February 10, 2016 17:45
Keybase Proof

Keybase proof

I hereby claim:

  • I am greggawatt on github.
  • I am greggawatt (https://keybase.io/greggawatt) on keybase.
  • I have a public key whose fingerprint is 2F04 A420 3C8C 9750 3B89 6AD4 A164 1C99 A275 4372

To claim this, I am signing this object:

@detournemint
detournemint / gist:3909c8339529548b49d9
Created March 28, 2016 16:02
Example of agnostic relationship
class Opportunity < ActiveRecord::Base
has_many :notes
end
class Note < ActiveRecord::Base
end
On the opportunity model I want a way when the Note updates (the updated_at column changes) that a column on the opportunity (note_last_updated or similar) updates. Notes are used all over my app so i wanted to avoid having a specific after_update callback on the note model.