Skip to content

Instantly share code, notes, and snippets.

View lovasoa's full-sized avatar
🎯
Focusing

Ophir LOJKINE lovasoa

🎯
Focusing
View GitHub Profile
package com.qwant.debouncer;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
-- Employees and departments
CREATE TABLE EMPLOYEES(ID INTEGER, NAME VARCHAR, CHIEF_ID INTEGER, SALARY INTEGER, DEPARTMENT_ID INTEGER);
CREATE TABLE DEPARTMENTS(ID INTEGER, NAME VARCHAR);
INSERT INTO DEPARTMENTS VALUES (1, "DEP 1"), (2, "DEP 2"), (3, "DEP 3");
INSERT INTO EMPLOYEES VALUES
(1,"Աշոտ",2,3000,1),
(2,"Ophir",NULL,2500,1),
(3,"Армен",1,4000,2);
#include <iostream>
using namespace std;
bool in(int x, int y, int x1, int x2, int y1, int y2){
return x1<=x && x<=x2
&& y1<=y && y<=y2;
}
int main()
{
@lovasoa
lovasoa / base2_add.cpp
Created April 18, 2018 15:05
Read and write numbers in base 2
#include<iostream>
using namespace std;
unsigned int read_base2() {
int n=0; char c;
for(cin.get(c); c=='0'||c=='1'; cin.get(c)) n = (n<<1)|(c-'0');
return n;
}
void write_base2(unsigned int n, bool first=true) {
@lovasoa
lovasoa / myxa.cpp
Last active April 17, 2018 08:11
МУХА + МУХА = СЛОН
#include<iostream>
using namespace std;
// муха + муха = слон
int main() {
// Числа не могут начитаться с нуля.
// Поэтому муха >= 1000
// и слон = 2*муха содержит 4 числа, поэтому
// 2*муха <= 9999
// муха <= 4999
@lovasoa
lovasoa / 3388.hs
Last active April 12, 2018 11:58
Soit la liste de nombres [3,8,3,8]. En utilisant tous les nombres de cette, liste, uniquement ces nombres, et les opérations mathématiques usuelles (addition, multiplication, division, soustraction), trouver une manière d'obtenir le nombre 24
import Data.List
import Control.Monad
data Operation = Plus | Minus | Mul | Div deriving (Eq,Ord)
data Tree = Compute Operation Tree Tree | Leaf Rational deriving (Eq,Ord)
instance Show Tree where
show (Compute op a b) = "(" ++ (show a) ++ (show op) ++ (show b) ++")"
show (Leaf x) = show (fromRational x)
#include<iostream>
using namespace std;
bool is_mirror(int n) {
if (n<=0) return true;
int n1, n2;
cin >> n1;
if (n==1) return true;
bool inner_mirror = is_mirror(n-2);
@lovasoa
lovasoa / move_left.c
Last active March 31, 2018 13:17
Move an array to the left by n positions without allocating more memory
#include <stdio.h>
void swap(int *a, int *b) {
int tmp = *a; *a = *b; *b = tmp;
}
void move_left(int a[], size_t size, int n) {
n = ((n % (int)size) + size) % size;
size_t remaining_size = size;
for(size_t i=0; i<size-1; i++) {
@lovasoa
lovasoa / LogisticMap.ipynb
Created February 17, 2018 17:32
Logistic Map with numpy and matplotlib
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@lovasoa
lovasoa / VectorMean.scala
Created February 15, 2018 13:43
spark UDAF for computing the mean of vectors
import org.apache.spark.ml.linalg.SQLDataTypes.VectorType
import org.apache.spark.ml.linalg.{Vector, Vectors}
import org.apache.spark.sql.Row
import org.apache.spark.sql.expressions.{MutableAggregationBuffer, UserDefinedAggregateFunction}
import org.apache.spark.sql.types._
class VectorMean extends UserDefinedAggregateFunction {
// This is the input fields for your aggregate function.