Skip to content

Instantly share code, notes, and snippets.

View animatedlew's full-sized avatar

Lewie [m80] animatedlew

View GitHub Profile
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));
# 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
# Example 1:
# s = "abc", t = "ahbgdc"
# Return true.
# Example 2:
# s = "axc", t = "ahbgdc"
# Return false.
def isSubsequence(s, t):
head, *tail = s
# 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:
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')));
});
@animatedlew
animatedlew / how-to-install-latest-gcc-on-ubuntu-lts.txt
Last active December 14, 2016 04:07 — forked from application2000/how-to-install-latest-gcc-on-ubuntu-lts.txt
How to install latest gcc on Ubuntu LTS (12.04, 14.04, 16.04)
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 && \
// 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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Min-Width</title>
<style>
.buttons {
width: 300px;
}
<!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>
#!/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!"