Skip to content

Instantly share code, notes, and snippets.

Batuhan Bayrakci baybatu

Block or report user

Report or block baybatu

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@jlong
jlong / uri.js
Created Apr 20, 2012
URI Parsing with Javascript
View uri.js
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"
@ufuk
ufuk / LazyDeveloper.java
Last active Jun 27, 2019
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.
View LazyDeveloper.java
import lombok.AllArgsConstructor;
import lombok.Data;
@Data
@AllArgsConstructor
public class LazyDeveloper {
private String firstName;
private String lastName;
@jonikarppinen
jonikarppinen / Messages.java
Last active May 11, 2019
Example of using message resources in Spring Boot service layer code, in as simple way as possible (hopefully!)
View Messages.java
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;
@joemiller
joemiller / clone-all.sh
Last active May 6, 2019
clone all repos from an org, including private repos
View clone-all.sh
#!/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
@ufuk
ufuk / BaseMockitoTest.java
Last active Apr 9, 2019
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)
View BaseMockitoTest.java
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)
@dettmering
dettmering / ping.1m.py
Created Jan 30, 2019
BitBar plugin for showing host availability
View ping.1m.py
#!/usr/local/bin/python3
import os
hosts = [
'google.com',
'microsoft.com'
]
header = []
@ufuk
ufuk / import-csv-file-from-s3-into-aws-redshift.sql
Created Jan 31, 2019
Import CSV file from S3 into AWS Redshift
View import-csv-file-from-s3-into-aws-redshift.sql
-- Before importing, you need to create table
CREATE TABLE example_table
(
...
);
-- Importing...
COPY example_table
FROM 's3://<BUCKET_NAME>/.../example_table.csv'
CREDENTIALS 'aws_access_key_id=...;aws_secret_access_key=...'
@ufuk
ufuk / bash-echo-time-by-timezone.sh
Created Jan 31, 2019
Echo time by timezone in BASH
View bash-echo-time-by-timezone.sh
echo "$(TZ='Europe/Moscow' date +%Y-%m-%d\ %H\:%M)"
# output => 2019-01-31 16:52
@ufuk
ufuk / ApplicationContextHolder.java
Last active Nov 27, 2018 — forked from baybatu/getting-spring-bean-from-unmanaged-area.java
Utility bean for getting Spring beans from static context.
View ApplicationContextHolder.java
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
@Component
public class ApplicationContextHolder implements ApplicationContextAware {
private static ApplicationContext applicationContext;
@rednaxelafx
rednaxelafx / demo.groovy
Created Apr 6, 2011
get properties from an object in Groovy, even when the object has an getProperties() method
View demo.groovy
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; //=> []
You can’t perform that action at this time.