Skip to content

Instantly share code, notes, and snippets.

@moalex
moalex / README.md
Last active December 8, 2020 16:28
Snoopy - the PHP net client
@moalex
moalex / getscript.js
Last active December 17, 2015 05:38
more or less stolen form jquery core and adapted by paul irish ### usage: getScript('http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js',function(){ alert('jQuery loaded. yay life') });
function getScript(url,success){
var head = document.getElementsByTagName("head")[0], done = false;
var script = document.createElement("script");
script.src = url;
// Attach handlers for all browsers
script.onload = script.onreadystatechange = function(){
if ( !done && (!this.readyState || this.readyState == "loaded" || this.readyState == "complete") ) {
done = true;
success();
}
@moalex
moalex / image-resize.php
Created September 28, 2013 04:11
Resize proportionally specifying just height or width <img src="resize.php?w=150&img=apple.jpg" /> <img src="resize.php?h=250&img=apple.jpg" /> Resize specifying height and width Specifying a width and a height will stretch an image to fit these dimensions, it will not crop your images. <img src="resize.php?w=150&h=250&img=apple.jpg" />
<?php
/*
Simple PHP Image Resizer
Copyright (c) 2012 Ryan Fait
www.ryanfait.com
INSTRUCTIONS:
Specify just the width: <img src="/dir/resize.php?w=100&amp;img=/test.jpg" />
@moalex
moalex / flat-pinboard.css
Created October 2, 2014 21:50
Userscripts & Userstyles
@-moz-document domain("pinboard.in") {
/* Theme Name: Flat Pinboard */
/* Theme URL: http://tackk.com/flat-pinboard */
/* Version: v1.0 */
/* Created by: Dan Klammer */
/* Broswer: Chrome + Stylish Extension */
html {
-webkit-font-smoothing:antialiased;
height:100%;
@moalex
moalex / clearness-dark.markdown.css
Last active February 16, 2021 17:46
Markdown Styles
h1,
h2,
h3,
h4,
h5,
h6,
p,
blockquote {
margin: 0;
padding: 0;

htaccess

DirectoryIndex index.php index.html index.htm
Options +Indexes
IndexOptions IgnoreCase FancyIndexing FoldersFirst NameWidth=* DescriptionWidth=* SuppressHTMLPreamble

php_flag display_errors on
php_value error_reporting E_ALL &amp; ~E_NOTICE

jQuery - Создание плагина

Как вы уже знаете, одним из главных качеств библиотеки jQuery является очень удобный поиск элементов и возможность дальнейших манипуляций с ними. Так вот, список этих манипуляций можно расширять, организуя новые методы для объекта jQuery. Вынесенные в отдельный файл, такие расширения образуют плагины для библиотеки jQuery.

Далее, описывая правила создания собственных плагинов мы будем реализовывать отдельный полноценный плагин в качестве примера. Его функциональность будет состоять в добавлении нового поведения для выбранных элементов — изменение цвета при наведении курсора. Назовем плагин responsiveBlock (отзывчивый блочный элемент).

Подключение

/*
* Запуск следующего кода до любого другого создаст метод trim(), если он ещё не реализуется браузером.
*
*/
if (!String.prototype.trim) {
(function() {
// Вырезаем BOM и неразрывный пробел
String.prototype.trim = function() {
return this.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
};

cURL

15 Practical Command Examples

cURL is a software package which consists of command line tool and a library for transferring data using URL syntax.

cURL supports various protocols like, DICT, FILE, FTP, FTPS, Gopher, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, POP3, POP3S, RTMP, RTSP, SCP, SFTP, SMTP, SMTPS, Telnet and TFTP.

PHP - POST JSON Data with cURL

<?php
$data = array("name" => "Hagrid", "age" => "36");                                                                    
$data_string = json_encode($data);                                                                                   
                                                                                                                     
$ch = curl_init('http://api.local/rest/users');                                                                      
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");