Skip to content

Instantly share code, notes, and snippets.

View shergin's full-sized avatar
🤔
But... why?

Valentin Shergin shergin

🤔
But... why?
View GitHub Profile
mailChecker = {
address: '[email protected]',
constructor: function() {
this.checkMail();
// method 1: use closure
var context = this;
function check() { context.checkMail(); }
// end of method 1
function create(x) {
// {node, name, child, attribute, property, event, link (node, ), service, append}
if (x instanceof Widget)
x = x.main();
if (x.nodeType)
return x;
var node = null;
var node = this.create({
name: 'edit' +
' ' + issue.mark +
' ' + issue.folder,
property: {issue: issue.id},
reference: {edit: issue.node},
child: [
{name: 'content', child: [
{name: 'title', child: [
{name: 'left mark'},
Date.prototype.days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
Date.prototype.months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
Date.prototype.military = !/\b(am|pm)\b/i.test(new Date().toLocaleTimeString());
Date.prototype.military = false;
(function () {
var date = new Date();
date.setFullYear(2013, 10, 11);
var string = date.toLocaleDateString();
@shergin
shergin / resize.js
Created October 15, 2011 16:53
Resizer
javascript:{var width = 800; var height = 600; var dy = window.outerHeight - document.documentElement.clientHeight; var dx = window.outerWidth - document.documentElement.clientWidth; window.resizeTo(width + dx, height + dy);}
@shergin
shergin / gist:1723959
Last active August 21, 2022 16:27
resolveURL
function resolveURL(baseURL, relativeURL) {
var html = document.implementation.createHTMLDocument("");
var base = html.createElement("base");
base.setAttribute("href", baseURL);
var a = html.createElement("a");
a.setAttribute("href", relativeURL);
html.head.appendChild(base);
html.body.appendChild(a);
return a.href;
}
@shergin
shergin / gist:3938422
Created October 23, 2012 12:08
javascript protocol
<a href="#" onclick="return onLinkClick(this)" link="http://softline.ru">SoftLine</a>
window.addEventListener('onload', onLoad, false);
function onLoad() {
var nodes = document.getElementsByTagName('a');
for (var i = nodes.length; i--;) {
var node = nodes[i];
@shergin
shergin / main.m
Last active August 29, 2015 14:13
Finding the most frequent character in string
#import <Foundation/Foundation.h>
#import <stdio.h>
#include <math.h>
#include <time.h>
typedef unsigned long characters_count_t;
typedef char character_t;
typedef unsigned char unsigned_character_t;
void mostFrequentCharacterEx(character_t *str, characters_count_t size, character_t *character, characters_count_t *count)
@shergin
shergin / EditDistance.swift
Created January 8, 2016 00:29
Edit Distance in Swift
enum EditOperation<Element> {
case Delete(index: Int)
case Insert(index: Int, element: Element)
case Substitute(index: Int, element: Element)
case DoNothing
var distance: Int {
switch self {
case .DoNothing: