git push -f origin master
Latest Event Updates
How do you paste source code into wordpress?
For sometime, I was posting source code as plain text, I knew there was a better way.
just wrap your code as such between code language tags as such:

Supported formats are :
- actionscript3
- bash
- clojure
- coldfusion
- cpp
- csharp
- css
- delphi
- diff
- erlang
- fsharp
- go
- groovy
- html
- java
- javafx
- javascript
- latex (you can also render LaTeX)
- matlab (keywords only)
- objc
- perl
- php
- powershell
- python
- r
- ruby
- scala
- sql
- text
- vb
- xml
Looks like wordpress has a nice support page up about it
Rails: stop ActiveRecord::RecordNotFound from breaking app
Was building a rails api backend, but when I would search for a record that was not found, the app would show the error. That is great for testing, but I wanted to handle the error without a 404 since this is an api and wanted to send a specific json message.
Found the solution as such:
class YourController < ActionController::Base rescue_from ActiveRecord::RecordNotFound, with: :dude_wheres_my_record def show # your original code without the begin and rescue end def dude_where_my_record # special handling here end end
Found on stack overflow thanks to noodl
Drop a database from postgres
in bash
type psql
\list or \l to list your database
terminate any connections by using the following command. example if databse named YourDatabase
select pg_terminate_backend(pid) from pg_stat_activity where datname=’YourDatabase’;
*use procid instead of pid for older versions of postgres
DROP DATABASE “YourDatabase”;
Now your database is gone.
https://stackoverflow.com/questions/7073773/drop-postgresql-database-through-command-line for reference
Cannot push commit to github :
Error:
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., ‘git pull …’) before pushing again.
hint: See the ‘Note about fast-forwards’ in ‘git push –help’ for details.
hint: Updates were rejected because the remote contains work that you do
FIX
error: src refspec master does not match any.
Started a new react app and wanted to get it on github
Got this error when I ran
// ♥ git push -u origin master
error: src refspec master does not match any.
error: failed to push some refs to “repo address”
what was the problem?
I didnt have any commits!
one commit and push later all is well
Render files and images for Rails 5 api only
I had built a rails 5 api only app. By installing the app only version of rails, I lost the view layer of rails. No app/assets, or public files.
This is of course the intended design for an api application but my projects also needed to reference locally stored images. How to overcome?
Example: I need to fetch http://mysite/images/image5.jpg
Solution:
#config/routes.rb . #add a route
get ‘images/:id’, :to => ‘images#show’
#app/controllers/images_controller.rb #create this file, make class ImagesController,
#add method below
def show
id = params[:id] #this will get the filename
send_file Rails.root.join(“public”, “#{id}.jpg”), type: “image/gif”, disposition: “inline” . #send the file requested, files stored in public
end
This is a word around and there could (probably is) a better way, but it worked to get the project going. During refactor, we can change this and look for a better solution of need be. This was better than having to start a new rails5 app from scratch.
Uncaught (in promise) SyntaxError: Unexpected end of JSON input
getting this error when using fetch to connect to my rails api
fetch(`/products/${dataid}/description`)
.then(res=>res.json())
.then(json=>console.log(json))
in the browser I was able to get to the page
http://127.0.0.1:3000/products/11/description
answer
rails action was rendering basic text not json, so I had to change fetch
***Rails
def description
product=Product.find(params[:id])
if product
if product.description
render plain: product.description
else
render plain: “No description”
end end end
***JS
fetch(`/products/${dataid}/description`)
.then(res=>res.text()) //<————————————-
.then(json=>console.log(json))
Could not find an executable [“phantomjs”] on your path.
ERROR:
Got this error when running rspec.
1.2) Failure/Error:
raise Dependency::NotFound.new(
“Could not find an executable #{@executables} on your path.“)
Cliver::Dependency::NotFound:
Could not find an executable [“phantomjs”] on your path.
FIX:
gem 'phantomjs', :require => 'phantomjs/poltergeist'
I added this to my gem file, under group :development, :test do and ran bundle install
After that this error didnt come up
answer found on https://github.com/learn-co-curriculum/your-own-js-and-css-in-rails/issues/7
Ah grep you are a time saver
Searching for a function valid_move that was made in one of my tttt dirs
How to quickly find it with out manually going to each file?
grep -R “valid_move” ttt*
MONGODB: What is a projection?
A projection is when you search for documents in MongoDB but only get back the fields that you request.
example records {name: “Tom”, age: “35”, zipcode: “10003”,_id:778789754}
using projection for name and zipcode: {name: “Tom”, zipcode: “10003”}
var mongo = require(“mongodb”).MongoClient;
var url = “mongodb://localhost/addressbook”;
var collectionName = “friends”;
mongo.connect(url,function(err,db){
if(err) console.log(err)//throw err;
else{
var collection = db.collection(collectionName);
collection.find({},{name: 1, age: 0,_id:0,zipcode: 0}).toArray( function(err,documents){
if(err) console.log(err)//throw err;
else{
console.log(documents)
}
});
db.close();
}
})