This file contains 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
trait Request { | |
def getParam(key: String): String | |
def getCommaParamList(key: String): Seq[String] | |
def paramOpt[T](key: String)(implicit reader: ParamReader[T]): Option[T] = Option(getParam(key)).map(reader.read) | |
def paramOpt[T](key: String, op: T => _)(implicit reader: ParamReader[T]): Unit = paramOpt(key).foreach(op) | |
def param[T](key: String)(implicit reader: ParamReader[T]): T = reader.read(getParam(key)) | |
def param[T](key: String, op: T => _)(implicit reader: ParamReader[T]): Unit = op(param(key)) | |
def paramExists(key: String): Boolean = getParam(key) != null | |
def paramExists(key: String, op: Boolean => _): Unit = op(paramExists(key)) |
This file contains 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
// before | |
override def receive(ev: AnyRef)(implicit self: ItemValue) = ev match { | |
case ev: MsgItems.ApplyAction if ev.getChoice == ActionChoice.Activate => | |
if (ev.getArgsCount > 0) { | |
val arg = ev.getArgs(0) | |
cfg.targets.lift(arg) match { | |
case Some(target) => | |
items.syncBroadcast(SyncToolForUpgrade(typeId = target.toolTypeId)).info match { | |
case Some(tool) => | |
target.nextUpgrade(upgradesHave = tool.upgrades) match { |
This file contains 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
#include <functional> | |
#include <optional> | |
#include <vector> | |
#include <iostream> | |
template<typename T> | |
using Receiver = std::function<void( T )>; | |
template<typename T, typename U> | |
using Transformer = std::function<U( T )>; |
This file contains 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
// what I carelessly wrote | |
BigInteger value = ciphertext[0]; | |
BigInteger p, o; | |
if (value.equals(ciphertext[1])) { // << here's careless fail. Never should've done it | |
BigInteger[] factors = factorize(value); | |
p = factors[0]; | |
o = factors[1]; | |
} else { | |
p = gcd(value, ciphertext[1]); | |
o = value.divide(p); |
This file contains 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
04-09 13:31:07.813: D/WebSocket.cpp(20710): WebSocket thread start, helper instance: 0xd19ad4e0 | |
04-09 13:31:07.820: D/WebSocket.cpp(20710): scheme: ws, host: echo.websocket.org, port: 0, path: | |
04-09 13:31:07.926: D/WebSocket.cpp(20710): WebSocket (0xce292b00) Unhandled websocket event: 32 | |
04-09 13:31:07.926: D/WebSocket.cpp(20710): WebSocket (0xce292b00) Unhandled websocket event: 29 | |
04-09 13:31:08.166: D/WebSocket.cpp(20710): WebSocket (0xce292b00) Unhandled websocket event: 24 | |
04-09 13:31:08.277: D/WebSocket.cpp(20710): WebSocket (0xce292b00) Unhandled websocket event: 2 | |
04-09 13:31:08.277: D/WebSocket.cpp(20710): onConnectionOpened...: 0xce292b00, client protocols: , server selected protocol: | |
04-09 13:31:08.286: D/WebSocket.cpp(20710): Safely done, msg(2)! | |
04-09 13:31:08.287: D/WebSocket.cpp(20710): msg(2) append: 0 + 4 = 4 | |
04-09 13:31:08.287: D/WebSocket.cpp(20710): msg(2) was totally sent! |
This file contains 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
build_prompt () { | |
local lhs=$1 | |
local rhs=$2 | |
local save='\e[s' # Save cursor position | |
local rest='\e[u' # Restore cursor to save point | |
# Strip ANSI commands before counting length | |
# From: https://www.commandlinefu.com/commands/view/12043/remove-color-special-escape-ansi-codes-from-text-with-sed | |
rhs_stripped=$(sed "s,\x1B\[[0-9;]*[a-zA-Z],,g" <<<"$rhs") | |
echo "\[${save}\e[${COLUMNS:-$(tput cols)}C\e[${#rhs_stripped}D${rhs}${rest}\]${lhs}" | |
} |
This file contains 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
// WebSocketFactory.d.ts | |
export function newWebSocket( url: String ): WebSocket; | |
// WebSocketFactory.js | |
exports.newWebSocket = function( url ) { | |
if (CC_JSB) { | |
return new WebSocket( url, [], "ssl_cert.pem" ); | |
} | |
else { | |
return new WebSocket( url ); |
This file contains 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 * as React from 'react'; | |
import { Button, Text, TextInput, View, StyleSheet } from 'react-native'; | |
import Constants from 'expo-constants'; | |
// You can import from local files | |
import AssetExample from './components/AssetExample'; | |
// or any pure javascript modules available in npm | |
import { Card } from 'react-native-paper'; |
This file contains 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
/* eslint-disable no-console */ | |
const config = require('../graphql-schema-linter.config.js') | |
// Aaa prefix is used to put this rule on top of the list | |
// which is required for excludes to work properly | |
// This rule allows to add exclusions (defined in graphql-schema.config.js) | |
function AaaWithExcludes (context) { | |
const stack = [] |
This file contains 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
const geometry = {}; | |
// for all the functions below, assume screen coordinates: the x-axis is rightward, the y-axis is downward | |
// finds a point with the lowest vertical position (leftmost wins in case of a tie) | |
geometry.lowestPoint = (points) => points.reduce((lowest, point) => { | |
if (point[1] > lowest[1]) { | |
return point; | |
} | |
if (point[1] === lowest[1] && point[0] < lowest[0]) { |
OlderNewer