Skip to content

Instantly share code, notes, and snippets.

View ZackMattor's full-sized avatar

Zachary Mattor ZackMattor

View GitHub Profile
@ZackMattor
ZackMattor / gist:5292165
Last active December 15, 2015 16:49
Trying to get more fields in my query, other than what the model represents?..
Console output:
7: def popular_tags
8: #Tag.find(:all)
9: tags = select('max(topics.tag_id) as "id", count(*) as "number_tagged", max(tags.title) as "title"').joins(:topics).group('tag_id').find(:all)
=> 10: binding.pry
11: end
[1] pry(Tag)> tags
=> [#<Tag id: 15, title: "Java">]
@ZackMattor
ZackMattor / remove_debugging
Created April 18, 2013 16:18
This pre-commit hook searches all of your staged files for debug statements (defined in the grep_search variable), and fails to commit if they are present. It also asks you if you want to have them automatically removed for your commit.
#!/bin/sh
txtrst=$(tput sgr0) # Text reset
txtred=$(tput setaf 1) # Red
exit_status=0
staging_modified=0
grep_search="binding.pry\\|console.log\\|debugger"
class CreateProjectUsers < ActiveRecord::Migration
def change
create_table :project_users do |t|
t.integer :user_id
t.integer :project_id
t.timestamps
end
add_index :project_users, [ :user_id, :project_id], unique: true
@ZackMattor
ZackMattor / Style.css
Last active December 17, 2015 19:59
Rotating Banner
#splashcontent {
font-family: Arial, Helvetica, sans-serif;
margin:0 0 0 4px;
background-color:#fff;
width:760px;
position: relative;
height:182px;
background-image: url('images/banner_image.png');
}
@ZackMattor
ZackMattor / projects.rb
Created June 2, 2013 02:37
Double relationship between users and projects. Projects have many users that can work on them, and projects have one user who is the original creator.
class Project < ActiveRecord::Base
attr_accessible :author, :description, :name, :user_ids
has_and_belongs_to_many :users
belongs_to :author, :class_name => "User", :foreign_key => "author"
end
@ZackMattor
ZackMattor / gist:5796684
Created June 17, 2013 13:00
m3u8 stream. Open in safari on mac.
<html>
<head>
<title>Streaming</title>
</head>
<body>
<video controls src="http://nlds138.cdnak.neulion.com/nlds/nhl/bruins/as/live/bruins_hd_4500.m3u8"></video>
</body>
</html>
@ZackMattor
ZackMattor / gist:5808759
Created June 18, 2013 20:01
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'NOT NULL, state smallint DEFAULT 0 NOT NULL, catid bigint DEFAULT 0 NO' at line 7
CREATE TABLE d6twp_content (
id int(11) NOT NULL,
asset_id bigint DEFAULT 0 NOT NULL,
title varchar(255) DEFAULT '',
alias varchar(255) DEFAULT '',
introtext text NOT NULL,
fulltext text NOT NULL,
state smallint DEFAULT 0 NOT NULL,
catid bigint DEFAULT 0 NOT NULL,
created timestamp DEFAULT 0,
@ZackMattor
ZackMattor / List
Last active December 19, 2015 11:59
Motors and props
Some of the props that I have
-------
http://www.hobbyking.com/hobbyking/store/uh_viewItem.asp?idProduct=18768
http://www.hobbyking.com/hobbyking/store/uh_viewItem.asp?idProduct=11333
Motor
------
(hexTronik DT750) http://www.hobbyking.com/hobbyking/store/uh_viewItem.asp?idProduct=6247
@ZackMattor
ZackMattor / ComponentSerializer.rb
Created July 11, 2013 19:33
Doesn't seem to want to load embeded data
class ComponentSerializer < ActiveModel::Serializer
embed :ids
attributes :id,
:back_image,
:cols,
:front_image,
:name,
:rows
has_many :parts, include: true
#include <iostream>
using namespace std;
int main() {
char name[15];
cout << "Please enter your name";
cin >> name;