Skip to content

Instantly share code, notes, and snippets.

💭
Experienced workaholic

Sergey Romanov Serhioromano

💭
Experienced workaholic
Block or report user

Report or block Serhioromano

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@Serhioromano
Serhioromano / backup.php
Last active Jul 17, 2018
AWS EC2 automatic volume daily snapshot.
View backup.php
#!/usr/bin/php -q
<?php
date_default_timezone_set('UCT');
$dryrun = FALSE;
$interval = '24 hours';
$keep_for = '10 Days';
$volumes = array('vol-9677d14a');
$api_key = 'AKI****EYUA';
$api_secret = 'IzMni****ct';
@Serhioromano
Serhioromano / paypal.php
Last active Dec 17, 2015
Convert PayPal Adaptive payment IPN into valide array.
View paypal.php
public function decodePayPalIPN()
{
$raw = file_get_contents("php://input");
// sometimes we already have & in returnUrl or cancelUrl
$raw = str_replace("&amp;", '^^^', $raw);
$post = array();
$pairs = explode('&', $raw);
foreach($pairs as $pair)
{
@Serhioromano
Serhioromano / calendar.js
Last active Dec 15, 2015
How to number of week in a year with javascript. The best way is to prototype it into core Javascript Date class so you can use it later in any part of your code.
View calendar.js
Date.prototype.getWeek = function() {
var first = new Date(this.getFullYear(), 0, 1);
return Math.ceil((((this.getTime() - first.getTime()) / 86400000) + first.getDay() + 1) / 7);
}
var date = new Date();
console.log(date.getWeek());
@Serhioromano
Serhioromano / calendar.js
Last active Jan 20, 2017
How to format date in Javascript into 2 digits format. By default javascript `getMonth()` return single digit and even start months index with 0. The best way around is to prototype Javascript core Date class so later you can use it anywhere within your script. The same apply to `getDate()`
View calendar.js
Date.prototype.getMonthFormatted = function() {
var month = this.getMonth() + 1;
return month < 10 ? '0' + month : month;
}
Date.prototype.getDateFormatted = function() {
var date = this.getDate();
return date < 10 ? '0' + date : date;
}
var date = new Date();
@Serhioromano
Serhioromano / tmpl.js
Created Sep 9, 2012
Load underscore templates with jQuery $ajax()
View tmpl.js
window.renderTemplate = function(name, el, json)
{
var url = '/templates/' + name + '.html';
$.ajax({
url: url,
method: 'GET',
async: false,
dataType: 'html',
success: function(data) {
var tmpl = _.template(data);
You can’t perform that action at this time.