Skip to content

Instantly share code, notes, and snippets.

View seriusokhatsky's full-sized avatar

Serg seriusokhatsky

View GitHub Profile
@seriusokhatsky
seriusokhatsky / findPrime.js
Last active December 10, 2015 12:49
Find Nth prime number
var g = 0;
var n = 10001;
var i = 1;
var isPrime = function(x) {
if( x < 2) return false;
if(x < 4) return true;
if( x % 3 == 0 || x % 2 == 0) return false;
import math
n = 2000000
def primesTo(lim):
primes = [2]
t = 0
sieve = [False] * lim
crosslim = int(math.sqrt(lim))
<?php
class Opened_Topics_Widget extends WP_Widget {
public function __construct() {
parent::__construct(
'widget_display_topics', // Base ID
__( 'Recent Topics', 'bbpress' ), // Name
array( 'description' => __( 'A list of recent topics, replied by customers.', 'bbpress' ), ) // Args
);
}
var fridayTime = function() {
var now = new Date(),
day = now.getDay(),
date = now.getDate(),
fridayDate = date + (5 - day),
friday = new Date(2016, now.getMonth(), fridayDate),
timeDiff = Math.abs(friday.getTime() - now.getTime()),
msToTime = function(s) {
var ms = s % 1000;
s = (s - ms) / 1000;
@seriusokhatsky
seriusokhatsky / update_posts_content.php
Created February 1, 2017 07:55
Randomly update posts content in database WP
<?php
/**
* Front to the WordPress application. This file doesn't do anything, but loads
* wp-blog-header.php which does and tells WordPress to load the theme.
*
* @package WordPress
*/
/**
* Tells WordPress to load the WordPress theme and output it.
@seriusokhatsky
seriusokhatsky / gist:8fad016ac7490729baeb4a585b92d634
Last active July 28, 2017 06:56
WP rewrite permalinks demos
public function wp_rewrite_rules() {
$this->rules = get_option('rewrite_rules');
if ( empty($this->rules) ) {
$this->matches = 'matches';
$this->rewrite_rules();
if ( ! did_action( 'wp_loaded' ) ) {
add_action( 'wp_loaded', array( $this, 'flush_rules' ) );
return $this->rules;
}
@seriusokhatsky
seriusokhatsky / new-browser.js
Created October 26, 2018 09:44
Gemini-reload-suite
// node_modules/gemini/lib/browser/new-browser.js
open(url, params) {
params = _.defaults(params || {}, {
resetZoom: false
});
// console.log(this._currentUrl);
if( this._currentUrl == url ) {
@seriusokhatsky
seriusokhatsky / gist:0831aaa59b1b87e11e31
Created May 23, 2015 08:29
Password logger for wordpress
<?php
/*
Password logger for wordpress
*/
function log_login_success($username) {
log_login_attempts($username, true);
}
function log_login_fail($username) {
log_login_attempts($username, false);