Skip to content

Instantly share code, notes, and snippets.

try (var distLock = distributedLockProvider.lock("some-key", 3000, 10000)) {
if (distLock.isEmpty())
return;
log.info("I'm running...");
} catch (Exception e) {
}
@Configuration
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class ShedlockMongoConfiguration {
private final MongoFactory mongoFactory;
private final MongoReplicaSetFactory mongoReplicaSetFactory;
@Value("${sahibinden.mongodb.dbs.sahibinden.replicaSetName}")
private String mongoReplicaSetName;
public interface DistributedLockProvider {
DistLock lock(String key, int lockAtLeastFor, int lockAtMostFor);
}
@Service
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@Slf4j
public class DistributedLockProviderImpl implements DistributedLockProvider {
private final LockProvider lockProvider;
@Override
public DistLock lock(String key, int lockAtLeastFor, int lockAtMostFor) {
var lockConfiguration = new LockConfiguration(Instant.now(), key,
@egcodes
egcodes / Banner.go
Last active February 15, 2018 17:32
package main
import (
"fmt"
"os"
"strconv"
"strings"
)
func main() {
package egcodes;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
/**
* @author egcodes
*/
@egcodes
egcodes / ReadFileUsingBit.py
Created October 6, 2014 10:38
Read file using bit
import array
class ReadFileUsingBit:
def __init__(self):
fileName = "file.txt"
buffer = ""
for b in self.readBitByBit(open(fileName, 'r')):
buffer += str(b)
@egcodes
egcodes / gist:dfcf310c4719a8c08b52
Created September 25, 2014 18:35
allIndexDownload.py
import urllib2
for a in range(1, 256):
for b in range(1, 256):
for c in range(1, 256):
for d in range(1, 256):
ip = "%d.%d.%d.%d"%(a,b,c,d)
buf = ""
print ip
@egcodes
egcodes / autoSetBacklight.py
Created July 29, 2014 19:44
Automatic backlight control for ubuntu
import os, time
import pyscreenshot as ImageGrab
while True:
screen = ImageGrab.grab()
dark = 0
bright = 0
for i in screen.getdata():
if i[0] > 150 and i[1] > 150 and i[2] > 150:
@egcodes
egcodes / getTrHackedSites.py
Last active December 29, 2015 14:09
get hacked tr(turkish) pages from zone-h.org
from BeautifulSoup import BeautifulSoup
import urllib2
from datetime import datetime
import time,os
pageNo = 1
while pageNo < 10:
print "PageNo: %d"%pageNo
page = urllib2.urlopen("http://www.zone-h.org/archive/page=%d"%pageNo, timeout=10).read()
soup = BeautifulSoup(page)