Skip to content

Instantly share code, notes, and snippets.

@xtian
xtian / 01_simple_case.ex
Last active Aug 16, 2017
Ecto errors_on helper that returns atoms instead of strings.
View 01_simple_case.ex
@doc """
Helper for returning list of errors in a struct when given certain data.
## Examples
Given a User schema that lists `:name` as a required field and validates
`:password` to be safe, it would return:
iex> errors_on(%User{}, %{})
@xtian
xtian / .editorconfig
Last active Jan 14, 2021
Rust .editorconfig
View .editorconfig
# EditorConfig helps developers define and maintain consistent
# coding styles between different editors and IDEs
# editorconfig.org
root = true
[*.rs]
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
View application.controller.js
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
currentWhen: 'foo bar'
});
View application.controller.js
import Ember from 'ember';
export default Ember.Controller.extend({
appName:'Ember Twiddle',
checked: true,
actions: {
clickCheck() {
this.toggleProperty("checked");
debugger
}
View gist:30eadee65323804c90f5
Verifying that +xtian is my openname (Bitcoin username). https://onename.com/xtian
@xtian
xtian / gist:9915230
Created Apr 1, 2014
es6-module-transpiler Esprima error
View gist:9915230
Line 2: Unexpected token => Error: Line 2: Unexpected token =>
at throwError (/Users/xtian/Projects/es6-test/node_modules/broccoli-es6-concatenator/node_modules/es6-module-transpiler/node_modules/esprima/esprima.js:2038:21)
at throwUnexpected (/Users/xtian/Projects/es6-test/node_modules/broccoli-es6-concatenator/node_modules/es6-module-transpiler/node_modules/esprima/esprima.js:2100:9)
at parsePrimaryExpression (/Users/xtian/Projects/es6-test/node_modules/broccoli-es6-concatenator/node_modules/es6-module-transpiler/node_modules/esprima/esprima.js:2554:16)
at /Users/xtian/Projects/es6-test/node_modules/broccoli-es6-concatenator/node_modules/es6-module-transpiler/node_modules/esprima/esprima.js:5120:38
at trackLeftHandSideExpressionAllowCall (/Users/xtian/Projects/es6-test/node_modules/broccoli-es6-concatenator/node_modules/es6-module-transpiler/node_modules/esprima/esprima.js:5022:61)
at parsePostfixExpression (/Users/xtian/Projects/es6-test/node_modules/broccoli-es6-concatenator/node_m
View keybase.md

Keybase proof

I hereby claim:

  • I am xtian on github.
  • I am xtian (https://keybase.io/xtian) on keybase.
  • I have a public key whose fingerprint is 9AAC 0C89 F8FA 7A8E E696 1B62 1E79 34DD 510B ECD0

To claim this, I am signing this object:

@xtian
xtian / ActiveRecord segfault
Created Feb 12, 2014
Rails edge segfault in ActiveRecord with Ruby 2.1.0
View ActiveRecord segfault
+~/Projects/rails-test$ rails new test_app -q --edge
Updating git://github.com/rails/rails.git
Updating git://github.com/rails/arel.git
Updating git://github.com/rails/sprockets-rails.git
Updating git://github.com/rails/sass-rails.git
Updating git://github.com/rails/coffee-rails.git
Fetching gem metadata from https://rubygems.org/........
Fetching additional metadata from https://rubygems.org/..
Resolving dependencies...
Using json (1.8.1)
View snip.js
TypeFast.GameRoute = Ember.Route.extend({
model: function() {
return this.store.find('quote', Math.floor((Math.random()*3)+1));
},
setupController: function(controller, model) {
controller.set('model', model);
}
});
var obj = {
View multiline_truncate.rb
def multiline_truncate(string, width, max_lines)
lines = word_wrap(string, line_width: width).split("\n")
# string does not wrap past maximum number of lines
return string unless lines[max_lines].present?
# join the last two lines and truncate them
last_line = "#{lines[max_lines - 1]} #{lines[max_lines]}"
lines[max_lines - 1] = truncate(last_line, length: width)