Skip to content

Instantly share code, notes, and snippets.

View h2rd's full-sized avatar

Igor Skrynkovskyy h2rd

View GitHub Profile
var a = [1,2,3,4,5,6,7,8];
Array.prototype.map = function(callback) {
var mapped = [];
for (var i = 0; i < this.length; i++) {
mapped[i] = callback.call(null, this[i]);
}
return mapped;
};
$.fn.getAttributes = function() {
var attributes = {};
if(this.length === 0) {
return attributes;
}
$.each(this[0].attributesttributes, function(index, attr) {
attributes[attr.name] = attr.value;
});
var unique = function(origArr) {
var newArr = [],
origLen = origArr.length,
found,
x, y;
for ( x = 0; x < origLen; x++ ) {
found = undefined;
for ( y = 0; y < newArr.length; y++ ) {
if ( origArr[x] === newArr[y] ) {
var unique = function(origArr) {
var newArr = [],
origLen = origArr.length,
found,
x, y;
for ( x = 0; x < origLen; x++ ) {
found = undefined;
for ( y = 0; y < newArr.length; y++ ) {
if ( origArr[x] === newArr[y] ) {
<?php
class UniqId {
public static function get() {
static $db = null;
if ( $db == null ) {
$db = new UniqId();
}
return $db;
protected function doRequest($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'spider');
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
$html = curl_exec($ch);
$header = curl_getinfo($ch);
@h2rd
h2rd / gist:1699842
Created January 29, 2012 17:55 — forked from alright/gist:1698905
Vkontakte API class
<?php
class Vkapi {
protected $_access_token = '%access_token%';
protected $_client_id = 0;
public static function factory ()
{
$class = get_class();
@h2rd
h2rd / renamer.php
Created March 9, 2012 15:59
Translite with php
<?php
function slugify($text) {
return strtolower(strtr(trim($text), array(' '=>'_') ));
}
function translit($str){
static $tbl= array(
'а'=>'a', 'б'=>'b', 'в'=>'v', 'г'=>'g', 'д'=>'d', 'е'=>'e', 'ж'=>'g', 'з'=>'z',
'и'=>'i', 'й'=>'y', 'к'=>'k', 'л'=>'l', 'м'=>'m', 'н'=>'n', 'о'=>'o', 'п'=>'p',
moduleKeywords = ['included', 'extended']
class Module
@extend: (object) ->
for key, value of object when key not in moduleKeywords
@[key] = value
object.included?.apply(@)
this
@h2rd
h2rd / clone.coffee
Created April 10, 2012 14:02
Clone object
clone = (object) ->
if not object? or typeof object isnt 'object'
return object
instance = object.constructor()
for key of object
instance[key] = clone object[key]
return instance