Instantly share code, notes, and snippets.

Batuhan Bayrakci baybatu

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 / 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
@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 = []
@jonikarppinen
jonikarppinen / Messages.java
Last active Jan 26, 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 Dec 6, 2018
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 / MockitoMocksCollector.md
Last active Dec 5, 2018
MockitoMocksCollector Hakkında
View MockitoMocksCollector.md

MockitoMocksCollector, bir test sınıfı içerisinde örneği oluşturulması halinde o sınıf içerisinde oluşturulan tüm Mock nesneleri (mock() static metodu ile oluşturulanlar dahil) elde edebilmemizi sağlar:

public final class MockitoMocksCollector {

    private final List<Object> createdMocks;

    public MockitoMocksCollector() {
        createdMocks = new LinkedList<Object>();
        MockingProgress mockingProgress = new ThreadSafeMockingProgress();
        mockingProgress.setListener(new CollectCreatedMocks(createdMocks));
@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; //=> []
@ufuk
ufuk / LazyDeveloper.java
Last active Aug 23, 2018
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;