Skip to content

Instantly share code, notes, and snippets.

@lyoshenka
lyoshenka / unserialize.js
Last active December 21, 2018 09:39 — forked from brucekirkpatrick/jquery.unserialize.js
Takes a string in format "param1=value1&param2=value2" and returns an javascript object. The opposite of https://api.jquery.com/serialize
/**
* $.unserialize
*
* Takes a string in format "param1=value1&param2=value2" and returns an object { param1: 'value1', param2: 'value2' }. If the "param1" ends with "[]" the param is treated as an array.
*
* Example:
*
* Input: param1=value1&param2=value2
* Return: { param1 : value1, param2: value2 }
*
@lyoshenka
lyoshenka / on_external_click.js
Created May 24, 2015 15:13
Detect a click outside of an element
/**
* Detects click outside element and calls callback()
*
* primaryElement - detect clicks outside this element. If element is removed from DOM, stop click detection.
* otherElements - optional array of elements that are also considered to be part of the primary elements (clicks in them are not external clicks)
* callback - function to call when an outclick is detected. Callback is passed the triggering Event.
*/
function onExternalClick(primaryElement, otherElements, callback) {
var uniqueCount = 0;
var ensureUniqueId = function(el) {
@lyoshenka
lyoshenka / stick-on-scroll.js
Last active August 29, 2015 14:21
Stick element to top of screen as you scroll past it.
$.fn.stickOnScroll = function() {
var $document = $(document),
element = $(this),
stuck = false,
didScroll = false,
offsetTop = parseInt(element.offset().top),
placeholder = $('<div>'),
scrollInterval = null,
stick = function() {
placeholder.css('height', element.css('height')).show();
@lyoshenka
lyoshenka / kill_bot_requests.php
Created May 20, 2015 15:40
Kill all requests from bots in an emergency
<?php
if (preg_match('/(bot|spider|crawler)/i', $_SERVER['HTTP_USER_AGENT']))
{
header("HTTP/1.1 503 Service Temporarily Unavailable");
header("Status: 503 Service Temporarily Unavailable");
die(1);
}
* {
font-size: 12pt;
font-family: monospace;
font-weight: normal;
font-style: normal;
text-decoration: none;
color: black;
cursor: default;
}
@lyoshenka
lyoshenka / file_upload.php
Created April 1, 2015 10:35
A super simple single-file upload script
<?php
ini_set('file_uploads', 'On');
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
$target_file = __DIR__ . '/' . basename($_FILES["fileToUpload"]["name"]);
// Check if file already exists
if (file_exists($target_file))
@lyoshenka
lyoshenka / strict_mode.php
Last active August 29, 2015 14:17
Strict mode for PHP. Show all errors, throw exceptions for errors, etc.
ini_set('display_errors', 'on');
error_reporting(E_ALL);
set_error_handler(function ($type, $message, $file = null, $line = null, $context = null) {
// dont throw error if it might have been supressed with an @
if ($file !== null && $line !== null)
{
$errorLine = explode("\n", file_get_contents($file))[$line-1];
if (strpos($errorLine, '@') !== false && !preg_match('/@[a-z0-9-_.]+\.[a-z]{2,6}/i', $errorLine))

Rich Hickey on becoming a better developer

Rich Hickey • 3 years ago

Sorry, I have to disagree with the entire premise here.

A wide variety of experiences might lead to well-roundedness, but not to greatness, nor even goodness. By constantly switching from one thing to another you are always reaching above your comfort zone, yes, but doing so by resetting your skill and knowledge level to zero.

Mastery comes from a combination of at least several of the following:

@lyoshenka
lyoshenka / xhr.js
Last active November 14, 2016 09:27
Simple JS AJAX wrapper that supports JSONP too.
/*
Usage:
xhr('GET', '/endpoint')
.success(function (data) { console.log(data); alert('AJAX success'); })
.error(function (data) { console.log(data); alert('AJAX ERROR'); });
*/
xhr = function (type, url, data) {
var methods = {
#!/bin/bash
## Copyright (C) 2009 Przemyslaw Pawelczyk <[email protected]>
## License: GNU General Public License v2, v3
#
# Lockable script boilerplate
### HEADER ###
LOCKFILE="/var/lock/`basename $0`"