Skip to content

Instantly share code, notes, and snippets.

View yefim's full-sized avatar

Yefim Vedernikoff yefim

View GitHub Profile
@yefim
yefim / create-repo.sh
Created May 4, 2012 06:10
Create a new GitHub repo
#!/bin/bash
read -s -p "GitHub password: " pass
# I assume the GitHub API and authentication works because I don't want to parse JSON
curl -u "yefim323:$pass" https://api.github.com/user/repos -d "{\"name\":\"$1\"}" > /dev/null
git remote add origin [email protected]:yefim323/$1.git
@yefim
yefim / sort_by_letter_freq.js
Created May 22, 2012 08:51
Sorts a string by the frequency of characters.
var sort_by_freq = function(str) {
var i, j;
var map = [];
var sorted = [];
for (i = 0; i < str.length; i++) {
if (map[str.charAt(i)] == null) {
map[str.charAt(i)] = 1;
} else {
map[str.charAt(i)] = map[str.charAt(i)] + 1;
}
@yefim
yefim / q.coffee
Last active November 17, 2020 03:02
Queue implementation in CoffeeScript
class Q
constructor: (@bound) ->
@offset = 0
@length = 0
@data = []
enqueue: (value) ->
return undefined if @length == @bound
@data.push value
++@length
dequeue: ->
@yefim
yefim / scrape.js
Created November 15, 2012 05:28
Simplest scraper
// Count all of the links from the nodejs build page
var jsdom = require("jsdom");
jsdom.env(
"http://nodejs.org/dist/",
["http://code.jquery.com/jquery.js"],
function (errors, window) {
$ = window.$;
console.log("there have been " + $("a").length + " nodejs releases!");
}
@yefim
yefim / doublell.cpp
Created December 16, 2012 04:29
Doubly Linked list implementation
#include <iostream>
#include <string>
#include "doublell.h"
using namespace std;
DoubleLL::DoubleLL()
{
head = NULL;
tail = NULL;
@yefim
yefim / merge_sort.coffee
Last active December 14, 2015 06:29
Merge Sort implemented in CoffeeScript
merge = (a, p, q, l) ->
L = a[p..q]
R = a[q+1..l]
L.push Infinity
R.push Infinity
i = 0
j = 0
for k in [p..l]
if L[i] <= R[j]
a[k] = L[i]
@yefim
yefim / bfs.coffee
Created February 27, 2013 05:57
BFS implemented in CoffeeScript
# G = [vertices]
# vertex = {
# adjacency_list: [vertex_ids]
# color: one of ["WHITE", "GRAY", "BLACK"]
# parent: vertex
# d: depth
# }
module.exports =
test: ->
@yefim
yefim / dfs.coffee
Created February 27, 2013 07:27
DFS implemented in CoffeeScript
# G = [vertices]
# vertex = {
# adjacency_list: [vertex_ids]
# color: one of ["WHITE", "GRAY", "BLACK"]
# parent: vertex
# d: discovery time
# f: finish time
# }
DFS_VISIT = (G, u) ->
@yefim
yefim / quicksort.coffee
Created February 27, 2013 08:15
Quicksort implemented in CoffeeScript
partition = (A, p, l) ->
x = A[l]
i = p - 1
for j in [p..l-1]
if A[j] <= x
i++
[A[i], A[j]] = [A[j], A[i]]
[A[i+1], A[l]] = [A[l], A[i+1]]
return i + 1
@yefim
yefim / random_guesser.coffee
Created March 10, 2013 19:39
Random guesser for the Guessing Game
contestant = {
start_game: (configs) ->
@guesses = [0..configs.game_size-1]
guess_index: (input) ->
i = Math.floor(Math.random() * @guesses.length)
@guesses.splice(i, 1)[0]
}