Skip to content

Instantly share code, notes, and snippets.

View christopherstyles's full-sized avatar

Chris Styles christopherstyles

View GitHub Profile
@diegocasmo
diegocasmo / Tab.js
Last active September 3, 2021 06:06
Source code for implementing a React <Tabs/> component.
import React, {PropTypes} from 'react';
export const Tab = (props) => {
return (
<li className="tab">
<a className={`tab-link ${props.linkClassName} ${props.isActive ? 'active' : ''}`}
onClick={(event) => {
event.preventDefault();
props.onClick(props.tabIndex);
}}>
@slavafomin
slavafomin / nodejs-custom-es6-errors.md
Last active January 30, 2026 17:29
Custom ES6 errors in Node.js

Here's how you could create custom error classes in Node.js using latest ES6 / ES2015 syntax.

I've tried to make it as lean and unobtrusive as possible.

Defining our own base class for errors

errors/AppError.js

@nathanl
nathanl / activerecord_model_scopes.rb
Last active May 27, 2019 06:39
Rails code to use PostGIS in place of some of Geocoder's functionality - based on http://ngauthier.com/2013/08/postgis-and-rails-a-simple-approach.html
# Scopes that make use of the index
def self.within_distance_of(lat:, lng:, meters:)
where(%{
ST_DWithin(
ST_GeographyFromText(
'SRID=4326;POINT(' || #{table_name}.longitude || ' ' || #{table_name}.latitude || ')'
),
ST_GeographyFromText('SRID=4326;POINT(%f %f)'),
%d
)
@ChuckJHardy
ChuckJHardy / example_activejob.rb
Last active March 12, 2025 21:24
Example ActiveJob with RSpec Tests
class MyJob < ActiveJob::Base
queue_as :urgent
rescue_from(NoResultsError) do
retry_job wait: 5.minutes, queue: :default
end
def perform(*args)
MyService.call(*args)
end
@pencilcheck
pencilcheck / _README.md
Last active March 18, 2023 13:15 — forked from shime/_README.md

What is this?

How do you compare date/times in RSpec?

If you do this

expect(Time.now.to_i).to eq Time.new(2014, 4, 2).to_i
--color
--require spec_helper
--require ./spec/support/lifx
-f LIFXFormatter
@erin-dot-io
erin-dot-io / _neat-breakpoints.scss
Last active August 29, 2015 14:06
Neat Breakpoints
// These are my base breakpoints when working on projects that
// utilize Bourbon (http://bourbon.io/) & Neat (http://neat.bourbon.io/)
$desktop-wide : new-breakpoint(min-width 1370px);
$desktop : new-breakpoint(min-width 1001px);
$desktop-narrow : new-breakpoint(max-width 1000px);
$desktop-narrow-only : new-breakpoint(min-width 769px max-width 1000px);
$tablet : new-breakpoint(max-width 768px);
$tablet-only : new-breakpoint(min-width 640px max-width 768px);
$phone-wide : new-breakpoint(max-width 669px);
@joost
joost / README.md
Last active January 8, 2024 20:03
How to fix invalid byte sequence in UTF-8 rack in Rails

Add the utf8_sanitizer.rb to your Rails 3.2 project in app/middleware. Instead of removing the invalid request characters and continuing the request (as some gems do) it returns a 400 error.

Add the following line to your config/application.rb:

config.middleware.use 'Utf8Sanitizer'

If you only need it in production add to config/environments/production.rb. This can be without quotes:

config.middleware.use Utf8Sanitizer
@ghilead
ghilead / create_es_combined_index.rake
Last active January 18, 2019 12:08
Rake task for collocating multiple models as types in a single index.
# A Rake tasks to facilitate importing data from your models into a common Elasticsearch index.
#
# All models should declare a common index_name, and a document_type:
#
# class Article
# include Elasticsearch::Model
#
# index_name 'app_scoped_index'
# document_type 'articles'
#
# config/routes.rb
resources :documents do
scope module: 'documents' do
resources :versions do
post :restore, on: :member
end
resource :lock
end
end