Skip to content

Instantly share code, notes, and snippets.

View alxzoomer's full-sized avatar
:octocat:
Coding...

Alexey Nikitin alxzoomer

:octocat:
Coding...
View GitHub Profile
@alxzoomer
alxzoomer / gist:e2a005c504298bd260676a6cbb002f71
Last active February 25, 2017 18:30
Electron menu doesn't support removing menu items
@alxzoomer
alxzoomer / registrations_controller.rb
Created December 23, 2016 09:54 — forked from jwo/registrations_controller.rb
API JSON authentication with Devise
class Api::RegistrationsController < Api::BaseController
respond_to :json
def create
user = User.new(params[:user])
if user.save
render :json=> user.as_json(:auth_token=>user.authentication_token, :email=>user.email), :status=>201
return
else
@alxzoomer
alxzoomer / left_join_arel_example.rb
Created December 8, 2016 17:35 — forked from mildmojo/left_join_arel_example.rb
LEFT JOIN in ARel for ActiveRecord in Ruby on Rails
# Here's a contrived example of a LEFT JOIN using ARel. This is an example of
# the mechanics, not a real-world use case.
# == DEFINITIONS
# - A Taxi is a car for hire. A taxi has_many :passengers.
# - A Passenger records one person riding in one taxi one time. It belongs_to :taxi.
class Taxi < ActiveRecord::Base
# This scope LEFT JOINs the Passenger table. You might use this if you wanted
# to select taxis by a set of taxi and passenger IDs (as with the
@alxzoomer
alxzoomer / iterm2.md
Created November 13, 2016 19:03
iterm2 cheatsheet

Tabs and Windows

Function Shortcut
Previous Tab + Left Arrow
Next Tab + Right Arrow
Go to Tab + Number
Go to Window + Option + Number
Go to Split Pane by Direction + Option + Arrow
Go to Split Pane by Order of Use + ] , + [
@alxzoomer
alxzoomer / hash_remap.rb
Created October 22, 2016 13:36 — forked from seanbehan/hash_remap.rb
Hash Remap
map = {
"Some Key" => :some_other_key
}
data = {
"Some Key" => 12345678910
}
Hash.new.tap do |new_hash|
map.each do |k,v|
@alxzoomer
alxzoomer / db.rake
Created October 11, 2016 19:13 — forked from bonkydog/db.rake
Fix 'ERROR: must be owner of extension plpgsql' complaints from Postgresql when dumping and reloading structure.sql
# Put this in your Rails app's lib/tasks directory
namespace :db do
desc "Fix 'ERROR: must be owner of extension plpgsql' complaints from Postgresql"
task :fix_psql_dump do |task|
filename = ENV['DB_STRUCTURE'] || File.join(ActiveRecord::Tasks::DatabaseTasks.db_dir, "structure.sql")
sql = File.read(filename)
sql.sub!(/(CREATE EXTENSION IF NOT EXISTS plpgsql)/, '-- \1')
sql.sub!(/(COMMENT ON EXTENSION plpgsql)/, '-- \1')
File.open(filename, 'w') do |f|
f.write(sql)
@alxzoomer
alxzoomer / Count lines in Git repo
Created October 7, 2016 20:47 — forked from mandiwise/Count lines in Git repo
A command to calculate lines of code in all tracked files in a Git repo
// Reference: http://stackoverflow.com/questions/4822471/count-number-of-lines-in-a-git-repository
$ git ls-files | xargs wc -l