Skip to content

Instantly share code, notes, and snippets.

View piyushchauhan2011's full-sized avatar
🔥
Working

Piyush Chauhan piyushchauhan2011

🔥
Working
View GitHub Profile
@piyushchauhan2011
piyushchauhan2011 / scalding_alice.scala
Created August 7, 2016 02:11 — forked from johnynek/scalding_alice.scala
Learn Scalding with Alice
/**
git clone https://github.com/twitter/scalding.git
cd scalding
./sbt scalding-repl/console
*/
import scala.io.Source
val alice = Source.fromURL("http://www.gutenberg.org/files/11/11.txt").getLines
// Add the line numbers, which we might want later
val aliceLineNum = alice.zipWithIndex.toList
@piyushchauhan2011
piyushchauhan2011 / grunt-hugo-lunrjs.md
Created June 23, 2016 15:59 — forked from sebz/grunt-hugo-lunrjs.md
hugo + gruntjs + lunrjs = <3 search
@piyushchauhan2011
piyushchauhan2011 / gist:ff2ab7ded0447723bdd922682c624ead
Created June 8, 2016 08:11 — forked from dodyg/gist:5823184
Kotlin Programming Language Cheat Sheet Part 1

#Intro

Kotlin is a new programming language for the JVM. It produces Java bytecode, supports Android and generates JavaScript. The latest version of the language is Kotlin M5.3

Kotlin project website is at kotlin.jetbrains.org.

All the codes here can be copied and run on Kotlin online editor.

Let's get started.

@piyushchauhan2011
piyushchauhan2011 / boot.rb
Created May 8, 2016 06:29 — forked from johnknott/boot.rb
Replacing "irb" with "pry" when using "padrino console"
# Add this to your boot.rb before Padrino.load!
# and add: gem 'pry'
# to your Gemfile and run bundle to install.
begin
require 'pry'
$VERBOSE = nil
IRB = Pry
$VERBOSE = false
rescue LoadError
// A Unit test template for Tape
// See 5 Questions every unit test must answer:
// https://medium.com/javascript-scene/what-every-unit-test-needs-f6cd34d9836d
import test from 'tape';
test('What are you testing?', assert => {
const msg = 'what should it do?'
const actual = 'what was the output?';

Private members in ES6 classes

"Let's create an ES6 class!" you say. "Let's give it a private variable x."

class Foo {
  constructor(x) {
    this.x = x;
  }
  getX() {
def nQueens(n: Int) = (0 until n).permutations filter {col => // col[r] = column of queen on r-th row
val p = col.zipWithIndex.toSet // col[] must be a permutation of (0 until n) because of rook attacks
p.map{case (c, d) => c + d}.size == n && // No 2 queens can have same col + diag because of left-bishop attacks
p.map{case (c, d) => c - d}.size == n // No 2 queens can have same col - diag because of right-bishop attacks
}
/*************************************** [Printing code below] *************************************************/
for ((solution, num) <- nQueens(8).zipWithIndex) {
println(s"Solution #${num + 1}:")
solution foreach {col =>
val row = solution.indices.map(i => if (i == col) 'Q' else '-')
@piyushchauhan2011
piyushchauhan2011 / Ports.js
Created January 26, 2016 01:17 — forked from evancz/Ports.js
Example usage of Elm "ports" that uses signals, non-signals, records, and tuples. Build the Elm code with "elm --only-js Shanghai.elm" and include all of the JS in the HTML document.
// initialize the Shanghai component which keeps track of
// shipping data in and out of the Port of Shanghai.
var shanghai = Elm.worker(Elm.Shanghai, {
coordinates:[0,0],
incomingShip: { name:"", capacity:0 },
outgoingShip: ""
});
function logger(x) { console.log(x) }
@piyushchauhan2011
piyushchauhan2011 / frp.md
Created January 11, 2016 22:51 — forked from ohanhi/frp.md
Learning FP the hard way: Experiences on the Elm language

Learning FP the hard way: Experiences on the Elm language

by Ossi Hanhinen, @ohanhi

with the support of Futurice 💚.

Licensed under CC BY 4.0.

Foreword

@piyushchauhan2011
piyushchauhan2011 / using_mailboxes_in_elm.md
Created January 7, 2016 05:46 — forked from mgold/using_mailboxes_in_elm.md
Using Mailboxes in Elm: a tutorial blog post

Using Mailboxes in Elm

Max Goldstein | July 30, 2015 | Elm 0.15.1

In Elm, signals always have a data source associated with them. Window.dimensions is exactly what you think it is, and you can't send your own events on it. You can derive your own signals from these primitives using map, filter, and merge, but the timing of events is beyond your control.

This becomes a problem when you try to add UI elements. We want to be able to add checkboxes and dropdown menus, and to receive the current state of these elements as a signal. So how do we do that?

The Bad Old Days