Skip to content

Instantly share code, notes, and snippets.

View afanasy's full-sized avatar
🏠
Working from home

Afanasii Kurakin afanasy

🏠
Working from home
View GitHub Profile
@afanasy
afanasy / isCircular.js
Created July 23, 2015 08:12
Javascript function to detect if variable has circular references.
function isCircular (d) {
try {JSON.stringify(d)}
catch (e) {return true}
return false
}
@afanasy
afanasy / php2js.js
Last active November 18, 2015 15:03
Regexps helper to convert php code to javascript
php2js: function (file, out, done) {
fs.readFile(file, {encoding: 'utf8'}, function (err, data) {
var replace = [
{in: /;\n/, out: '\n'},
{in: /->/, out: '.'},
{in: /\$([a-z0-9_]+)/, out: '$1'},
{in: /([a-z0-9_]+?)\['([^\]]+?)'\]/, out: '$1.$2'},
{in: / \. /, out: ' + '},
{in: / \.= /, out: ' += '},
{in: /foreach \(([a-z0-9_.]+?) as &?([a-z0-9_.]+?)\)/, out: '_.each($1, function ($2)'},

A demonstration of SVG's Gaussian blur filter effect: the svg:feGaussianBlur element.

Image source: GitHub's octodex.

@afanasy
afanasy / gist:1527440
Created December 28, 2011 10:13
Thanksgiving date for the given year
new Date(year, 10, 28 - (new Date(year, 10, 1).getDay() + 2) % 7)
@afanasy
afanasy / gist:1281380
Created October 12, 2011 14:36
Ignore .DS_Store and remove it from git history
#ignore
echo '.DS_Store*' >> .gitignore
#remove from history
find . -name '.DS_Store*' | while read f; do git filter-branch --index-filter "git rm --cached --ignore-unmatch $f"; rm -rf .git/refs/original; done;
#cleanup
git gc --prune=now