Skip to content

Instantly share code, notes, and snippets.

View SuperManEver's full-sized avatar
🎯
Focusing

Nick Luparev SuperManEver

🎯
Focusing
View GitHub Profile
require 'rails/all'
# require 'action_view'
require 'rspec/rails'
require 'capybara/rspec'
require 'capybara/rails'
# This file was generated by the `rails generate rspec:install` command. Conventionally, all
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
# The generated `.rspec` file contains `--require spec_helper` which will cause
# this file to always be loaded, without a need to explicitly require it in any
@SuperManEver
SuperManEver / display.rb
Created March 25, 2016 06:15
Display class responsible for displaying search results
require 'paint'
class Display
def self.display(args)
# display search results
@@search_result = args[:result]
@@options = args[:options]
@@search_result.each_pair do |file_name, lines|
display_search_result(file_name, lines)
@SuperManEver
SuperManEver / users_controller.rb
Created May 17, 2016 14:30
Experimenting with extracting logic from Controller class
require 'forwardable'
class UsersController < ApplicationController
def show
@user = User.find_by_id(params[:id])
end
def new
@user = User.new
end
@SuperManEver
SuperManEver / event.rb
Created June 9, 2016 19:15
Attempt to extract class methods to separate class with delegation to this new class
class Event < ActiveRecord::Base
delegate :next_occurrence, :select_events_with_time, :find_category_next_occurences :to => :OccurrenceManager
end
class OccurrenceManager
def self.next_occurrence(event_type, begin_time = COLLECTION_TIME_PAST.ago)
events_with_times = select_events_with_time(event_type: event_type, begin_time: begin_time)
unless events_with_times.empty?
events_with_times = events_with_times.sort {|e1, e2| e1.time <=> e2.time }
@SuperManEver
SuperManEver / example.js
Created June 14, 2016 14:34
sample code for SPA module
// Module /spa/
// Provides chat slider capabilities
var spa = (function($) {
var
/* --- Constants --- */
configMap = {
extended_height: 434,
extended_title: 'Click to retract',
rectracted_height: 16,
@SuperManEver
SuperManEver / model_react.jsx
Created August 2, 2016 19:34
adding model to react app
const React = require('react');
const ReactDOM = require('react-dom');
const TodoInput = require('./todo_input.js');
const TodoList = require('./todo_list.js');
var tasks = [
{ text : 'buy milk' },
{ text : 'do exercises' }
];
@SuperManEver
SuperManEver / javascript
Created August 26, 2016 17:28
backend example
var express = require('express');
var app = express();
var path = require('path');
app.set('port', (process.env.PORT || 5000));
app.use(express.static(__dirname + '/public'));
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, 'public', 'index.html'));
var articles = [
{
title: 'Everything Sucks',
url: 'http://do.wn/sucks.html',
author: {
name: 'Debbie Downer',
email: 'debbie@do.wn'
}
},
square x = x * x
double x = x + x
factorial n = if n == 1
then 1
else n * factorial (n - 1)
evaluate f x = f x
factorial :: (Integral a) => a -> a
factorial 0 = 1
factorial n = n * factorial (n - 1)
maximum' [] = error "can't be empty"
maximum' [x] = x
maximum' (x:xs) = max x (maximum' xs)
head' :: [a] -> a
head' [] = error "Can't call head on an empty list"