This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // closure | |
| const add = x => y => | |
| x + y | |
| // Bad - unlikely no auto complete/evaluation for your IDE/editor and also an anonymous function. Hard for debugging. | |
| const addOne = add(1); | |
| console.log(addOne.name); //=> "" // empty string | |
| const __addOne = add(1); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // @flow | |
| const immutable = <T>(item: T): T => | |
| typeof item === 'object' ? JSON.parse(JSON.stringify(item)) : item; | |
| const immutableAll = (...args) => | |
| args.map(immutable) | |
| const pipe = (fn: function, ...fns: Array<function>): function => <S>(...args: Array<S>) => { | |
| return fns.reduce( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class App { | |
| constructor() { | |
| this._listeners = {}; | |
| } | |
| ev(obj, listener) { | |
| return this._listeners[name](this, obj); | |
| } | |
| listener(name, func) { | |
| if(this._listeners[name]) { | |
| throw `${name} already exists`; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| lapis = require "lapis" | |
| db = require "lapis.db" | |
| html = require "lapis.html" | |
| queries = require "queries" | |
| config = require("lapis.config").get! | |
| import get_redis from require "lapis.redis" | |
| import notNil from require "utils" | |
| main = require "components.main" | |
| get_set_redis = (widget) => |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| toOneResult = (result) -> | |
| if result | |
| return result[1] | |
| else | |
| return result | |
| blog = [[ | |
| SELECT `api_blog_option_terms`.`blog_option_name`, `api_blog_option_index`.`blog_option_title` FROM `api_blog_option_index` | |
| JOIN api_blog_option_terms | |
| ON api_blog_option_index.blog_option_id = api_blog_option_terms.blog_option_id | |
| WHERE api_blog_option_index.domain_id = ? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| lapis = require "lapis" | |
| db = require "lapis.db" | |
| html = require "lapis.html" | |
| queries = require "queries" | |
| config = require("lapis.config").get! | |
| widgets = require "views.widgets" | |
| import get_redis from require "lapis.redis" | |
| import render_html from require "lapis.html" | |
| import notNil from require "utils" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import asynchttpserver, asyncdispatch | |
| import json | |
| import cgi | |
| var server = newAsyncHttpServer() | |
| proc handler(req: Request) {.async.} = | |
| let msg = %* {"message": "hello world"} | |
| await req.respond(Http200, $msg, newHttpHeaders([("Content-Type","application/json")])) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function setDepth(obj, path, value) { | |
| var tags = path.split("."), len = tags.length - 1; | |
| for (var i = 0; i < len; i++) { | |
| obj = obj[tags[i]]; | |
| } | |
| obj[tags[len]] = value; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export function isObject(item) { | |
| return (item && typeof item === 'object' && !Array.isArray(item) && item !== null); | |
| } | |
| export default function mergeDeep(target, source) { | |
| let output = Object.assign({}, target); | |
| if (isObject(target) && isObject(source)) { | |
| Object.keys(source).forEach(key => { | |
| if (isObject(source[key])) { | |
| if (!(key in target)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from __future__ import unicode_literals | |
| import sys | |
| # We only use unicode in our parser, except for __repr__, which must return str. | |
| if sys.version_info.major == 2: | |
| repr_str = lambda s: s.encode("utf-8") | |
| str = unicode | |
| else: | |
| repr_str = lambda s: s |