Skip to content

Instantly share code, notes, and snippets.

View nikolaifedorov's full-sized avatar

Nikolai Fedorov nikolaifedorov

View GitHub Profile

Ex. 2. RegExp crossword

"Royal Dinner"

(FI|A)+ (YE|OT)K (.)[IF]+ [NODE]+ (FY|F|RG)+
(Y|F)(.)\2[DAF]\1 F O O D F
*(U|O|I)T[FRO]+ I T F O R
[KANE]*[GIN]* A K I N G
RegExp.clone = function (regExp) {
var pattern = regExp.source,
isGlobal = regExp.global,
isIgnoreCase = regExp.ignoreCase,
isMultiline = regExp.multiline;
flags = '';
flags += isGlobal ? 'g' : '';
flags += isIgnoreCase ? 'i' : '';
flags += isMultiline ? 'm' : '';
// kills long running ops in MongoDB (taking seconds as an arg to define "long")
// attempts to be a bit safer than killing all by excluding replication related operations
// and only targeting queries as opposed to commands etc.
killLongRunningOps = function(maxSecsRunning) {
currOp = db.currentOp();
for (oper in currOp.inprog) {
op = currOp.inprog[oper-0];
if (op.secs_running > maxSecsRunning && op.op == "query" && !op.ns.startsWith("local")) {
print("Killing opId: " + op.opid
r(function() {
Backtrace = {};
Backtrace.Router = (function() {
Router.prototype.optionalParam = /\((.*?)\)/g;
Router.prototype.namedParam = /:\w+/g;
function adler32(data) {
var MOD_ADLER = 65521;
var a = 1, b = 0;
var index;
// Process each byte of the data in order
for (index = 0; index < data.length; ++index) {
a = (a + data.charCodeAt(index)) % MOD_ADLER;
b = (b + a) % MOD_ADLER;
}
@nikolaifedorov
nikolaifedorov / gist:8076316
Created December 21, 2013 22:58
This example iterates over all the files selected by the user using an input element
// https://developer.mozilla.org/en-US/docs/Web/API/FileList
// fileInput is an HTML input element: <input type="file" id="myfileinput" multiple>
var fileInput = document.getElementById("myfileinput");
// files is a FileList object (similar to NodeList)
var files = fileInput.files;
var file;
// loop trough files
@nikolaifedorov
nikolaifedorov / ruby_ftp_example.rb
Last active December 21, 2015 19:19 — forked from 3dd13/ruby_ftp_example.rb
Sample code of using Ruby Net::FTP library. Login to FTP server, list out files with parsing for unix-like ftp, check directory existence, upload files
require 'net/ftp'
CONTENT_SERVER_DOMAIN_NAME = "one-of-the-ftp-server.thought-sauce.com.hk"
CONTENT_SERVER_FTP_LOGIN = "saucy-ftp-server-login"
CONTENT_SERVER_FTP_PASSWORD = "saucy-ftp-server-password"
# LOGIN and LIST available files at default home directory
Net::FTP.open(CONTENT_SERVER_DOMAIN_NAME, CONTENT_SERVER_FTP_LOGIN, CONTENT_SERVER_FTP_PASSWORD) do |ftp|
files = ftp.list.map{ |obj| parse_ls_unix_like_format(obj) }
@nikolaifedorov
nikolaifedorov / dropboxfs.rb
Last active December 21, 2015 11:18
Ruby script that implements a readonly FUSE FS. It uses the web interface for it's data. more see: https://forums.dropbox.com/topic.php?id=4164 http://dl.dropboxusercontent.com/u/263514/dropboxfs.rb
#! /usr/bin/env ruby
#
# dropboxfs.rb
#
# Copyright (c) 2008 Raymond Sneekes (raymond@sneek.es)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
@nikolaifedorov
nikolaifedorov / file_managers.js.coffee
Created August 7, 2013 13:31 — forked from giosakti/file_managers.js.coffee
Adding Custom Context Menu for elFinder
# ======================================================================
# admin/file_managers.js.coffee
#
# Description:
# contains snippets & functions for handling file-manager-related operation.
# ======================================================================
root = exports ? this
$ ->
Copyright (c) 2012 James Conroy-Finn
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE US