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
worker_processes 1; | |
events { | |
worker_connections 1024; | |
} | |
http { | |
include mime.types; | |
default_type application/octet-stream; |
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
#Strip HTML tags | |
def strip_html(allowed = []) | |
str = self.strip || '' | |
str.gsub(/<(\/|\s)*[^(#{allowed.join('|') << '|\/'})][^>]*>/,'') | |
end |
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
* instance_eval, class_eval, module_eval | |
* instance_eval, evaluates code on instance level: | |
class Bongas | |
class << self | |
def nu_kazka | |
puts "Nu Kazka Bongas" | |
end | |
end | |
end | |
Bongas.instance_eval { nu_kazka } # -> "Nu Kazka Bongas" |
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
What JavaScript considers as False: false, null, undefined, '', 0, NaN. | |
--- | |
Objects are passed around by reference. They are never copied: | |
var x = stooge; | |
x.nickname = 'Curly'; | |
var nick = stooge.nickname; | |
// nick is 'Curly' because x and stooge | |
// are references to the same object |
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
# =stylesheet_include_tag | |
def stylesheet_include_tag(filename) | |
mtime = File.new(File.join(APP_PATH,"public","stylesheets","#{filename}.css")).mtime | |
%Q(<link rel="stylesheet", href="/stylesheets/#{filename}.css?#{mtime.to_i}"></link>) | |
end | |
... | |
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
=config | |
# use colors in git output | |
git config --global color.ui true | |
=basics | |
git branch -d test //delete branch | |
=.gitignore file | |
*a # ignore all with .a ext | |
!lib.a # except file "lib.a" |
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
=users and groups | |
# add user into 'admin' group, only users in 'admin' group can use 'sudo' | |
sudo usermod -G admin username | |
# useradd defaults | |
/etc/default/useradd | |
# check to what groups user belongs to | |
id username | |
# ubuntu | |
adduser, addgroup |
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
def match! battle, winner, loser | |
r_a = winner.rating | |
r_b = loser.rating | |
max = battle.max.to_i | |
min = battle.min.to_i | |
th = ( max - min ) / 2 | |
e_a = 1.0 / ( 1 + 10 ** ( (r_b - r_a) / 400 )) | |
e_b = 1.0 / ( 1 + 10 ** ( (r_a - r_b) / 400 )) |
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
def foo(x, y=10, **kwargs): | |
# dictionaries | |
dict = {'a':1, 'b':23, 'c':'eggs'} | |
del dict['b'] | |
dict.has_key('e') | |
# list comprehension | |
[x for x in range(5) if x%2 == 0] | |
# exception |
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
canvas = document.createElement("canvas"), | |
ctx = canvas.getContext("2d"); | |
canvas.className = "myClass"; | |
canvas.id = "myId"; | |
canvas.width = image.width; | |
canvas.height = image.height; | |
ctx.drawImage(image, 0, 0); | |
pixelData = ctx.getImageData(0, 0, image.width, image.height); |
OlderNewer