Skip to content

Instantly share code, notes, and snippets.

@kastigar
kastigar / Href.scala
Created December 12, 2011 12:15
Href snippet for liftweb. Allows to fill href/src attribute with url of specified Loc.
package kastigar
package snippet
import net.liftweb._
import http._
import common._
import sitemap._
import scala.xml._
object Href extends DispatchSnippet {
@kastigar
kastigar / L10n.scala
Created December 12, 2011 12:50
L10n snippet for liftweb. Modified version of builtin Loc snippet. Main feature is localization of attributes.
package kastigar
package snippet
import net.liftweb._
import http._
import common._
import scala.xml._
object L10n extends DispatchSnippet {
def dispatch: DispatchIt = {
@kastigar
kastigar / MongoFileMetaRecord.scalaMongoFileMetaRecord.scala
Created March 5, 2012 11:19
Extension for lift-mongodb-record to work with MongoDB's GridFS
package kastigar.mongodb
import java.io._
import net.liftweb._
import common._
import mongodb._
import mongodb.record._
import json.JsonAST.JObject
@kastigar
kastigar / app.js
Last active December 19, 2015 03:38
Working example of scala.js.annotation.JSName
// ...
Class.prototype["main()V"] = (function() {
var model$jsid$23613 = new $.g.Backbone.Model();
model$jsid$23613.set("prop", "value");
var buttons$jsid$23614 = $.g.$("button").add($.g.$("a.btn"));
buttons$jsid$23614.text("BUTTON");
$.g.$("#NextButton").trigger("click");
var siblings$jsid$23615 = $.g.$("#SomeElement").siblings();
function findGreatestPalindromeOfProduct(base) {
var res = {
factor1: undefined,
factor2: undefined,
palindrome: undefined,
};
const min = Math.pow(10, base-1) + 1;
const max = Math.pow(10, base) - 1;
// constants/actions.js
export default const Actions = {};
Actions.SomeAction = "SomeAction";
Actions.AnotherAction = "AnotherAction";
Actions.ThirdAction = "ThirdAction";
// in actions/some_action.js
@kastigar
kastigar / TASK.md
Last active December 8, 2018 18:17
Test task

Task

Implement a page with a multi-step form, where each step comes out below after filling out the previous one.

Steps

  1. Two checkboxes with labels A1 and A2. Both are unchecked by default. Next step is available after at least one of them is checked.
  2. Two toggle buttons with labels B1 and B2. One button untoggles another (same as radio buttons behavior). Both are inactive by default. Next step is available when any option has been chosen.
  3. Text field with button Check. When button is pressed a value of the field will be send. Next step is available if a response from API is fine.
  4. Selectbox with C1, C2, C3 options. It is empty by default. Next step is available when any option has been chosen.
export const addStep = actionCreator(
setType('addStep'),
withReducer.inPath('turn.steps', (atom, card) => [...atom, card]),
);
export const finishTurn = actionCreator(
setType('finishTurn'),
withReducer.inPath('turn.done', () => true),
);
module.exports = function AutotypePlugin({ types: t }) {
const gettersByType = {
VariableDeclarator(path) {
const { id } = path.parent;
if (t.isIdentifier(id)) {
return id.name;
}
console.log(`Unsupported VariableDeclarator.id: ${id.type}`);
@kastigar
kastigar / defaultReducerCase.js
Created November 23, 2016 12:01
Higher order reducer for default case
function createReducerWithDefaultCase(decl, initial) {
const defaultCase = decl['*'];
delete decl['*'];
const reducer = createReducer(decl, initital);
if (!defaultCase) return reducer;
const declaredActions = Object.keys(decl);
return (state, action) => {