Skip to content

Instantly share code, notes, and snippets.

Avatar
🦄

Sia siakaramalegos

🦄
View GitHub Profile
@BideoWego
BideoWego / Searchable.rb
Last active Jul 9, 2018
Model Searchable concern for Rails
View Searchable.rb
module Searchable
def self.included(base)
base.extend(ClassMethods)
end
module ClassMethods
@@searchable_fields = []
@@searchable_scope = nil
def search(q, method=nil)
@Restuta
Restuta / framework-sizes.md
Last active Jan 21, 2022
Sizes of JS frameworks, just minified + minified and gzipped, (React, Angular 2, Vue, Ember)
View framework-sizes.md

Below is the list of modern JS frameworks and almost frameworks – React, Vue, Angular, Ember and others.

All files were downloaded from https://cdnjs.com and named accordingly. Output from ls command is stripped out (irrelevant stuff)

As-is (minified)

$ ls -lhS
566K Jan  4 22:03 angular2.min.js
@jwill
jwill / MemeMaker.html
Last active Jul 15, 2021
Starter code for Meme Maker
View MemeMaker.html
<!DOCTYPE html>
<html>
<head>
<title>MemeMaker-Simple</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
<meta name="mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-capable" content="yes">
<style>
@eriktrautman
eriktrautman / sublime_text_2_preferences
Last active Jan 12, 2018
Sublime Text 2 User Preferences
View sublime_text_2_preferences
// These settings can be found under Sublime Text 2 >> Preferences >> Settings - User
// You can just copy-paste this file right over whatever was there if you want
//
// Check out the file at Sublime Text 2 >> Preferences >> Settings - Default
// to see what options are available for you
{
"color_scheme": "Packages/Color Scheme - Default/LAZY.tmTheme",
"font_size": 14.0,
"ignored_packages":
@kyletcarlson
kyletcarlson / json_response_handling_ruby.rb
Created Dec 11, 2013
Ruby script that uses open-uri to fetch the contents of a JSON endpoint, uses the JSON gem to parse the string into a Ruby array & prints some of the records. This is the foundation for all web API requests, so feel free to use it in the future.
View json_response_handling_ruby.rb
# http://ruby-doc.org/stdlib-2.0.0/libdoc/open-uri/rdoc/OpenURI.html
require 'open-uri'
# https://github.com/flori/json
require 'json'
# http://stackoverflow.com/questions/9008847/what-is-difference-between-p-and-pp
require 'pp'
# Construct the URL we'll be calling
request_uri = 'http://localhost:3000/users.json'
request_query = ''
@jwo
jwo / secret_controller.rb
Created Nov 5, 2013
Devise testing controllers - minitest / rails4
View secret_controller.rb
class SecretController < ApplicationController
before_filter :authenticate_user!
def show
end
end
@mperham
mperham / after.rb
Created Jul 4, 2012
Thread-friendly shared connection
View after.rb
class ActiveRecord::Base
mattr_accessor :shared_connection
@@shared_connection = nil
def self.connection
@@shared_connection || ConnectionPool::Wrapper.new(:size => 1) { retrieve_connection }
end
end
ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection
@them0nk
them0nk / rspec_rails_cheetsheet.rb
Created Mar 23, 2012
Rspec Rails cheatsheet (include capybara matchers)
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 slugify.js
function slugify(text)
{
return text.toString().toLowerCase()
.replace(/\s+/g, '-') // Replace spaces with -
.replace(/[^\w\-]+/g, '') // Remove all non-word chars
.replace(/\-\-+/g, '-') // Replace multiple - with single -
.replace(/^-+/, '') // Trim - from start of text
.replace(/-+$/, ''); // Trim - from end of text
}
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')