Skip to content

Instantly share code, notes, and snippets.

View salanki's full-sized avatar

Peter Salanki salanki

View GitHub Profile
@salanki
salanki / CiscoNACAppliance.scala
Created February 9, 2011 00:42
Beginning of API implementation for the Cisco NAC Appliance in Scala. Should be easily usable from Java, depends on dispatch-http.
package cisconacpoller
import scala.util.matching.Regex
trait Response
case class FailResponse(reason: String) extends Response
object NoSuchUserFailure extends FailResponse("No logged in user matches the criteria")
object InvalidCredentialsFailure extends FailResponse("Username or password is incorrect")
def union[A](a: Set[A], b: Set[A]) {
var c = b
for(item <- a) {
c += item
}
c
}
OR:
@salanki
salanki / mac2ip.scala
Created July 6, 2011 21:58
Mac2IP implementation
package com.proceranetworks.psm.leasepoller
package twpoller
import java.net.InetAddress
import java.nio.ByteBuffer
object ByteBufferImplicits {
implicit def byteBuffer2PimpedByteBuffer(buffer: ByteBuffer): PimpedByteBuffer = new PimpedByteBuffer(buffer)
}
class PimpedByteBuffer(buffer: ByteBuffer) {
@salanki
salanki / todo.scpt
Created July 15, 2013 12:20
Automatically add TODOs to Inbox of Things from iMessages beginning with "TODO:"
using terms from application "Messages"
on message received theMessage from theBuddy for theChat
set buddyId to id of theBuddy as text
if (makelower(theMessage) begins with "todo:") then
set trim1 to trim_line(theMessage, "todo:", 0)
set trim2 to trim_line(trim1, " ", 0)
tell application "Things 2"
set newToDo to make new to do ¬
with properties {name:trim2, notes:"From: " & buddyId}
/* Actions.scala */
package actions
trait Action // Trait ~= abstract class / interface. Can't be directly instantiated.
sealed trait Feed extends Actions // Sealing is not required but important as the compiler will know that this class can't be extended by any other code, meaning we can do static typechecking that anything that is supposed to handle all cases of Feed actually does so. More reading: http://underscore.io/blog/posts/2015/06/02/everything-about-sealed.html
/* Objects are often used similar to packages in Scala. In this case you can just think of them as a grouping, no other special meaning */
object Feed {
class FetchRequest extends Feed
function generator(baseType) {
// Need to handle variable length argument lists
const fun = (payload) => ({
type: fun,
payload: payload,
baseType: baseType
});
return fun;
}
// lib/actions.js
import identity from 'lodash/identity';
export const ActionType = {
REQUEST: 'REQUEST',
SUCCESS: 'SUCCESS',
FAILURE: 'FAILURE'
};
function createActionCreatorFlat(prefix, type, requestPayloadCreator = identity) {
@salanki
salanki / activerecord.md
Last active February 7, 2018 06:52
Performance effects of subtly different ActiveRecord methods

Checking for existance

TL;DR

Use exists?

exits?

Ruby:

@salanki
salanki / render-example.yaml
Last active October 25, 2019 18:45
For Brian
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: render-123-classroom
spec:
maxParallelism: 50 # Run maximum 50 tasks in parallel
retryStrategy:
limit: 2 # Retry each task max twice
entrypoint: render
templates:

Keybase proof

I hereby claim:

  • I am salanki on github.
  • I am salanki (https://keybase.io/salanki) on keybase.
  • I have a public key ASCUTCgXmhpAZAGEASjr0WsQkx8a8xjqoaQiZF9lhfwvDgo

To claim this, I am signing this object: