Skip to content

Instantly share code, notes, and snippets.

View DavidGoussev's full-sized avatar

David Goussev DavidGoussev

View GitHub Profile
@DavidGoussev
DavidGoussev / commentbox.js
Created September 26, 2015 22:30
react commentbox js
var Comment = React.createClass({
rawMarkup: function() {
var rawMarkup = marked(this.props.children.toString(), {sanitize: true});
return { __html: rawMarkup };
},
render: function() {
return (
<div className="comment">
<h2 className="commentAuthor">
@DavidGoussev
DavidGoussev / def pitch_class(note)
Last active December 31, 2015 07:05
musical pitch hash
def pitch_class(note)
hash = { 'C' => 0, 'D' => 2, 'E' => 4, 'F' => 5, 'G' => 7, 'A' => 9, 'B' => 11 }
if note == 'B#'
return 0
elsif note == 'Cb'
return 11
elsif note.length > 2
return nil
elsif note.include?('#')
hash[note.delete('#')] + 1
@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
@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 / 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 / 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 / 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 / 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 / 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 / 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();