Skip to content

Instantly share code, notes, and snippets.

View m1kc's full-sized avatar

Max Musatov m1kc

View GitHub Profile
// не моё
function plural_str(i, str1, str2, str3) {
if (i % 10 === 1 && i % 100 !== 11) return str1;
if (i % 10 >= 2 && i % 10 <= 4 && (i % 100 < 10 || i % 100 >= 20)) return str2;
return str3;
}
@m1kc
m1kc / request.coffee
Last active August 29, 2015 14:03
Посвящается тем говноедам, которые не любят CoffeeScript.
request = require 'request'
rand = Math.floor(Math.random()*100000000).toString()
request(
method: 'PUT'
uri: 'http://mikeal.iriscouch.com/testjs/' + rand
multipart: [
'content-type': 'application/json'
'body': JSON.stringify(
foo: 'bar'
Function.prototype.arrowise = function(){
// удаляем комментарии, выделяем префикс "function...", аргументы и тело
var parsed = this.toString()
.replace(/\/\*[\s\S]*?\*\/|\/\/.*$/mg, '')
.match(/(function.*?)\((.*?)\)\s*\{([\s\S]*)\}.*/);
var prefix = parsed[1], args = parsed[2], code = parsed[3];
// если аргументы есть, добавляется запятая перед аргументом __cb
if(!/^\s*$/.test(args)) args += ',';

TODO: нужен опыт

TODO: недостатки

TODO: порядок сборки для тупых

Набросок: ВР - самый жёсткий из мидовых agility carry для поздней игры

{
"node": true,
"undef": true,
"bitwise": true,
"latedef": true,
"trailing": true,
"maxlen": 120
}
function getURLParameter(name) {
return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search)||[,""])[1].replace(/\+/g, '%20'))||null;
}
travis_retry() {
local result=0
local count=3
while [ $count -gt 0 ]; do
"$@"
result=$?
[[ "$result" == "0" ]] && break
count=$(($count - 1))
echo "Command ($@) failed. Retrying: $((3 - $count))" >&2
sleep 1

Code written by a CS 101 student

public int fibonacci(int x) {
	if (x == 1) {
		return 1;
	} else if (x == 2) {
		return 1;
	} else {
		return fibonacci(x - 1) + fibonacci(x - 2);
@m1kc
m1kc / setLookAndFeel.java
Created August 9, 2012 20:10
setLookAndFeel()
private static void setLookAndFeel()
{
// Well, let's try to set Nimbus explicitly first.
try
{
UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
System.out.println("LaF: com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
return; // success
}
catch(Throwable ex)
@m1kc
m1kc / create-micro-service.go
Created November 2, 2016 08:37
If your go-micro options just don't seem to work, try this approach.
import (
"time"
"github.com/micro/go-micro"
_ "github.com/micro/go-micro/broker"
"github.com/micro/go-micro/server"
brokerNats "github.com/micro/go-plugins/broker/nats"
transportNats "github.com/micro/go-plugins/transport/nats"
)