Skip to content

Instantly share code, notes, and snippets.

View DavidGoussev's full-sized avatar

David Goussev DavidGoussev

View GitHub Profile
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<p id="text"></p>
<script>
@DavidGoussev
DavidGoussev / donteatthelastcake.rb
Created December 19, 2015 07:51
Dont Eat the Last Cake!
class Player
def initialize(cakes)
end
# Decide who move first - player or opponent (return true if player)
def firstmove(cakes)
# games with < 2 cakes are unwinnable when going first because the starting player
# can always be forced into a loss condition:
# 1 cakes
# - pick 1 (lose, they ate the cake!)
@DavidGoussev
DavidGoussev / app.js
Created December 6, 2015 06:02
flipboard_slide jquery
var main = function() {
$('.dropdown-toggle').click(function() {
$('.dropdown-menu').toggle();
});
$('.arrow-next').click(function() {
var currentSlide = $('.active-slide');
var nextSlide = currentSlide.next();
@DavidGoussev
DavidGoussev / status_update.js
Created December 6, 2015 05:15
status_update jquery
var main = function() {
$('.btn').click(function() {
var post = $('.status-box').val();
$('<li>').text(post).prependTo('.posts');
$('.status-box').val('');
$('.counter').text('140');
$('.btn').addClass('disabled');
});
$('.status-box').keyup(function() {
@DavidGoussev
DavidGoussev / twitter_api.rb
Created December 6, 2015 04:18
twitter api
# TWITTER API
require 'rubygems'
require 'oauth'
require 'open-uri'
# Parse a response from the API and return a user object.
def parse_user_response(response)
user = nil
@DavidGoussev
DavidGoussev / topthree.rb
Last active November 19, 2015 07:41
Top-Three in Array by Length
def top_3_words(text)
words = text.split(/('\w+)|(\w+'\w+)|(\w+')|(\w+)/)
words.max_by(3) {|x| words.length }
end
def top_3_words(text)
words = text.split(/[^a-zA-Z0-9']+/)
words.each{|word| word.downcase!}
puts words
@DavidGoussev
DavidGoussev / GIF-Screencast-OSX.md
Created November 16, 2015 22:06 — forked from dergachev/GIF-Screencast-OSX.md
OS X Screencast to animated GIF

OS X Screencast to animated GIF

This gist shows how to create a GIF screencast using only free OS X tools: QuickTime, ffmpeg, and gifsicle.

Screencapture GIF

Instructions

To capture the video (filesize: 19MB), using the free "QuickTime Player" application:

@DavidGoussev
DavidGoussev / apikey logic
Created October 31, 2015 20:55
Marvel API
if(cache_key in cache) {
console.log('had cache for '+cache_key);
var images = cache[cache_key].images;
cache[cache_key].hits++;
cb(images[getRandomInt(0, images.length-1)]);
} else {
var monthStr = month<10?"0"+month:month;
//lame logic for end of month
var eom = month==2?28:30;
var beginDateStr = year + "-" + monthStr + "-01";
@DavidGoussev
DavidGoussev / plugboard.rb
Last active October 8, 2015 06:08
plug board
class Plugboard
def initialize(wires = "")
chars = wires.split('')
if chars.length % 2 == 1 || chars.length > 20
raise
end
@hash = Hash.new
chars.each_with_index do |c, index|
if index % 2 == 0
@DavidGoussev
DavidGoussev / matrices
Created September 30, 2015 04:01
matrices
(1)
def diagsum(matrix)
(0...matrix.length).map{ |i| matrix[i][i] }.reduce(:+)
end
# uses map enumerator for the array of matrix values - remember to use the three-dot notation as it omits the last value since array starts at 0
# matrix[i][i] indicates the array position of each diagonal value for each row (row, column will be the same value for a square matrix
# reduce(:+) is an enumerator method sums up the block values that were just mapped from the array