This file contains hidden or 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
| console.log(perm([1,2,3])); | |
| // result: [[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]] | |
| function perm(xs) { | |
| if (xs.length < 2) return [xs]; | |
| else { | |
| let result = []; | |
| for (let i = 0; i < xs.length; i++) { | |
| let head = xs[i]; | |
| let tail = xs.slice(0, i).concat(xs.slice(i+1)); |
This file contains hidden or 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
| # list[t] -> list[list[t]] | |
| def perm(xs): | |
| if len(xs) < 2: | |
| yield xs | |
| else: | |
| for i in range(len(xs)): | |
| head, tail = xs[i], xs[:i] + xs[i+1:] | |
| for p in perm(tail): | |
| yield [head]+p |
This file contains hidden or 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
| # Example 1: | |
| # s = "abc", t = "ahbgdc" | |
| # Return true. | |
| # Example 2: | |
| # s = "axc", t = "ahbgdc" | |
| # Return false. | |
| def isSubsequence(s, t): | |
| head, *tail = s |
This file contains hidden or 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
| # Given an array of integers, 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once. | |
| # Find all the elements that appear twice in this array. | |
| # Could you do it without extra space and in O(n) runtime? | |
| input = [4, 3, 2, 7, 8, 2, 3, 1] | |
| output = [2, 3] | |
| cache = {} | |
| for n in input: |
This file contains hidden or 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 fs = require('fs'); | |
| fs.open('main.class', 'r', (status, fd) => { | |
| if (status) { | |
| console.log(status.message); | |
| return; | |
| } | |
| let buffer = new Buffer(4); | |
| fs.read(fd, buffer, 0, 4, 0, (err, num) => console.log(buffer.toString('hex'))); | |
| }); |
This file contains hidden or 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
| These commands are based on a askubuntu answer http://askubuntu.com/a/581497 | |
| To install gcc-6 (gcc-6.1.1), I had to do more stuff as shown below. | |
| USE THOSE COMMANDS AT YOUR OWN RISK. I SHALL NOT BE RESPONSIBLE FOR ANYTHING. | |
| ABSOLUTELY NO WARRANTY. | |
| If you are still reading let's carry on with the code. | |
| sudo apt-get update && \ | |
| sudo apt-get install build-essential software-properties-common -y && \ | |
| sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y && \ |
This file contains hidden or 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
| // define your regex groups: one that grabs everything from the end of the line, | |
| // and another group that grabs everything else... | |
| val pathExtractor = """(.*/)(.*)$""".r | |
| // then you can use unapply like this... | |
| val pathExtractor(path, file) = "some/long/path/file.ext" | |
| // or like this (recommended) | |
| "some/long/path/file.ext" match { | |
| case pathExtractor(p, f) => p -> f |
This file contains hidden or 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
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta charset="utf-8"> | |
| <title>Spiderweb in JavaScript</title> | |
| <style> | |
| @import url('https://fonts.googleapis.com/css?family=Creepster'); | |
| html, body { margin: 0; } | |
| </style> | |
| </head> |
This file contains hidden or 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
| #!/usr/bin/env bash | |
| SBT_PLUGINS_PATH=~/.sbt/0.13/plugins | |
| mkdir -p $SBT_PLUGINS_PATH | |
| echo | |
| echo 'addSbtPlugin("org.ensime" % "sbt-ensime" % "1.10.0")' >> $SBT_PLUGINS_PATH/plugins.sbt | |
| echo "You're almost done..." | |
| echo "Run 'sbt ensimeConfig' on your project's root." | |
| echo "From your editor, start the ensime server." | |
| echo "That's all folks!" |