Skip to content

Instantly share code, notes, and snippets.

View Peters8090's full-sized avatar

Piotr Bartoszewski Peters8090

  • GP Solutions
  • Warsaw, Poland
View GitHub Profile
def squareFromNumbers(n):
return list(map(lambda x: [n] * n, ([n] * n)))
print(squareFromNumbers(5))
def multipleArray(num, length):
return list(map(lambda x: int(x[1]) ** (x[0] + 1), enumerate(str(num) * length)))
print(multipleArray(5, 3))
@Peters8090
Peters8090 / sqrt.ts
Created December 2, 2020 13:12
A function counting the square root of a number with the given precision.
const sqrt = (a: number, precision = 3) => {
let cur: number = a / 2;
while (true) {
if ((cur ** 2).toFixed(precision) === a.toFixed(precision)) {
return cur.toFixed(precision);
}
const step = 10 ** (-1 * (precision + 1));
if (cur ** 2 > a) {
cur -= cur * step;
package programowanie_komputerowe;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Hashtable;
import java.util.List;
public class BinSearch {
public static void main(String[] args)
{
@Peters8090
Peters8090 / LoadingPage.js
Created June 6, 2020 21:14
[React, Material UI] - Loading page with a fancy spinner
import React from 'react';
import useTheme from '@material-ui/core/styles/useTheme';
import useMediaQuery from '@material-ui/core/useMediaQuery';
import {CircularProgress} from '@material-ui/core';
/** @jsx jsx */
import {jsx, css} from '@emotion/core';
export const LoadingPage = () => {
const styles = {
root: css`
@Peters8090
Peters8090 / views.py
Last active June 6, 2020 21:14
[Django 3.0.5] - i18n JSONCatalog with domain list and tuple support
# Example of use in urls.py:
# from django.urls import path
# from .views import
# from .views import JSONCatalogWithDomainListTupleSupport
# urlpatterns = [
# path('i18n/', views.JSONCatalogWithDomainListTupleSupport.as_view(domain=['django', 'djangojs'])),
# ]
@Peters8090
Peters8090 / ArraysAndLoops.java
Created November 11, 2019 16:29
[Computer programming homework] Write a program, in which we create an array of integers of length 10, which is initialized with any numbers from 1 to 100. The program has to print that array and the sum of all its elements.
import java.util.Random;
public class ArraysAndLoops {
public static void main(String[] args) {
int[] array = new int[10];
int arraySum = 0;
System.out.println("Array: ");
for(int i = 0; i < array.length; i++)
{
array[i] = new Random().nextInt(100);
@Peters8090
Peters8090 / SimpleCalculator.java
Last active October 5, 2019 15:06
[Computer programming homework] Java introduction: Write a program that simulates calculator operations. Create variables number1 and number 2. Create variables summing [dodawanie], subtraction [odejmowanie] etc. Assign the results of specific mathematical operations to variables summing [dodawanie], subtraction [odejmowanie], etc.
package programowanie_komputerowe;
public class SimpleCalculator {
//liczby na ktorych beda wykonywane dzialania
static double liczba1 = Math.random();
static double liczba2 = Math.random();
//wyniki dzialan na liczbach 1 i 2
static double dodawanie = liczba1 + liczba2;
@Peters8090
Peters8090 / NumbersSumming.cs
Created September 21, 2019 21:30
[Computer programming homework] This script is written in C# and can be easily executed in Unity. Algorithm asks you to input two numbers and tells you then the sum of them.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using System.Linq;
using UnityEditor;
using System.Reflection;
public class NumbersSumming : MonoBehaviour
{
@Peters8090
Peters8090 / NumbersComparing.cs
Last active September 21, 2019 21:28
[Computer programming homework] This script is written in C# and can be easily executed in Unity. Algorithm asks you to input two numbers, which can't be equal and tells you then which one is bigger.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using System.Linq;
using UnityEditor;
using System.Reflection;
public class NumbersComparing : MonoBehaviour
{