Skip to content

Instantly share code, notes, and snippets.

View venkatperi's full-sized avatar

Venkat Peri venkatperi

View GitHub Profile
['cast#reset#running', () =>
nextState('done/cancel')
.postpone()],
['cast#done/:sessionId#running', ({data, args, event}) =>
args.sessionId === data.sessionId
? nextState('done/done').data({response: {$set: event.extra}})
: keepState()],
['cast#done/:sessionId#running', ({data, args, event}) =>
args.sessionId === data.sessionId
? nextState('done/done').data({response: {$set: event.extra}})
: keepState()],
['enter#*_#running', ({data}) => {
const res = keepState().emit('run', data)
return data.timeout ? res.stateTimeout(data.timeout) : res
}],
['cast#start#idle', ({event}) =>
nextState('running')
.data({request: {$set: event.extra}})],
['enter#*_#idle', () => keepState()
.emit('init')
.data({
errors: {$set: []},
response: {$set: null},
sessionId: {$set: uniqid()}
})],
@venkatperi
venkatperi / pushFixed.ts
Last active September 17, 2018 03:55
For a fixed sized array, adds item to the end of an array and drops elements from the front, if needed
/**
* For a fixed sized array, adds item to the end of
* an array and drops elements from the front, if needed
*
* @param item {T}- to be added to the end of the array
* @param arr {T[]} - the array
* @param size {number} - Max size of the array.
* @return {T[]} The updated array
*/
function pushFixed<T>(item: T, arr: Array<T>, size: number): Array<T> {
@venkatperi
venkatperi / custom.css
Created August 30, 2018 18:11
Tweeten.app Custom CSS for dark/compact mode
html .system-font-stack {
font-weight: 200 !important;
font-family: "mplus-1c-light" !important;
font-size: 12px !important;
color: #748FB4 !important;
}
.js-app .js-column .stream-item .js-tweet-text {
color: #748FB4 !important;
}
class MovingAverageWithRate(object):
"""
Computes the moving average (with optional sample rate) of supplied
samples over a given window size.
Add new samples with add()
"""
def __init__(self, window_size):
@venkatperi
venkatperi / IterableExtSpec.kt
Last active April 11, 2018 15:24
Kotlin: Split Iterable into two at given index
object IterableExtSpec : Spek({
val list = (0 until 100).toList()
describe("splitAt") {
it("asserts when n < 0") {
assertFailsWith<IllegalArgumentException> {
list.splitAt(-2)
}
}