Skip to content

Instantly share code, notes, and snippets.

View wegorich's full-sized avatar
💩
Crappy codding

Egor Malkevich wegorich

💩
Crappy codding
View GitHub Profile
@wegorich
wegorich / add_position_to_asset.rb
Created February 13, 2014 13:52
Make items sortable and store at db
# db/migrations/your_migration
class AddPositionToAsset < ActiveRecord::Migration
def change
add_column :assets, :position, :integer
end
end
@wegorich
wegorich / _addthis.haml
Created February 16, 2014 12:34
Adding castom add this buttons to your site
#app/views/shared/_addthis.haml
.addthis_toolbox.addthis_default_style
-# %a.addthis_button_vk
-# %i.icon-vkontakte
-# %a.addthis_button_facebook
-# %i.icon-facebook-sign
-# %a.addthis_button_google_plusone_share
-# %i.icon-google_oauth2-sign
-# %a.addthis_button_twitter
@wegorich
wegorich / index.html
Created February 20, 2014 13:15
d3.js collision detection
<!DOCTYPE html>
<meta charset="utf-8">
<body>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script>
var width = 960,
height = 500;
var nodes = d3.range(200).map(function() { return {radius: Math.random() * 12 + 4}; }),
@wegorich
wegorich / staging.rb
Created March 7, 2014 08:16
set password to staging
config.middleware.insert_after(::Rack::Runtime, "::Rack::Auth::Basic", "Staging") do |u, p|
[u, p] == ['username', 'password']
end
@wegorich
wegorich / phone.coffee
Created March 31, 2014 11:43
USA phone formating
format_phone = (phone, convert, trim) ->
convert = true if typeof convert is "undefined"
trim = true if typeof trim is "undefined"
# Strip out any extra characters that we do not need only keep letters and numbers
phone = phone.replace(/[^0-9A-Za-z]/, "")
# Do we want to convert phone numbers with letters to their number equivalent?
if convert is true and phone.match(/[a-zA-Z]/)
replace =
{
"AL": "Alabama",
"AK": "Alaska",
"AS": "American Samoa",
"AZ": "Arizona",
"AR": "Arkansas",
"CA": "California",
"CO": "Colorado",
"CT": "Connecticut",
"DE": "Delaware",
@wegorich
wegorich / playSound.coffee
Created May 20, 2014 12:24
Simple way to play small sounds on a background using Web Audio API. Used for phone keypad
angular.module('module').factory "Sound", () ->
class Sound
constructor: ()->
@context = new webkitAudioContext()
@cache = {}
@request = new XMLHttpRequest()
@request.responseType = "arraybuffer"
@wegorich
wegorich / gist:b9e4c3715bd5aebe6f24
Created July 25, 2014 13:09
JS doing the N.times in Ruby code
var list = Array.apply(null, { length: 100 }).map(Number.call, Number).map(function (i) {
return callback(i);
});
@wegorich
wegorich / gist:0ac26eb71ea9288550a6
Created August 21, 2014 13:43
simple fib function
def fib(n):
a, b = 0, 1
while a < n:
print(a)
a, b = b, a+b