import matplotlib.pyplot as plt
import numpy as np
L = 6
x = np.linspace(0, L)
ncolors = len(plt.rcParams['axes.color_cycle'])
shift = np.linspace(0, L, ncolors, endpoint=False)
for s in shift:
plt.plot(x, np.sin(x + s), 'o-')
This file contains 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 ruby | |
require 'optparse' | |
require 'pry' | |
def main | |
options = {to_encoding: 'utf-8'} | |
option_parser = OptionParser.new do |opts| | |
executable_name = File.basename($PROGRAM_NAME) |
This file contains 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
#!/bin/bash | |
# run it with sudo | |
# https://www.digitalocean.com/community/tutorials/how-to-add-swap-on-ubuntu-14-04 | |
SWAPFILE=/swapfile | |
SWAPSIZE=$1 | |
ls $SWAPFILE && swapoff $SWAPFILE && rm $SWAPFILE | |
fallocate -l $SWAPSIZE $SWAPFILE | |
chmod 600 $SWAPFILE |
This file contains 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
(add-to-list 'load-path "~/.emacs.d/el-get/el-get") | |
(unless (require 'el-get nil 'noerror) | |
(with-current-buffer | |
(url-retrieve-synchronously | |
"https://raw.github.com/dimitri/el-get/master/el-get-install.el") | |
(let (el-get-master-branch | |
el-get-install-skip-emacswiki-recipes) | |
(goto-char (point-max)) | |
(eval-print-last-sexp)))) |
This file contains 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
defmodule Chop do | |
def guess(final, range) do | |
low..high = range | |
middle = div(low + high, 2) | |
_guess_helper(final, low, high, middle) | |
end | |
defp _guess_helper(final, _low, _high, middle) when final === middle do | |
middle | |
end |
Here’re two powerset function implemented in Python and Haskell.
import copy
def powerset(s):
if s == []:
return [[]]
elif len(s) == 1:
return [[], s]
This file contains 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
import unittest | |
def binary_search(array, t): | |
l = 0 | |
h = len(array) - 1 | |
while (l <= h): | |
m = (l + h) // 2 | |
if (array[m] == t): | |
return m |
This file contains 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
require 'json' | |
require 'yaml' | |
input_filename = ARGV[0] | |
output_filename = input_filename.sub(/(yml|yaml)$/, 'json') | |
input_file = File.open(input_filename, 'r') | |
input_yml = input_file.read | |
input_file.close |
This file contains 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
%% udp test client and server, from joe armstrong's "programming erlang, second | |
%% edition" | |
-module(udp_test). | |
-export([start_server/0, client/1]). | |
start_server() -> | |
spawn(fun() -> server(4000) end). | |
%% the server | |
server(port) -> |
OlderNewer