Skip to content

Instantly share code, notes, and snippets.

@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))
var http = require('http');
module['exports'] = function echoHttp (hook) {
hook.debug("Debug messages are sent to the debug console");
hook.debug(hook.params);
@kubek2k
kubek2k / MapMatcher.java
Created May 25, 2015 08:21
Handy hamcrest map matcher
public static class MapMatcher<K, V> extends TypeSafeMatcher<Map<K, V>> {
private final Map<K, V> desiredContents = new HashMap<>();
@Override
protected boolean matchesSafely(final Map<K, V> item) {
for(final Map.Entry<K, V> kvEntry : this.desiredContents.entrySet()) {
if (!kvEntry.getValue().equals(item.get(kvEntry.getKey()))) {
return false;
}
#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 / 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 / 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 / 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 / get_all_repos_urls.sh
Last active October 20, 2015 10:04
Get all repositories for a given organization in GH or GHE
#!/bin/bash
curl -u $GITHUB_USER:$GITHUB_TOKEN https://$GITHUB_HOST/api/v3/users/$GITHUB_ORG/repos?per_page=1000 | json -a 'ssh_url'