Skip to content

Instantly share code, notes, and snippets.

View sherman's full-sized avatar
🏠
Working from home

Denis M. Gabaydulin sherman

🏠
Working from home
View GitHub Profile
@sherman
sherman / gist:5065004
Created March 1, 2013 14:29
trivia http server
<?php
set_time_limit (0);
$address = 'localhost';
$port = 9999;
$socket = socket_create(AF_INET, SOCK_STREAM, 0);
socket_get_option($socket, SOL_SOCKET, SO_LINGER);
socket_bind($socket, $address, $port) or die('Could not bind to address');
socket_listen($socket);
@sherman
sherman / gist:5063949
Last active December 14, 2015 09:19
Support handling of HTTP 307 (repost to the given location)
From e623f4d152f175cd804d063543b848471fa422f5 Mon Sep 17 00:00:00 2001
From: "d.gabaydulin" <D.Gabaydulin@qiwi.ru>
Date: Fri, 1 Mar 2013 15:01:33 +0400
Subject: [PATCH] * support handling of HTTP 307 (repost to the given
location)
---
src/client.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
multipleClientQueriesTestTemplate(
ImmutableList.<Pair<Node, Pair<BaseWebSocket, List<String>>>>of(
Pair.<Node, Pair<BaseWebSocket, List<String>>>of(
node1,
Pair.<BaseWebSocket, List<String>>of(
new BaseWebSocket() {
@Override
public void onMessage(String message) {
log.info("answer:" + message);
latch.countDown();
After request [method=GET;uri=/api/feed/posts?ids=413186409059322668&ids=413185660694825764&ids=4131851
49518220066&ids=413175824246639373&ids=413175498080783115&ids=413153978902121206&ids=412555460067985988&ids=412555422679960130&ids=412555350168832576&ids=412555313686776382&ids=412555247416773180&ids=412555215741389368&ids=41255518687618
9238&ids=412555141141498420&ids=412555095121594930&ids=412555055535753776&ids=412555023122172462&ids=412554989852953132&ids=412554968076126762&ids=412476329062041662&ids=412472486542706748&ids=412472137165572154&ids=412471288859199544&id
s=396557214988372178&ids=396555308090001606&ids=396554505501542596&ids=396549650720491712&ids=390696842490284555&ids=384981709403195533&ids=384896478016965398&ids=478481760565332893&ids=476397892060318684&ids=474243458089880206&ids=47353
8421852211300&ids=473538320501049442&ids=428446004824509340&ids=427702303521245648&ids=427702179764111822&ids=427698279011060171&ids=427697806757595593&ids=427690331190856135&ids=427689599662295493&ids=427
require(graphics)
# get first group result
x <- round(rnorm(100, 150, 10))
# get second group result (20% better mean)
y <- sample(c(round(rnorm(80, 150, 10)), round(rnorm(20, 180, 10))))
groups <- c(rep(1, length(x)), rep(2, length(y)))
data <- c(x, y)
# make an observation (difference in mean)
new JsonDeserializer<NativeObject>() {
@Override
public NativeObject deserialize(
JsonElement json,
Type type,
JsonDeserializationContext context
) {
NativeObject object = RhinoUtils.createJsObject(globalCtx);
@sherman
sherman / git-loglive
Created September 16, 2012 14:12 — forked from tlberglund/git-loglive
Log Live Git Command
#!/bin/bash
while :
do
clear
git --no-pager log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%ci) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative --all
sleep 1
done
commit e560ef1ac4be1fada8efba54e75f9bc70fb5b70a
Author: Denis M. Gabaidulin <gabaden@gmail.com>
Date: Thu Sep 6 22:21:29 2012 +0400
+ exit when no activity
****.cs | 16 +++++++++++++++-
1 files changed, 15 insertions(+), 1 deletions(-)
public class Thunk<T> {
private volatile T value;
private final Provider<T> provider;
public Thunk(Provider<T> provider) {
this.provider = provider;
}
/**
* Data race is possible here: there can be multiple invocations of creator func
ExecutorService s = Executors.newFixedThreadPool(10);
Future<?> f = s.submit(
new Runnable() {
@Override
public void run() {
try {
Context.enter();
// do stuff
} catch (Throwable e) {
} finally {