Skip to content

Instantly share code, notes, and snippets.

@kevinsalter
kevinsalter / RailsCastsColorScheme.tmTheme
Created June 16, 2013 00:56
RailsCast Colour Scheme
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>name</key>
<string>Railscasts 2</string>
<key>settings</key>
<array>
<dict>
<key>settings</key>
@kevinsalter
kevinsalter / remove all spaces in filesnames
Last active December 18, 2015 23:28
Search and replace on command line to rename files
# change *.* to *.jpg to only target JPGs, for example
# and to customize the search...
# sed -e 's, what you're searching for goes in this space , what you want to replace it with goes here ,g'
#the default example here with turn spaces into nothing ( i.e. remove all spaces from file names )
for i in *.*; do mv "$i" "`echo $i | sed -e 's, ,,g'`"; done
Verifying that +kevinsalter is my openname (Bitcoin username). https://onename.io/kevinsalter
@kevinsalter
kevinsalter / container.jsx
Created May 27, 2016 16:42
<Container /> example
import React, {Component, PropTypes} from 'react';
import $ from 'jquery';
import Loading from './loading.js';
import MainView from './main-view.js';
class Container extends Component {
static propTypes = {
loadingTimeout: PropTypes.number.isRequired
};
@kevinsalter
kevinsalter / container.spec.jsx
Created May 27, 2016 16:43
<Container /> unit tests
import React from 'react';
import {shallow, mount} from 'enzyme';
import {assert} from 'chai';
import {spy} from 'sinon';
import Container from '../src/container.js';
describe('<Container />', () => {
it('should show the <Loading /> component be default', () => {
const wrapper = shallow(<Container />);
@kevinsalter
kevinsalter / loading.spec.jsx
Created May 27, 2016 16:44
<Loading /> unit tests
import React from 'react';
import {shallow} from 'enzyme';
import {assert} from 'chai';
import Loading from '../src/loading.js';
describe('<Loading />', () => {
const LOADING_PROPS = {
imgSrc: 'https://media.giphy.com/media/feN0YJbVs0fwA/giphy.gif'
};
@kevinsalter
kevinsalter / main-view.spec.jsx
Created May 27, 2016 16:45
<MainView /> unit tests
import React from 'react';
import {shallow} from 'enzyme';
import {assert} from 'chai';
import {spy} from 'sinon';
import MainView from '../src/main-view.js';
import {Users} from '../fixtures/users.js';
describe('<MainView />', () => {
const MAIN_VIEW_PROPS = {
@kevinsalter
kevinsalter / naive-reordering.js
Last active February 6, 2019 18:53
naive array re-ordering
const getReorderedQuestions = (event, questions) => {
const movedQuestion = questions.find((question, index) => index === event.oldIndex);
const remainingQuestions = questions.filter((question, index) => index !== event.oldIndex);
const reorderedQuestions = [];
remainingQuestions.forEach((question, index) => {
if (index === event.newIndex) {
reorderedQuestions.push(movedQuestion);
reorderedQuestions.push(question);
} else {
@kevinsalter
kevinsalter / array-spread-reordering.js
Last active June 25, 2023 12:04
reordering array using ES2015 array spread operator
const reorderArray = (event, originalArray) => {
const movedItem = originalArray.find((item, index) => index === event.oldIndex);
const remainingItems = originalArray.filter((item, index) => index !== event.oldIndex);
const reorderedItems = [
...remainingItems.slice(0, event.newIndex),
movedItem,
...remainingItems.slice(event.newIndex)
];
/**
* ellipsisify
* @param {string} filename - The filename to be truncated.
* @param {number} lengthThreshold - (optional) The minimum length of filename to truncate.
*/
export const ellipsisify = (filename, lengthThreshold = 20) => {
// just return the filename if it's less than 20 characters long
if (filename.length < lengthThreshold) return filename;