This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
You have given n numbers from 1 to n. You have to sort numbers with increasing number of set bits. | |
Example: n = 5 => Output: 1,2,4,3,5 | |
*/ | |
def numberOfBitsSet(i: Int) = { | |
// http://en.wikipedia.org/wiki/Hamming_weight implementation | |
val j = i - ((i >> 1) & 0x55555555); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
filename = "dict.csv" | |
lookup = {} | |
with open(filename,"r") as file: | |
for line in file: | |
(key, value) = line.split(" ")[0:2] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
import sys | |
dict = { | |
0: "часов", | |
1: "час", | |
2: "часа", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
implicit val bdStringView = StringView.of[BigDecimal] as { _.toString } | |
def makeStringValue[T](implicit sv: StringView[T]) = new StringValue { | |
def getString(value: AnyRef) = sv(value.asInstanceOf[T]) | |
} | |
bdStringValue = makeStringValue[BigDecimal] | |
strStringValue = makeStringValue[String] | |
qtyStringValue = makeStringValue[Long](StringView.of[Long] as { _.toString } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* dirwatcher.scala | |
* | |
* Uses the Java 7 WatchEvent filesystem API from within Scala. | |
* Adapted from: | |
* http://download.oracle.com/javase/tutorial/essential/io/examples/WatchDir.java | |
* | |
* @author Chris Eberle <[email protected]> | |
* @version 0.1 | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// project/Build.scala | |
import sbt._ | |
import Keys._ | |
import AndroidKeys._ | |
object General { | |
val settings = Defaults.defaultSettings ++ Seq( | |
scalaVersion := "2.9.2" | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE OR REPLACE TRIGGER UPD_INF AFTER | |
UPDATE OF SALARY ON hr.employees FOR EACH ROW | |
DECLARE | |
dif NUMBER; | |
str VARCHAR2(3000); | |
e hr.employees%ROWTYPE; | |
BEGIN | |
dif := TRUNC((TRUNC(sysdate) - TRUNC(e.hire_date))/365,0); | |
e := :old; | |
str := 'Номер сотрудника:' || e.employee_id || |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "stdafx.h" | |
#include <iostream> | |
#include <fstream> | |
#include <string> | |
using namespace std; | |
void readFromFile() { | |
string line; | |
ifstream myfile ("tolstoy.txt"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private def upsert(filename: String, extension: String, is: InputStream) { | |
gridfs.findOne(filename) match { | |
case Some(_) => println(filename + " is already in database") | |
case None => | |
gridfs(is) { | |
file => | |
file.filename = filename | |
file.contentType = "image/" + extension | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.github.omnomnom | |
import java.util.concurrent.Semaphore | |
import concurrent.Lock | |
object SleepingBarber extends App { | |
val NCustomers = 12 | |
val NChairs = 5 | |
val CutTime = 10 | |
val VisitInterval = 5 |