Skip to content

Instantly share code, notes, and snippets.

View demoth's full-sized avatar
🎯
Refactoring full throttle!

demoth demoth

🎯
Refactoring full throttle!
View GitHub Profile
public interface Differ<T> {
public Object diff(T t1, T t2);
}
Differ<SomeType> differ = getInstance();
SomeType a[];
int N = a.length();
Object delta;
if (N < 2){
public void importDepartments(EntityManager em, EntityManager iem) {
// вывод
List<String> log = new ArrayList<String>();
int foundParents = 0, notFoundDeps = 0, expiredIds = 0;
// ImportMapping по внешнему коду
List<ImportMapping> ims = em.createQuery("from ImportMapping i where i.epoch=:epoch")
.setParameter("epoch", 13).getResultList();
Map<String, ImportMapping> imMap = new HashMap<String, ImportMapping>();
for (ImportMapping i : ims) {
@demoth
demoth / GameEngine.java
Created August 15, 2012 11:23
Nifty control trouble
package org.caster.client;
import com.jme3.app.SimpleApplication;
import com.jme3.asset.plugins.FileLocator;
import com.jme3.niftygui.NiftyJmeDisplay;
import de.lessvoid.nifty.Nifty;
import de.lessvoid.nifty.controls.TextField;
import de.lessvoid.nifty.screen.Screen;
import de.lessvoid.nifty.screen.ScreenController;
import org.json.JSONObject;
@demoth
demoth / exp.qc
Created November 16, 2012 18:09
exp
/*
==============================================================================
EXPERIENCE SYSTEM A - POINTS PER KILL
==============================================================================
*/
float XP_ARMY = 5;
float XP_ENFORCER = 10;
# параметр сглаживания
a = 1/100
# аппроксимация модуля
ma = (a + x^2)^(1/2)
# выражение максимума через модуль
var('xm1 xm2')
xmax=1/2*(ma(xm1-xm2) + xm1 + xm2)
var_names = 'x1 x2 x3 x4'
args = var(var_names)
@demoth
demoth / mag7.sage
Created June 5, 2013 13:28
7 версия
# -*- coding: utf-8 -*-
'''
Оптимизация рейтинга факультета
Даниил Бубнов 10.03.2013
ОПТИМИЗАЦИЯ РЕЙТИНГА С АППРОКСИМАЦИЕЙ МОДУЛЯ
'''
##################################################################
# Читаем данные из файла
import csv
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
JDK_HOME=/usr/lib/jvm/jdk1.7.0_09
# If not running interactively, don't do anything
[ -z "$PS1" ] && return
# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options
HISTCONTROL=ignoreboth
class Finder {
/**
* Simple Binary search implementation.
* Author: Daniil
* @param arr - list to search in
* @param el - element to find
* @return index of the found element, or -1 if there is no such element in
* <code>arr</code> or of <code>arr</code> is empty or <code>null</code>
*/
static int binarySearch(List arr, int el) {
@demoth
demoth / messagesLookup.groovy
Last active December 23, 2015 17:39
groovy script to look for all i18n files in all jar archives in some directory
import java.util.zip.ZipFile
import static groovy.io.FileType.*
new File('/home/daniil/bundles').eachFileMatch(FILES, ~/.*.jar/ , { f ->
new ZipFile(f).entries().each{
if (it.toString().matches('.*messages_.*properties'))
println ' ' + f + '!/' + it
}
})
@demoth
demoth / pascal.groovy
Created September 23, 2013 17:21
pascal triangle and recursive pascal function done in groovy
def pascal(col, row) {
assert col >= 0 && row >= 0 && col <= row
if (col == 0 || row == 1 || col == row)
return 1
return pascal(col - 1, row - 1) + pascal(col, row - 1)
}
def triangle(rows) {
assert rows >= 0
(0..rows).each { row ->