Skip to content

Instantly share code, notes, and snippets.

View negator's full-sized avatar

Naveen Gattu negator

View GitHub Profile
@negator
negator / blum.py
Created January 29, 2016 20:26
blum secure password algorithm
import string
import re
alpha = raw_input('alpha: ')
seq = raw_input('seq: ')
name = raw_input('text: ')
seq = map(int, list(seq.replace(" ","")))
f = dict(zip(list(string.ascii_lowercase), map(int, list(alpha.replace(" ","")))))
@negator
negator / designer.html
Last active August 29, 2015 14:16
designer
<link rel="import" href="../core-ajax/core-ajax.html">
<link rel="import" href="../paper-tabs/paper-tabs.html">
<link rel="import" href="../paper-tabs/paper-tab.html">
<link rel="import" href="../core-menu/core-submenu.html">
<link rel="import" href="../core-item/core-item.html">
<link rel="import" href="../core-icon-button/core-icon-button.html">
<polymer-element name="my-element">
<template>
@negator
negator / designer.html
Created February 28, 2015 02:29
designer
<link rel="import" href="../google-map/google-map.html">
<polymer-element name="my-element">
<template>
<style>
:host {
position: absolute;
width: 100%;
height: 100%;
@negator
negator / shapeless-xml.scala
Last active April 26, 2017 04:13
Easy XML typeclasses with Shapeless and Scalaz
/** Domain mapped XML doesnt have to be a boilerplate filled annotational mess. Using shapeless automatic
* typeclass derivation and a little scalaz magic, it becomes painless. Requires shapeless-2.1.0 and scala >2.10
*
*
* import scalaz._
* import scalaz.std._
* import anyVal._
* import list._
* import scala.xml._
*
@negator
negator / shapeless_2-1-0-json.scala
Last active June 27, 2016 13:05
shapeless_2.1.0-json.scala
/**
The Play (2.3) json combinator library is arguably the best in the scala world. However it doesnt
work with case classes with greater than 22 fields.
The following gist leverages the shapeless 'Automatic Typeclass Derivation' facility to work around this
limitation. Simply stick it in a common location in your code base, and use like so:
Note: ** Requires Play 2.3 and shapeless 2.1.0
import SWrites._
import SReads._
object log {
class LineOfCode() {
val loc = {
val list = Thread.currentThread.getStackTrace.toList
list match {
case (_ :: _ :: _ :: loc :: loc2 :: _) => s"${loc2.getFileName}:${loc2.getLineNumber}->${loc.getFileName}:${loc.getLineNumber}"
case _ => ""
}
}
}
/**
The Play (2.3) json combinator library is arguably the best in the scala world. However it doesnt
work with case classes with greater than 22 fields.
The following gist leverages the shapeless 'Automatic Typeclass Derivation' facility to work around this
limitation. Simply stick it in a common location in your code base, and use like so:
Note: ** Requires Play 2.3 and shapeless 2.0.0
@negator
negator / run.scala
Last active December 10, 2015 02:58
Hook up Enumerator to Enumeratee to Iteratee and run it
//The collect function below returns an Enumerator[Activity], given some target meta-data
val iterateePromise = collect(target) &> fileWriting |>> updatingCursor
iterateePromise.flatMap(_.run)
@negator
negator / stats.scala
Last active December 10, 2015 02:58
Status updating and reporting iteratee
/* Status updating and reporting iteratee*/
def updatingStatus:Iteratee[ErrorOrActivity,Unit] = Iteratee.foreach[ErrorOrActivity] {
case Left(error) =>
reportError(error)
statsd("collector.error")
case Right(activity) =>
reportSuccess(activity)
statsd("collector.success")
}
@negator
negator / flatMap.scala
Last active December 10, 2015 02:18
flatMap for Enumerateess
object KloutEnumeratee {
def flatMapInput[From] = new {
def apply[To](f: Input[From] => PlayPromise[Input[To]]) =
new Enumeratee.CheckDone[From, To] { //Checkdone is part of the Play Iteratee library
def step[A](k: K[To, A]): K[From, Iteratee[To, A]] = {
case in @ (Input.El(_) | Input.Empty) =>
val promiseOfInput = f(in)
Iteratee.flatten(promiseOfInput map { input =>
new CheckDone[From, To] {
def continue[A](k: K[To, A]) = Cont(step(k))