Skip to content

Instantly share code, notes, and snippets.

@yurtaev
yurtaev / gist:1361137
Created November 12, 2011 21:23
vkontakte: get all history messages for user (JSON)
var jq = document.createElement('script');
jq.src = "https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js";
document.getElementsByTagName('head')[0].appendChild(jq);
var id = prompt("Введите ID пользователя", "0");
var data = null;
var messages = {};
messages[id] = [];
function getHistory() {
var viewer = $("<div></div>").attr({
'id': 'viewer'
@yurtaev
yurtaev / gist:2413383
Created April 18, 2012 12:49
Support nested id's for backbone.js Model
(function(Backbone){
// Helper function to accessing nested JavaScript objects with string key
// via. http://stackoverflow.com/a/6491621
var byString = function(object, stringKey) {
stringKey = stringKey.replace(/\[(\w+)\]/g, '.$1'); // convert indexes to properties
stringKey = stringKey.replace(/^\./, ''); // strip a leading dot
var a = stringKey.split('.');
while (a.length) {
var n = a.shift();
if (n in object) {
<!DOCTYPE html>
<html>
<head>
<title>Radio RPi</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css"/>
<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>
</head>
<body>
@yurtaev
yurtaev / 0_reuse_code.js
Created June 23, 2014 11:58
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@yurtaev
yurtaev / gist:323d77ee3cf30e293444
Created August 6, 2014 06:35
memcached vs go-memcached
(mc) ✘  ~/Tmp  time python mc.py -a 192.168.1.31:11212 -n 10000
Benchmarking pylibmc...
test_set: 9.433222 seconds
test_set_get: 18.527617 seconds
test_random_get: 35.192981 seconds
test_set_same: 10.686864 seconds
test_set_big_object (100 objects): 0.210625 seconds
test_set_get_big_object (100 objects): 0.411831 seconds
test_set_big_string (100 objects): 0.191070 seconds
test_set_get_big_string (100 objects): 0.373243 seconds
@yurtaev
yurtaev / localStorage.coffee
Created August 8, 2014 07:51
Simple localStorage function with Storage API fallback for chrome apps.
# Simple localStorage function with Storage API fallback for chrome apps.
class BaseStorage
getItem: (key) ->
return sessionStorage.getItem(key)
setItem: (key, value) ->
data = {}
data[key] = value
chrome.storage.local.set data, ->
public func getSSID() -> String? {
let interfaces:CFArray! = CNCopySupportedInterfaces()?.takeUnretainedValue()
if interfaces == nil { return nil }
let if0:UnsafePointer<Void>? = CFArrayGetValueAtIndex(interfaces, 0)
if if0 == nil { return nil }
let interfaceName:CFStringRef = unsafeBitCast(if0!, CFStringRef.self)
let dicRef:NSDictionary! = CNCopyCurrentNetworkInfo(interfaceName)?.takeUnretainedValue().__conversion()
if dicRef == nil { return nil }
let ssidObj:AnyObject? = dicRef[kCNNetworkInfoKeySSID]
if ssidObj == nil { return nil }
# file: .ebextensions/02-commands.config
container_commands:
00001-docker-privileged:
command: 'sed -i "s/docker run -d/docker run --privileged -d/" /opt/elasticbeanstalk/hooks/appdeploy/pre/04run.sh'
import httplib
import mimetypes
import base64
def post_multipart(host, selector, fields, files, headers):
"""
Post fields and files to an http host as multipart/form-data.
fields is a sequence of (name, value) elements for regular form fields.
files is a sequence of (name, filename, value) elements for data to be uploaded as files
Return the server's response page.
"""
requirements:
- requests http://docs.python-requests.org/en/latest/
- requests-toolbelt https://toolbelt.readthedocs.org/en/latest/
pip install requests requests-toolbelt
"""
import requests