Skip to content

Instantly share code, notes, and snippets.

View StevenJL's full-sized avatar

Steven Li StevenJL

  • Fountain Inc.
  • SF Bay Area
  • 23:30 (UTC -07:00)
View GitHub Profile
>> @article.slides[0].photo_crop_w
=> 479
>> @article.slides[0].photo_crop_h
=> 319
@StevenJL
StevenJL / tag_inserts_script.rb
Last active August 29, 2015 14:04
Tag Inserts Script
######## PARAMS
# DATABASE = :Orient
DATABASE = :Postgres
POSTGRES_PORT = '5432'
ORIENT_PATH = '/Users/stevenli/releases/orientdb'
ORIENT_BIN_PATH = "#{ORIENT_PATH}/bin"
ORIENT_DATABASE_PATH = "local:#{ORIENT_PATH}/databases/tags"
@StevenJL
StevenJL / tag_query_script.rb
Last active August 29, 2015 14:04
Tag Query Script
require 'pry'
##### PARAMS
# Select a database
# DATABASE = :Orient
DATABASE = :Postgres
POSTGRES_PORT = '5432'
ORIENT_PATH = '/Users/stevenli/releases/orientdb'
@StevenJL
StevenJL / my_list.exs
Last active October 19, 2016 00:33
Writing foldr and foldl in elixir
# Looks like List.foldr and List.foldl are delegated to erlang:
# https://github.com/elixir-lang/elixir/blob/v1.0.3/lib/elixir/lib/list.ex#L116L118
# But if we wanted to implement these in elixir, seems like we can only write fold1, but not foldr
# Question: Can we define `foldr` without using high-level functions (ie. List.reverse)
# and using a recursive approach similar to `foldl`? I really can't think how but would be
# very interested if someone can show me a solution (if it exists).
defmodule MyList do
def foldl([], acc, _) do
// plain javascript
var Form = React.createClass({ ... });
Form.Row = React.createClass({ ... });
Form.Label = React.createClass({ ... });
Form.Input = React.createClass({ ... });
var App = (
React.createElement(Form, null,
React.createElement(Form.Row, null,
React.createElement(Form.Label, null),
// you can interpolate basic variables
var name = "monkeyman"
var person = <Person name={name} />;
// you can interpolate javascript expressions
var person = <Person name={window.isLoggedIn ? window.name : ''} />;
// The simplest component is a Javascript function that takes `props`
// as an argument and returns a React element. This is called a
// "functional component" since, well, it's just a function!
function CommentBox(props) {
return <div>Hello, here is a comment: {props.content} </div>;
}
// If you're using ES 6, React components can be created
// by extending React.Component.
class CommentBox extends React.Component {
var CommentList = React.createClass({
render: function() {
return (
<div className="commentList">
Hello, world! I am a CommentList.
</div>
);
}
});
// Suppose our comment data to be given as an array of objects
var data = [
{id: 1, author: "Hunter Thompson", text: "Where is my white powder?"},
{id: 2, author: "Tom Wolfe", text: "Where is my white suit?"}
]
ReactDOM.render(
// The starting point for the data array of comments
// it's passed in as a property of <CommentBox> component
<CommentBox data={data} />,
ReactDOM.render(
<CommentBox url="/api/comments" />,
document.getElementById('content')
);