Skip to content

Instantly share code, notes, and snippets.

@qassa
qassa / Csharp if condition
Created October 12, 2018 18:04
short ways
using System;
using System.Collections.Generic;
namespace SharpDelegateSwitch
{
class Program
{
static void Main(string[] args)
{
Dictionary<int, Action> vars = new Dictionary<int, Action>();
@qassa
qassa / go functions
Created September 19, 2018 11:16
Function in Go can return a function
func call(resp *http.Response) func() {
return func() {
if resp != nil {
resp.Body.Close()
}
}
}
func(url string) {
resp, err := http.Get(url)
img {
display: none!important;
}
/*
*::before{
content: ""!important;
}
*::after{
content: ""!important;
}
@qassa
qassa / MotionDetection2Frames.cs
Created January 18, 2018 14:52
Simple difference oriented algorithm for motion detetion in WPF
using System;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Imaging;
private ImageMatrix create_matrix(string file_name)
{
Uri imageUri = new Uri(file_name, UriKind.Relative);
BitmapImage imageBitmap = new BitmapImage(imageUri);
var inventoryGlobal = inventory;
var itemToOffer
@qassa
qassa / isNegative
Created November 14, 2015 18:59
check if float number is negative?
#include <stdlib.h>
#include <stdio.h>
static int isNegative(float arg){
char *p = (char*) malloc(20);
sprintf(p,"%f",arg);
return p[0] == '-';
}
int main(){
@qassa
qassa / JavaScript First Animation
Last active November 4, 2015 09:46
Анимация плавно выезжающего элемента страницы с заданным значением таймера
var element = document.getElementById("im");
var currentPosition = element.offsetTop; //Получаем текущее положение блока, который будет выплывать
smoothAnimation = requestAnimationFrame(function anim(time) {
currentPosition++;
element.style.top = currentPosition +"px";
smoothAnimation = requestAnimationFrame(anim); // The animation would not stop after 1.5 sec if delete smoothAnimation in this line because the fucntion reference changes every time it's called
});
setTimeout(function(){
@qassa
qassa / Assign variable in while-loop conditional
Last active October 20, 2015 14:23
Assigning variable a in while-loop
int a = 0;
while((a=5) != 0 && 5 > 4){
System.out.println("Hello! It's a loop.");
}
@qassa
qassa / Java lerp
Last active May 2, 2017 07:41
lerp realization in Java using interpolation by time. Ability to set determine speed of object when it's moving on the straight line (X,Y) on the scene.
public int lerp(float start, float target, float duration, float timeSinceStart){
float value = start;
if(timeSinceStart>=0.0f && timeSinceStart < duration){
float range = target - start;
float percent =timeSinceStart / duration;
value = start + range * percent;
}
else if(timeSinceStart>=duration)
value = target;
return Math.round(value);
@qassa
qassa / queue
Created November 22, 2013 19:45
Данные queue: MAXSIZ - (константа) максимальное количество элементов в очереди. data - массив данных. top - индекс первого элемента в очереди. Интерфейс queue: push - положить значение value в очередь q. В случае переполнения значение в очередь помещено не будет. pop - извлечь значение из очереди q. back - получить последний элемент из очереди q…
#include <stdio.h>
#include <assert.h>
#define MAXSIZ 10
typedef struct {
int data[MAXSIZ];
int top;
} queue_t;