Skip to content

Instantly share code, notes, and snippets.

@ej2015
ej2015 / nested_json_struc.go
Created January 2, 2020 06:53
Golang nested json
//https://play.golang.org/p/9deaMVBwBgm
package main
import (
"fmt"
"encoding/json"
)
type BodyRequest struct {
@ej2015
ej2015 / Rails_scope_does_not_cache.txt
Last active December 20, 2019 04:51
Rails scope does not cache
Rails cache SQL calls
So suppose we have a model Author which has_many Book
expect(author.books).to equal author.books
If Book has a scope, say by_countries:
scope :by_countries, -> c { where(countries: c) if c.present? }
@ej2015
ej2015 / script.md
Created April 30, 2019 21:47 — forked from markbates/script.md
Getting Started with Sinatra

In an earlier video we took a look at Rack to build incredibly lightweight web applications with Ruby. Rack's toolkit allowed us to quickly throw to get a working application, but we did have to put a little effort into it once we wanted to build something a little more complex.

Sometimes you want a fast and simple framework for building a simple web application. Perhaps you only need to respond to a handful of routes, or you want the response time for a small part of a bigger application to be lighting fast. The Sinatra framework is made for just these moments.

Today let's take a quick look at this framework and see how quickly we can build lightweight web applications.

To get started we first need to install the Sinatra gem:

gem install sinatra
@ej2015
ej2015 / deploy.rb
Created October 10, 2018 09:12 — forked from joost/deploy.rb
Capistrano 3 rails console tasks
# encoding: UTF-8
# Place in config/deploy.rb
# See: https://gist.github.com/joost/9343156
# Adapted to work with rbenv
namespace :rails do
desc "Open the rails console on primary app server"
task :console do
on roles(:app), primary: true do
rails_env = fetch(:stage)
execute_interactively "#{bundle_cmd} #{current_path}/script/rails console #{rails_env}"
@ej2015
ej2015 / install_kafka.md
Created August 19, 2018 23:07 — forked from sam95/install_kafka.md
Installation and Getting started with Apache-Kafka for OSX

Apache Kafka is a highly-scalable publish-subscribe messaging system that can serve as the data backbone in distributed applications. With Kafka’s Producer-Consumer model it becomes easy to implement multiple data consumers that do live monitoring as well persistent data storage for later analysis. You can assume that RabbitMQ is similar to Kafka, You do get an option for message-sending or Broadcasting. The installation process for OSX is as below.

  1. The best way to install the latest version of the Kafka server on OS X and to keep it up to date is via Homebrew.

     brew search kafka
     brew install kafka 
    
  2. The above commands will install a dependency called zookeeper which is required to run kafka. Start the zookeeper service.

zkserver start

@ej2015
ej2015 / find_and_replace.txt
Created August 17, 2018 02:38
find and replace recursively on Mac
find . -name '*.txt' -print0 | xargs -0 sed -i "" "s/form/forms/g"
@ej2015
ej2015 / .vimrc
Created July 27, 2018 22:04 — forked from imxiaobo/.vimrc
My .vimrc configuration. Plugins are managed by vundle.vim.
set nocompatible " be iMproved
filetype off " required!
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()
" let Vundle manage Vundle
" required!
Bundle 'gmarik/vundle'
@ej2015
ej2015 / require_file.rb
Last active July 24, 2018 20:58
require files in Ruby
#given files a.rb and b.rb in the same directory
#b.rb
dir = File.expand_path('.',__dir__)
# $: is a short form for $LOAD_PATH
$:.unshift(dir) unless $:.include?(dir)
require 'a'
## now we can run b.rb from anywhere and it will require a.rb successfully.
@ej2015
ej2015 / curl.md
Created July 1, 2018 21:10 — forked from subfuzion/curl.md
curl POST examples

Common Options

-#, --progress-bar Make curl display a simple progress bar instead of the more informational standard meter.

-b, --cookie <name=data> Supply cookie with request. If no =, then specifies the cookie file to use (see -c).

-c, --cookie-jar <file name> File to save response cookies to.

@ej2015
ej2015 / minitest_spec_expectations.md
Created June 22, 2018 22:49 — forked from ordinaryzelig/minitest_spec_expectations.md
How to write MiniTest::Spec expectations

I'm a fan of MiniTest::Spec. It strikes a nice balance between the simplicity of TestUnit and the readable syntax of RSpec. When I first switched from RSpec to MiniTest::Spec, one thing I was worried I would miss was the ability to add matchers. (A note in terminology: "matchers" in MiniTest::Spec refer to something completely different than "matchers" in RSpec. I won't get into it, but from now on, let's use the proper term: "expectations").

Understanding MiniTest::Expectations

Let's take a look in the code (I'm specifically referring to the gem, not the standard library that's built into Ruby 1.9):

# minitest/spec.rb

module MiniTest::Expectations