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 "pp" | |
DUDES = [ { name: "Alice", time: 5 }, | |
{ name: "Bob", time: 10 }, | |
{ name: "Candace", time: 20 }, | |
{ name: "Dave", time: 25 } ] | |
INITIAL_STATE = { left: [ ], right: (0...DUDES.length).to_a, time_left: 60 } | |
def backward(state, path) |
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
n = rand(10) + 2 | |
list = (1..n).to_a.shuffle | |
list[1 + rand(list.length - 1)] = list.first | |
puts list.join(", ") | |
a = n * n.succ / 2 | |
b = n * n.succ * (2 * n).succ / 6 | |
a2 = list.inject(:+) | |
b2 = list.inject(0) { |acc, x| acc + x * x } | |
missing = ((b2 - b) / (a2 - a) - a2 + a) / 2 | |
duplicate = a2 - a + missing |
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
-module(causes). | |
-export([causes/1]). | |
leven1(Word, Word) -> not_friends; | |
leven1(Left, Right) when length(Left) == length(Right) -> | |
leven1_subst(Left, Right, friends); | |
leven1(Left, Right) -> leven1_insert(Left, Right). | |
leven1_subst([], [], _Acc) -> friends; |
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 | |
# Just a small script I made to dump my favorite tweets to a text file. | |
# Because agrep in a text file is a super powerful and mega fast search engine :) | |
# Change USER and periodically run $ ruby twitter-favorites.rb >> favorites.txt | |
require 'twitter' | |
USER = '<your twitter user name>' | |
SINCE_ID_FILE = "#{ENV['HOME']}/.favorites_since_id" |
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
$ ftp ftp.ibiblio.org | |
Connected to ftp.ibiblio.org. | |
220 ProFTPD Server | |
Name (ftp.ibiblio.org:j): ftp | |
331 Anonymous login ok, send your complete email address as your password | |
Password: | |
230- | |
Welcome to ftp.ibiblio.org, the public ftp server of ibiblio.org. We | |
hope you find what you're looking for. |
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
/* ---------- Code of duty 1 - Frank DENIS <[email protected]> @jedisct1 ---------- */ | |
#include <stdio.h> | |
#include <string.h> | |
#include <stdlib.h> | |
#include <stdint.h> | |
#include <assert.h> | |
#define MIN_ITEM_VALUE 0U |
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
realpath() { | |
local file="$1" | |
local _file | |
local realpath_file | |
while _file=$(readlink -- "$_file"); do file="$file"; done | |
if [ -d "$file" ]; then | |
realpath_file=$(cd -- "$file" && pwd -P) | |
else | |
local dir=$(dirname -- "$file") | |
local realpath_dir=$(cd -- "$dir" && pwd -P) |
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
#include <stdio.h> | |
#include <stdlib.h> | |
#include <unistd.h> | |
#include <assert.h> | |
#include <string.h> | |
#include <sys/types.h> | |
#include <sys/socket.h> | |
#include <netinet/in.h> | |
#include <netdb.h> |
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
#include <pthread.h> | |
#include <stdlib.h> | |
#include <stdio.h> | |
#include <assert.h> | |
#define NTH 100U | |
#define MXC 100U | |
#define JUNK "UIACZNEYIAZCBIYAZUBYECIZAUBEIYZUABCEYZAUBEYIAZUBCYAUEBCYZIU" \ | |
"UIACZNEYIAZCBIYAZUBYECIZAUBEIYZUABCEYZAUBEYIAZUBCYAUEBCYZIU" \ | |
"UIACZNEYIAZCBIYAZUBYECIZAUBEIYZUABCEYZAUBEYIAZUBCYAUEBCYZIU" \ |
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
uint32_t djb_hash(const char * const key, size_t keylen) | |
{ | |
uint32_t j = (uint32_t) 5381U; | |
const unsigned char *ukey = (const unsigned char *) key; | |
size_t i = (size_t) 0U; | |
if (keylen >= (size_t) 8U) { | |
const size_t keylen_chunk = keylen - 8U; | |
while (i <= keylen_chunk) { | |
const unsigned char * const p = ukey + i; | |
i += (size_t) 8U; |