Skip to content

Instantly share code, notes, and snippets.

@ViliusKraujutis
ViliusKraujutis / lampHolder.scad
Created September 1, 2017 21:08
A holder for table lamp to fit on the corner of IKEA table
$fn=60;
holeH=37;
holeD=12.5;
h=40;
module lampHolder() {
difference() {
holderBody();
tableSpace();
@ViliusKraujutis
ViliusKraujutis / MainActivity.java
Created August 16, 2017 06:28
Use RxJava to detect changes
package lt.andro.learnrxjava;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.Editable;
import android.text.TextUtils;
import android.widget.RadioGroup;
import android.widget.TextView;
import com.jakewharton.rxbinding2.InitialValueObservable;
@ViliusKraujutis
ViliusKraujutis / printer lamp handle.scad
Created August 4, 2017 05:24
Čia rankenėlė tai lemputei šalia spausdintuvo. Padariau kad viduje būtų apytuščia, su susiaurėjimais galuose; skylutes jungikliui ir magnetukui; taip pat padariau pussferės ir kūbiuko išėmimą lemputės galiukui.
$fn=60;
module lampHandle() {
difference() {
cylinder(d=35, h = 100);
translate([0,0,84]){
bulbSpace();
}
holoInside();
buttonHole();
@ViliusKraujutis
ViliusKraujutis / belt tensioner back
Created July 31, 2017 17:22
Anet A8 Y axis belt tensioner
$fn=20;
module holder () {
difference() {
// create rounded corners cube
rcube([20, 30, 20]);
// make a hole for the screw
translate([10, 10, 0])
screwHole();
@ViliusKraujutis
ViliusKraujutis / compass.txt
Created May 28, 2017 13:47
Compass app for micro:bit which shows where's the NORTH. App reads compassHeading value and uses it to determine which LED to turn on. All 360 degrees are divided by 12 (ie. 30 degrees). 12 LEDs around the LED matrix are used to show the NORTH.
let Angle = 0
basic.forever(() => {
Angle = input.compassHeading()
if (345 < Angle || Angle < 15) {
basic.showLeds(`
. . # . .
. . . . .
. . . . .
. . . . .
. . . . .
@ViliusKraujutis
ViliusKraujutis / air-sensor.ino
Created March 28, 2017 13:02
Air Sensor Arduino based air quality sensor Sensors used: DHT22 - temperature and humidity sensor MQ-2 - gas leakage detector. It is suitable for detecting H2, LPG, CH4, CO, Alcohol, Smoke or Propane MQ-3 - alcohol sensor is suitable for detecting alcohol concentration on your breath, just like your common breathalyzer. It has a high sensitivity…
/*
Air Sensor
Arduino based air quality sensor
Sensors used:
DHT22 - temperature and humidity sensor
MQ-2 - gas leakage detector. It is suitable for detecting H2, LPG, CH4, CO, Alcohol, Smoke or Propane
MQ-3 - alcohol sensor is suitable for detecting alcohol concentration on your breath, just like your common breathalyzer. It has a high sensitivity and fast response time
MQ-7 - Carbon Monoxide (CO) sensor
@ViliusKraujutis
ViliusKraujutis / BuildingRetrofit.java
Created October 4, 2016 15:26
Two different custom value enum serialization
...
Gson gson = new GsonBuilder()
.registerTypeAdapter(NumberOfPeople.class, NumberOfPeople.getDeserializer())
.create();
return new Retrofit.Builder()
...
.addConverterFactory(GsonConverterFactory.create(gson))
.client(client)
.build();
@ViliusKraujutis
ViliusKraujutis / Timelapse_servo
Created May 7, 2016 23:07
Arduino Nano + 9V battery + M-1503 Servo = panoramic timelapse rotator-phone holder.
#include <Servo.h>
float TIMELAPSE_SPEED = 5; // N:1
long COOLDOWN = 2000 * TIMELAPSE_SPEED;
long CYCLE = 20000 * TIMELAPSE_SPEED;
long ANGLE_MIN = 45;
long ANGLE_MAX = 135;
long angleRange = ANGLE_MAX - ANGLE_MIN;
@ViliusKraujutis
ViliusKraujutis / PIR sensor for LED lighting
Created May 2, 2016 15:06
Attached PIR sensor to Arduino, so it could adjust power 12V ~18W LED lamp sticker-strip under kitchen's cupboards. Just a simple, although interesting project combining electronics, automation and programming.
int relayPin = 3;
int pirPin = 2;
int ledPin = 13; // just a LED on Arduino board. Not that huge ~18W LED lamp.
long lastDetection = 0; // millis
long DELAY = 3 * 1000; // N seconds (also adjustable at PIR sensor too)
void setup() {
pinMode(relayPin, OUTPUT);
pinMode(pirPin, INPUT);
@ViliusKraujutis
ViliusKraujutis / Solution.java
Last active April 22, 2016 19:20
Codility solution https://codility.com/demo/results/demoGYMPA6-Q73/ Take your own here: https://codility.com/demo/take-sample-test/ This is a demo task. You can read about this task and its solutions in this blog post: http://dev.tasubo.com/2012/09/tips-for-tasks-on-codility.html
class Solution {
public int solution(int[] A) {
long left = 0;
long right = 0;
long sum = sum(A);
for (int i = 0; i < A.length; i++) {
right = sum - left - A[i];
if (left == right)