Skip to content

Instantly share code, notes, and snippets.

View OlegIlyenko's full-sized avatar

ΘLΞG OlegIlyenko

View GitHub Profile
@OlegIlyenko
OlegIlyenko / table-helper.js
Created September 24, 2013 14:25
Highlights rows and cells as well as sums clicked cells
var src = 'https:' == location.protocol ? 'https':'http', script = document.createElement('script');
script.src = src+'://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js';
script.onload = function () {
var $ = jQuery;
var elem = $('<div>').text("0").css({position: 'fixed', top: 0, left: 0, width: 250, height: 40, backgroundColor: '#006699', borderBottomRightRadius: 7, color: 'white', padding: 9, fontWeight: 'bold', fontSize: '30px', boxShadow: "0 0px 20px 2px black"}).appendTo(document.body);
var sum = 0;
var count = 0;
$("table td").click(function () {
var cell = $(this);
@OlegIlyenko
OlegIlyenko / same_xml.rb
Created August 14, 2013 20:19
Ruby script that checks whether 2 XML files are structurally same
#!/usr/bin/env ruby
require 'nokogiri'
require 'equivalent-xml'
xml = ARGV.map {|file_name| File.open(file_name) {|f| Nokogiri::XML(f)}}
print "Same: ", EquivalentXml.equivalent?(xml[0], xml[1])
import scaldi.{Injectable, Module, Injector}
class UserService
class UserController(implicit inj: Injector) extends Injectable {
val userService = inject [UserService]
}
class OrderService(implicit inj: Injector) extends Injectable {
val userService = inject [UserService]
@OlegIlyenko
OlegIlyenko / SecureModule.scala
Created May 17, 2013 20:39
Fixed version of SecureModule
import scaldi.{Injector, Module, Injectable}
trait Security {
type User
def authenticate(username: String, password: String): Boolean
}
class SecuritySample extends Security {
def authenticate(username: String, password: String): Boolean = false
@OlegIlyenko
OlegIlyenko / gist:4235329
Created December 7, 2012 18:33
Type classes
package org.am.incident
object Test extends App {
def ??? = throw new IllegalStateException()
trait Conv[A, B] {
def conv(a: A): B
}
package scaldi.keys
import math._
import swing._
import java.io.{Closeable, InputStream, FilterInputStream}
import javax.swing.UIManager
import java.net.URL
object Downloader extends SimpleSwingApplication {
import javax.swing.UIManager
import java.net.URL
import java.awt.Dimension
import java.io.Closeable
import swing._
object Downloader extends SimpleSwingApplication {
UIManager.getInstalledLookAndFeels
.filter(_.getName contains "Nimbus").headOption
import math._
case class Progress(percent: Int, size: Long, remains: Long, done: Long, bps: Long, elapsed: Long, estimated: Long) {
lazy val formattedMetrics= List(
"Progress: " + percent + "%",
"File size: " + formatSize(size),
"Downloaded: " + formatSize(done),
"Remains: " + formatSize(remains),
"Speed: " + (bps / 1024) + " kb/s",
"Elapsed: " + formatTime(elapsed),
import math._
class ProgressListener(availableBytes: Long, tracker: Progress => Unit) extends Function1[Long, Unit] {
var transfered: Long = 0
val startTime = System.currentTimeMillis
def apply(bytesTransfered: Long) {
transfered += bytesTransfered
val elapsed = System.currentTimeMillis - startTime
val bpms = (transfered / max(elapsed, 1000)).toLong
import java.io.{FilterInputStream, InputStream}
class ProgressInputStream(in: InputStream, listener: Long => Unit) extends FilterInputStream(in) {
val NotificationThreshold = 8 * 1024;
var unnotifiedByteCount = 0
override def read() = {
val data = super.read()
if (data != -1) notify(1)