Skip to content

Instantly share code, notes, and snippets.

#include <stdio.h>
int main(int argc, char ** argv){
int a,b;
printf("Program policzy roznice dwoch liczb,podaj pierwsza z nich \n");
scanf("%d \n",&a);
printf("Podaj druga liczbe \n");
scanf("%d \n",&b);
printf("roznica wynosi %d ", a-b);
getchar();
return 0;
@kubek2k
kubek2k / pisanie_do_pliku.c
Created January 5, 2012 22:15
pisanie do pliku
#include <stdio.h>
main() {
FILE * plik; // uchwyt do pliku
char bufor[100]; // zawartosc tego bufora zapiszemy do pliku
plik = fopen("plik_wyjsciowy.txt", "w"); // otwarcie pliku do odczytu
scanf("%99s", bufor); // wczytanie lancucha znakowego do bufora (99 poniewaz musi sie zmiescic jeszcze \0)
fputs(bufor, plik); // zapis do pliku
@kubek2k
kubek2k / czytanie_pliku.c
Created January 5, 2012 22:16
czytanie z pliku
#include <stdio.h>
main() {
int wielkosc_bufora = 100;
char bufor[wielkosc_bufora]; // bufor do ktorego bedziemy czytac dane
FILE * plik; // zmienna zawierajaca uchwyt do pliku
plik = fopen("plik_wejsciowy.txt", "r"); // sciezka do pliku, tryb otwarcia do odczytu
fgets(bufor, wielkosc_bufora - 1, plik); // wczytanie pierwszych 99 bajtow pliku do bufora (PAMIETAJ - (wielkosc bufora - 1) poniewaz musisz zostawic miejsce na \0 w stringu
@kubek2k
kubek2k / quicksort.pl
Created January 26, 2012 12:05
Quicksort in prolog
pivot(_, [], [], []).
pivot(Pivot, [Head|Tail], [Head|LessOrEqualThan], GreaterThan) :- Pivot >= Head, pivot(Pivot, Tail, LessOrEqualThan, GreaterThan).
pivot(Pivot, [Head|Tail], LessOrEqualThan, [Head|GreaterThan]) :- pivot(Pivot, Tail, LessOrEqualThan, GreaterThan).
quicksort([], []).
quicksort([Head|Tail], Sorted) :- pivot(Head, Tail, List1, List2), quicksort(List1, SortedList1), quicksort(List2, SortedList2), append(SortedList1, [Head|SortedList2], Sorted).
@kubek2k
kubek2k / yakuake-functions.sh
Created February 17, 2012 21:49
Functions for yakuake to automatically spawn new terminals
#
# Utility functions to spawn terminals automatically
# @kubek2k 2012
#
# sample usage:
# open_new_session_and_run_command ssh myhost tail -f /log/syslog.log
YAKUAKE_DBUS="qdbus org.kde.yakuake"
function close_session {
@kubek2k
kubek2k / gist:5229457
Created March 23, 2013 21:37
Show git tree everytime we change something (so the screen is not blinking) - its a good way of showing how git is actually working
#!/bin/bash
get_last_change() {
find .git -type f -exec stat -f "%m %N" {} \; | sort -nr | head -1 | awk '{print $1}'
}
while [ true ]; do
LAST_CHANGE=`get_last_change`
clear
GIT_PAGER="cat" git log --format=oneline --abbrev-commit --decorate --graph --all
@kubek2k
kubek2k / sha256.clj
Last active October 23, 2022 19:42
SHA-256 in clojure
(defn sha256 [string]
(let [digest (.digest (MessageDigest/getInstance "SHA-256") (.getBytes string "UTF-8"))]
(apply str (map (partial format "%02x") digest))))
@kubek2k
kubek2k / gist:10114138
Created April 8, 2014 11:56
Dropwizard 0.7.0 CORS configuration
environment.servlets().addFilter("cors-filter", CrossOriginFilter.class)
.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/*");
@kubek2k
kubek2k / gist:10368672
Created April 10, 2014 11:02
Context manager example
class X:
def __enter__(self):
print "entering"
def __exit__(self, exception_type, exception_val, trace):
print "exiting"
def restart():
return X()
@kubek2k
kubek2k / gist:10558929
Created April 12, 2014 21:59
Primes in haskell
module Main where
primes = 1:(nextPrime 2 [])
divisibleByAny x numbers = any (\n -> (rem x n) == 0) numbers
nextPrime start primesSoFar = let
nextP = head (dropWhile (\x -> divisibleByAny x primesSoFar) [start..])
in
nextP:(nextPrime (nextP + 1) (nextP:primesSoFar))