Skip to content

Instantly share code, notes, and snippets.

Avatar
🚀
Better then yesterday

Nikolay Ponomarev itsNikolay

🚀
Better then yesterday
View GitHub Profile
View app.rb
# frozen_string_literal: true
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
gem 'rails', '5.2.4.5'
gem 'sqlite3'
end
View main.c
#include <stdio.h>
#include <stdlib.h>
int *initArray(int n) {
int i;
int *array;
array = malloc(n * sizeof(*array));
/* you should always check malloc success */
if (array == NULL)
View zsh.md

Prereq:

apt-get install zsh
apt-get install git-core

Getting zsh to work in ubuntu is weird, since sh does not understand the source command. So, you do this to install zsh

wget https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh -O - | zsh
View test16.rb
require 'active_record'
class Person < ActiveRecord::Base
establish_connection adapter: 'sqlite3', database: 'foobar.db'
connection.create_table table_name, force: true do |t|
t.string :mobile_no
end
validate do
regexp = /^(07[\d]{9})/
View test.rb
require 'active_record'
require "active_support"
class Person < ActiveRecord::Base
establish_connection adapter: 'sqlite3', database: 'foobar.db'
connection.create_table table_name, force: true do |t|
t.date :date
end
validate :is_date?
View rspec_rails_cheetsheet.rb
#Model
@user.should have(1).error_on(:username) # Checks whether there is an error in username
@user.errors[:username].should include("can't be blank") # check for the error message
#Rendering
response.should render_template(:index)
#Redirecting
response.should redirect_to(movies_path)
View Ubuntu rbenv
# for more info: https://gist.github.com/1120938
View capybara cheat sheet
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')
View Cheffile
#!/usr/bin/env ruby
#^syntax detection
site 'http://community.opscode.com/api/v1'
cookbook "apt"
cookbook "build-essential", {}
cookbook "rvm", {:github=>"fnichol/chef-rvm", :ref=>"v0.9.0"}
cookbook "git", {}
cookbook "postgresql", {}
View application.css
/*
*= require_self
*= require_tree .
*/
@import "bootstrap";
html, body {
height: 100%;
}