Skip to content

Instantly share code, notes, and snippets.

View baybatu's full-sized avatar
🏠
Working from home

Batuhan Bayrakci baybatu

🏠
Working from home
View GitHub Profile
@rednaxelafx
rednaxelafx / demo.groovy
Created April 6, 2011 08:51
get properties from an object in Groovy, even when the object has an getProperties() method
def getPropertiesFrom(obj) {
obj.metaClass.properties.findAll { it.name != 'class' && it.name != 'metaClass' }.inject([:]) { acc, e -> acc[e.name] = e.getProperty(obj); acc }
}
class Foo {
int getBar() { 42; }
List getProperties() { [] }
}
def foo = new Foo();
foo.properties; //=> []
@jlong
jlong / uri.js
Created April 20, 2012 13:29
URI Parsing with Javascript
var parser = document.createElement('a');
parser.href = "http://example.com:3000/pathname/?search=test#hash";
parser.protocol; // => "http:"
parser.hostname; // => "example.com"
parser.port; // => "3000"
parser.pathname; // => "/pathname/"
parser.search; // => "?search=test"
parser.hash; // => "#hash"
parser.host; // => "example.com:3000"
import re
import csv
import urllib
class Parse:
params = re.compile('(?P<key>[\S]*)=\{(?P<value>[\S]*)\}')
prep = re.compile('(?P<key>[\S]*)=(?P<value>[\S]*)')
@ufuk
ufuk / BaseMockitoTest.java
Last active April 9, 2019 20:30
Performs "verify no more interactions" check automatically for all mock objects (works with Mockito version 2). For detailed description: https://ufukuzun.wordpress.com/2019/04/09/ne-olup-bittiginden-habersiz-testlere-derman-mockscollector/ (Turkish)
import org.apache.commons.lang3.ArrayUtils;
import org.junit.After;
import org.junit.runner.RunWith;
import org.mockito.InOrder;
import org.mockito.runners.MockitoJUnitRunner;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.verifyNoMoreInteractions;
@RunWith(MockitoJUnitRunner.class)
@joemiller
joemiller / clone-all.sh
Last active December 28, 2020 18:02
clone all repos from an org, including private repos
#!/bin/sh
# Reqs: curl, ruby, git
#
# TOKEN: Create a personal access token here: https://github.com/settings/tokens
#
# Usage:
#
# To clone all repos from $ORG into current directory:
#
# $ curl https://gist.githubusercontent.com/joemiller/2dd72670e37769cb647c/raw | TOKEN=<githubtoken> ORG=<orgname> bash
@jonikarppinen
jonikarppinen / Messages.java
Last active February 23, 2021 23:36
Example of using message resources in Spring Boot service layer code, in as simple way as possible (hopefully!). NOTE: this approach supports only a single locale, not dynamically changing it.
package com.company.project.components;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.context.support.MessageSourceAccessor;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import java.util.Locale;
@ufuk
ufuk / HowToGetHttpServletRequestAndResponseProgrammatically.java
Created October 6, 2016 11:31
To get the request and response objects in Spring MVC projects you can use this code
ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes();
HttpServletRequest httpServletRequest = servletRequestAttributes.getRequest();
HttpServletResponse httpServletResponse = servletRequestAttributes.getResponse();
@ufuk
ufuk / LazyDeveloper.java
Last active June 27, 2019 13:04
Just another reason to why you shouldn't use Lombok, in another saying another reason to why you should write unit tests: You have two fields in your class. Fields are in the same type. You use @AllArgsConstructor to auto-generate your all args constructor. It works for a moment, until you change the order of the field.
import lombok.AllArgsConstructor;
import lombok.Data;
@Data
@AllArgsConstructor
public class LazyDeveloper {
private String firstName;
private String lastName;
@ufuk
ufuk / StartEndTimeWithJodaTime.java
Created October 24, 2016 09:09
Joda-Time library provides us a Virtual Clock utility named "DateTimeUtils". This is a demonstration for mocking start-end times.
import org.joda.time.DateTime;
public class StartEndTimeWithJodaTime {
private DateTime startTime;
private DateTime endTime;
public void process() {
startTime = DateTime.now();
@livacengiz
livacengiz / detail.md
Last active July 30, 2018 07:59
Otomat Hackathon Detaylar

alt text

Nedir?

Creative coding (yaratıcı programlama) işlevsel olmasından çok yaratıcılığı ön plana çıkarmak için bilgisayar programları yazma işine verilen isimdir. Ortaya çıkan sonuçlar işitsel, görsel ya da başka herhangi bir formda olabilir.

Otomat, sürekli CRUD uygulamalar yapmaktan sıkılmış geliştiriciler olarak birlikte çok ilginç projeler geliştireceğimiz bir hackathon/creative coding partisi. 19-20 Kasım tarihlerinde (gece dahil) bir araya gelerek çok güzel görsel/işitsel ürünler üretip, çok güzel sohbetler edeceğiz.

Neler yapacağız?

Ne yapmak istiyorsanız! Yapılacak şey ve konu üzerine herhangi bir sınırlandırmamız yok. Ama etkinlik günü söyleyeceğimiz bazı teknik sınırlandırmalarımız olacak :) Bireysel olarak ya da grup olarak katılımak konusunda serbestsiniz. Hatta en güzeli herkesle yardımlaşmanız :)