Skip to content

Instantly share code, notes, and snippets.

Avatar

Michael kagemusha

View GitHub Profile
@kagemusha
kagemusha / gist:1542498
Created Dec 31, 2011
Rails include related Model in JSON Response
View gist:1542498
Tested on: Rails 3.1
In this example, you want to return as json a group of Items and the name of the Company which makes them.
Models are as follows:
class Company < ActiveRecord::Base
has_many :items
class Item < ActiveRecord::Base
@kagemusha
kagemusha / gist:5866759
Created Jun 26, 2013
Using Debugger with Grunt
View gist:5866759
version: grunt-cli v0.1.8
1. Install node-inspector globally (-g)
npm install -g node-inspector
2. Add debugger statements to your code
3. Run your grunt task in debug mode
@kagemusha
kagemusha / gist:1569836
Created Jan 6, 2012
Dump Heroku Postgres DB and load locally
View gist:1569836
Get the Heroku db as detailed here:
http://devcenter.heroku.com/articles/pgbackups#exporting_via_a_backup
1. heroku pgbackups:capture
2. heroku pgbackups:url <backup_num> #=>backup_url
- get backup_num with cmd "heroku pgbackups"
3. curl -o latest.dump <backup_url>
Then locally do:
$ pg_restore --verbose --clean --no-acl --no-owner -h localhost -U myuser -d mydb latest.dump
@kagemusha
kagemusha / gist:1660712
Created Jan 23, 2012
JQuery Datatables warning: Requested unknow parameter...
View gist:1660712
Versions: Datatables 1.8.x
If get error such as:
DataTables warning (table id = 'myTable'): Requested unknown parameter '2'
from the data source for row 0
Means num of columns in table heading and in data as specified in
aoColumns do not match. Making sure are same number should fix this.
View gist:b7f57be9becb4a054d780d8c95af22bc
echo "redoing aliases"
# alias to reload aliases in your current window
alias real=". ~/kagemusha/aliases/aliases"
# specific things i'm currently working on
alias rspet="rspec spec/controllers/api/canvas/email_templates_controller_spec.rb"
alias rspes="rspec spec/controllers/api/canvas/email_sections_controller_spec.rb"
alias dlvw="dlv debug github.com/kagemusha/vowpal_websrv -- --workers 1 --models ./sample_models"
alias 58="lsof -i tcp:5858"
@kagemusha
kagemusha / gist:2781562
Created May 24, 2012
TypeError: Cannot visit...(Rails)
View gist:2781562
Version: Rails 3.2.1
TypeError: Cannot visit Videoset
Happens when specify class for id in validations (perhaps other places), e.g.:
INCORRECT
validates_uniqueness_of :song_num, :scope=>[:videoset]
CORRECT
validates_uniqueness_of :song_num, :scope=>[:videoset_id]
@kagemusha
kagemusha / gist:b97db366ccec0fe11995c77755319295
Created Jun 19, 2018
Create postgres table with auto-incrementing primary key
View gist:b97db366ccec0fe11995c77755319295
// id SERIAL primary key
CREATE TABLE public.user_events
(
id serial primary key,
campaign_id bigint NOT NULL,
user_uuid bigint NOT NULL,
reward integer NOT NULL
)
@kagemusha
kagemusha / go get with private github repo
Created Jun 13, 2018
go get with private github repo
View go get with private github repo
1. If you are trying to `go get` a private repo, you need to be able to enter your `username` and `password` from the prompt.
To get the prompt you need to enable the git terminal prompt.
env GIT_TERMINAL_PROMPT=1 go get 'github.com/the-user/the-repo'
2. Because of 2FA you cannot use your password. You need to generate an access token and enter that in the password field
instead (you will want to copy at the clipboard on the token generation page, b/c it will be long). To generate the token, go
to [https://github.com/settings/tokens/new](https://github.com/settings/tokens/new). Or from the Github UI,
` Setting - Developer Settings - Personal access tokens`
@kagemusha
kagemusha / gist:1504625
Created Dec 21, 2011
Invalidate Session when SessionRestoreError in Rails 3.x
View gist:1504625
Tested on: Rails 3.1
If have error:
ActionDispatch::Session::SessionRestoreError (Session contains objects whose class definition isn't available.
Remember to require the classes for all objects kept in the session.
can fix by changing a char in secret token in initializers/secret_token.rb
MyApp::Application.config.secret_token
@kagemusha
kagemusha / gist:1504633
Created Dec 21, 2011
Migrate from Mongo to Postgres in Rails 3.1
View gist:1504633
Tested on: Rails 3.1, Mongoid 2.0.1, pg 0.12.0 gem
Migrate from Mongo to PG
1. remove mongoid gem
2. add pg gem
3. in application.rb re-add ActiveRecord
4. for all models
- inherit from ActiveRecord::Base
- get rid of Mongoid:Document line
- make migrations and put fields there
You can’t perform that action at this time.