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 / shift.date.js
Created January 2, 2016 21:31
When we want publish an article in time range, we have to use something like that
var baseDate = new Date();
function shiftDate(date, minutes){
date = new Date(date.valueOf() + minutes * 60 * 1000);
if (date.getHours() > 22){
date.setHours(7);
date.setDate(date.getDate() + 1);
}
return date;
}
@wegorich
wegorich / gist:8a0089309962bb0237b9
Created November 24, 2015 10:16
Magic of index
~"cat".indexOf("r") // false
@wegorich
wegorich / command
Created November 22, 2015 21:13
Update mongodb OS X
$ brew updae
Already up-to-date
$ brew install mongodb
Error: mongodb-2.6.8 already installed
To install this version, first `brew unlink mongodb`
$ brew upgrade mongodb
==> Updating 1 outdated package, with result:
mongodb 3.0.4
...
@wegorich
wegorich / crap.js
Last active September 17, 2015 07:12
Crap coding best practise
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
var logger = require("./server/components/logger");
///
// Set default node environment to development
var express = require('express');
var mongoose = require('mongoose');
var config = require('./server/config/environment');
var fs = require('fs'),
@wegorich
wegorich / snippet.js
Last active August 29, 2015 14:22 — forked from necolas/snippet.js
/*
* Updated to use the function-based method described in http://www.phpied.com/social-button-bffs/
* Better handling of scripts without supplied ids.
*
* N.B. Be sure to include Google Analytics's _gaq and Facebook's fbAsyncInit prior to this function.
*/
(function(doc, script) {
var js,
fjs = doc.getElementsByTagName(script)[0],
@wegorich
wegorich / goo.gl.formatter.js
Created January 5, 2015 11:17
goo.gl format link for dissertation literature
var textToPutOnClipboard = "This is some text";
document.addEventListener('copy', function(e) {
e.clipboardData.setData('text/plain', textToPutOnClipboard);
e.preventDefault();
});
$('#shortenerSubmitButton').on('mousedown',function(){
setTimeout(function(){
var host = new URL($('#shortenerInputText').val()).hostname;
@wegorich
wegorich / assets.py
Last active August 29, 2015 14:11
How generate path to assets at Django
css_css = Bundle(
'css/css.css',
filters=['cssrewrite'],
output='compiled_css.%(version)s{0}.css'.format(settings.GLOBAL_CACHE_LETTER))
register('css', css_css)
@wegorich
wegorich / html
Created November 4, 2014 07:51
Disable submit empty string in native html
<input type="text" required pattern=".*\S+.*" />
@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
@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);
});