Skip to content

Instantly share code, notes, and snippets.

View gnapse's full-sized avatar
💭
I may be slow to respond.

Ernesto García gnapse

💭
I may be slow to respond.
View GitHub Profile
@gnapse
gnapse / visual-surround.vim
Created August 19, 2013 16:07
Convenient key-bindings for an easier use of the vim-surround plugin. See http://gnapse.github.io/2013/08/12/easier-use-of-the-vim-surround-plugin/ for details.
" Surround text currently selected in visual mode
" (The surrounded text is kept selected after being surround)
vmap <leader>" S"lvi"
vmap <leader>' S'lvi'
vmap <leader>` S`lvi`
vmap <leader>( S)lvi(
vmap <leader>{ S}lvi{
vmap <leader>[ S]lvi[
vmap <leader>< S>lvi<
@gnapse
gnapse / pr.md
Created August 26, 2013 18:38 — forked from piscisaureus/pr.md

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = git@github.com:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:

@gnapse
gnapse / keybase.md
Last active October 30, 2017 02:53

Keybase proof

I hereby claim:

  • I am gnapse on github.
  • I am gnapse (https://keybase.io/gnapse) on keybase.
  • I have a public key ASCLxlhSQ3ZoFyZr7YlHbhD-jI9RoitJ0FdwytXR6XEF7Qo

To claim this, I am signing this object:

@gnapse
gnapse / Testing.scala
Last active March 7, 2017 15:04
Testing if it's possible to have Scala class parameters not becoming instance attributes
// Regarding these discussions about Scala class constructor parameters:
// http://stackoverflow.com/questions/15639078/scala-class-constructor-parameters
// http://stackoverflow.com/questions/1889454/in-scala-how-do-you-define-a-local-parameter-in-the-primary-constructor-of-a-cl
// Class parameter `fake` is not prefixed by either `val` or `var`
class Testing(fake: Boolean) {
val buffer = if (fake) null else new StringBuilder()
def output(str: Any): Unit = {
// The class parameter `fake` is accessible beyond the construction phase
@gnapse
gnapse / post-notifications.coffee
Last active August 29, 2015 14:14
Some features implemented with and without reactive programming
Kefir.Observable.prototype.withIndex = (mapType, fn) ->
index = 0
this[mapType]((value) -> fn(value, index++))
ApiController = Ember.Controller.extend
# With reactive programming
# (also needs the function withIndex in the top of this file)
postNotifications: (startCallback) ->
@gnapse
gnapse / xhr.js
Last active August 29, 2015 14:23 — forked from mythz/xhr.js
//Adds $.xhr and jQuery-like $.ajax methods to the prescribed namespace.
//Inspired from David Flanagans excellent cross-platform utils http://www.davidflanagan.com/javascript5/display.php?n=20-1&f=20/01.js
//Includes underscore.js _.each and _.extend methods
//modified to behave like jQuery's $.ajax(), not complete.
(function($) {
var win=window, xhrs = [
function () { return new XMLHttpRequest(); },
function () { return new ActiveXObject("Microsoft.XMLHTTP"); },
function () { return new ActiveXObject("MSXML2.XMLHTTP.3.0"); },
function () { return new ActiveXObject("MSXML2.XMLHTTP"); }

Switch To Vim For Good

This guide is coming from an email I used to send to newcomers to Vim. It is not intended to be a complete guide, it is about how I did the switch.

Some background: my decision to switch to Vim has been made a long time ago. Coming from TextMate 1, I wanted to learn an editor that is Open Source (so I don’t lose my time learning a tool that can be killed), cross platform (so I can use it everywhere), and powerful enough (so I won’t regret TextMate). For these reasons, Vim has always been the editor I wanted to learn, but it took me several years before I did it in a way that works for me. I tried to switch progressively, using the Janus Vim distribution for a few months, then got back to using TextMate 2 for a time, waiting for the next attempt… here is what finally worked for me.

Non Optional

  1. Watch the Derek Wyatt videos in order (at least the “Novice” ones for now): http://derekwyatt.org/vim/tutorials/
  2. Read the first part of this Sta

Hi Nicholas,

I saw you tweet about JSX yesterday. It seemed like the discussion devolved pretty quickly but I wanted to share our experience over the last year. I understand your concerns. I've made similar remarks about JSX. When we started using it Planning Center, I lead the charge to write React without it. I don't imagine I'd have much to say that you haven't considered but, if it's helpful, here's a pattern that changed my opinion:

The idea that "React is the V in MVC" is disingenuous. It's a good pitch but, for many of us, it feels like in invitation to repeat our history of coupled views. In practice, React is the V and the C. Dan Abramov describes the division as Smart and Dumb Components. At our office, we call them stateless and container components (view-controllers if we're Flux). The idea is pretty simple: components can'

@gnapse
gnapse / Enhance.js
Last active August 29, 2015 14:24 — forked from sebmarkbage/Enhance.js
import { Component } from "React";
export var Enhance = ComposedComponent => class extends Component {
constructor() {
this.state = { data: null };
}
componentDidMount() {
this.setState({ data: 'Hello' });
}
render() {
@gnapse
gnapse / doc.md
Created October 9, 2016 00:12 — forked from oelmekki/doc.md
Rails + Browserify + React + es7

1. Gemfile

gem 'browserify-rails', '1.5.0' # until fix: https://github.com/browserify-rails/browserify-rails/issues/101
gem 'react-rails'

Browserify-rails allows to use browserify within assets pipeline. React-rails is here only to allow to use #react_component (and thus, prerendering).

Note that jquery-rails can be removed from Gemfile, the npm version of jquery and jquery-ujs will be used instead.