Skip to content

Instantly share code, notes, and snippets.

Strings

String.prototype.*

None of the string methods modify this – they always return fresh strings.

  • charAt(pos: number): string ES1

    Returns the character at index pos, as a string (JavaScript does not have a datatype for characters). str[i] is equivalent to str.charAt(i) and more concise (caveat: may not work on old engines).

@aghuddleston
aghuddleston / .bashrc
Last active April 4, 2017 17:36 — forked from jusopi/check.sh
Set node version per project using .nvmrc file
cd() {
builtin cd "$1"
if [ -f ".nvmrc" ]; then
nvm use
fi
}
@aghuddleston
aghuddleston / docker-terminal.sh
Created August 18, 2016 13:52 — forked from okunishinishi/docker-terminal.sh
Start docker and change terminal theme on osx.
#!/bin/bash
#
# Start Docker terminal and set theme.
#
TERMINAL_APP="Terminal"
TERMINAL_THEME="Novel"
# Set Terminal theme
osascript -e "
@aghuddleston
aghuddleston / angularjs-addproperty-template.html
Created August 11, 2016 14:55
AngularJS 1.3 Sample Directives, Filters and Miscellaneous
<!-- Bootstrap 3 -->
<div>
<div class="modal fade" my-modal id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" ng-click="vm.cancel()"><span aria-hidden="true">&times;</span><span
class="sr-only">Close</span></button>
<h4 class="modal-title" id="myModalLabel">Add New Property</h4>
@aghuddleston
aghuddleston / angularjs-addproperty-template.html
Last active August 14, 2016 23:12
AngularJS 1.3 Sample Directives, Filters and Miscellaneous
<!-- Bootstrap 3 -->
<div>
<div class="modal fade" my-modal id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" ng-click="vm.cancel()"><span aria-hidden="true">&times;</span><span
class="sr-only">Close</span></button>
<h4 class="modal-title" id="myModalLabel">Add New Property</h4>
@aghuddleston
aghuddleston / AddIndividualCmd.rb
Created July 29, 2016 20:25
"Command" class to create a simple chain of Sidekiq workers and an example worker implementation.
require 'json'
class AddIndividiualCmd
attr_reader :roster_id, :current_step
STEPS = %w(
PhoneInsertWorker
RosterLinkToSchoolWorker
RosterLinkToSchoolAddressWorker
@aghuddleston
aghuddleston / collection_check_boxes.html.haml
Last active June 8, 2016 18:12
SimpleForm (and Ransack) with Bootstrap 3, needing "checkbox-inline" style without the extra "label" field that simple-form seems to like to generate. Manually adding the collection wrapper div.
= search_form_for @q, url: my_path, html: {method: :get} do |f|
.row
.col-md-4
.form-group
%label.string.required.control-label= "Years Teaching"
.row-link
= f.collection_check_boxes :contact_info_profile_teaching_history_subject_taughts_years_teaching_in, TeachYears.all, :id, :name, {item_label_class: "checkbox-inline", item_wrapper_tag: false, boolean_style: :inline } do |b|
- b.label(class: "checkbox-inline") { b.check_box + b.text}
@aghuddleston
aghuddleston / chevron_toggle.html
Created March 7, 2016 15:05 — forked from swanson/chevron_toggle.html
Autoswap Bootstrap icon-chevron when using Collapsible
<a class="btn" data-toggle="collapse" data-target="#my-container">
Toggle <i class="icon-chevron-right"></i>
</a>
<div id="#my-container">
... cool stuff goes here ...
</div>
@aghuddleston
aghuddleston / csv_for_excel.rb
Last active August 10, 2022 19:19
Write a CSV file using Ruby 2.2.2 which can open in Excel, properly displaying accents.
require 'csv'
module DownloadService
OPEN_MODE = "w+:UTF-16LE:UTF-8"
BOM = "\xEF\xBB\xBF" #Byte Order Mark
def student_list
File.open("#{file_name}.tsv", OPEN_MODE) do |f|
csv_file = CSV.generate({:col_sep => "\t"}) do |csv|
# header row
@aghuddleston
aghuddleston / brew-install-redis.txt
Created April 29, 2015 13:31
Output from brew install redis, for future reference
/Users/me$ brew install redis
==> Downloading https://homebrew.bintray.com/bottles/redis-3.0.0.yosemite.bottle.tar.gz
######################################################################## 100.0%
==> Pouring redis-3.0.0.yosemite.bottle.tar.gz
==> Caveats
To have launchd start redis at login:
ln -sfv /usr/local/opt/redis/*.plist ~/Library/LaunchAgents
Then to load redis now:
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.redis.plist
Or, if you don't want/need launchctl, you can just run: