function returnTrue() {
    return true;
}
By Anonymous, 2019-12-19 19:41:56
public class MetricsChecker
{
    protected const string AwaitingRecognitionCountMetricName = "AwaitingRecognitionCount";
    protected const string AwaitingExportCountMetricName = "AwaitingExportCount";
    protected const string NotYetDownloadedEventCountMetricName = "NotYetDownloadedEventCount";
    
    ...
    
    public virtual void PublishNotYetDownloadedEventCounts()
    {
        this.logger.Trace($"Starting to gather and publish {NotYetDownloadedEventCountMetricName}(s).");
        ...
    }
    
    ...
}
By Senior developer with 30 rear experience, 2019-12-13 16:22:28
j =0
import random
import hashlib
#geetting inputs
c = input("data  ")
n= int(input("N(the count of last numbers)=  "))
v= input(str(n)+" last char  ")
#list of alphas
l1 = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'v', 'w', 'x', 'y', 'z', 'u']
l2 = ["A", 'B', 'C', 'D', 'E', 'F','G' , 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'V', 'W', 'X', 'Y', 'Z', 'U']
alphas= 0
#calc the count of alppphas
x=""
for j in c:
    if(j in l1 or j in l2):
        alphas +=1
#positions
h = 2**alphas
hs = []
cc =0
j=0
xf =0
# the stat of main coode
for j in range(h):
    #making a sring with 1 and 0
    while True:
        x=""
        for i in range(len(c)):
            x+=str(random.randint(0,1))
        if(not(x in hs)):
            hs.append(x)
            break
    Xx =""
    cc =0
    #convert that to lower and upper
    for j1 in x:
        if(j1=="0"):
            Xx+=c[cc].lower()
        else:
            Xx+=c[cc].upper()
        cc+=1
    #hash
    m = hashlib.sha256()
    m.update(Xx.encode('utf-8'))
    h = m.hexdigest()
    #if
    if(h[0-n:]==v):
        print("text :"+Xx)
        print("hash :"+h)
        xf = True
        break
    if xf==True:
        break
j =0
#if that not possible to have git push -Desirable-hash by changed lower to upper and upper to lower
if(xf==0):
    while 1:
        j+=1
        d = c+str(j)
        m = hashlib.sha256()
        m.update(d.encode('utf-8'))
        h = m.hexdigest()
        if(h[0-n:]==v):
            print("text :"+d)
            print("hash :"+h)
            break
x = input("press enter to exit")0

this program take a string from you and give you a Desirable-hash by changing lower to upper and changing lower to upper if that possible

By shamsnaamir, 2019-12-13 10:04:28
const ITEM_COUNT = 100
let visibleItems = []
for (let i = 0; i < ITEM_COUNT; ++i) {
  visibleItems.push(false)
}

function showItem(index) {
  visibleItems = []
  for (let i = 0; i < ITEM_COUNT; ++i) {
    visibleItems.push(false)
  }
  visibleItems[index] = true
}

It was more or less like this. The guy had a collection of React components and wanted to show only one of them at a time. Instead of storing the index of the component to show at the moment, he decided that a boolean array would work much better. O(n) in runtime and space and null readability just because.

By Anonymous, 2019-12-07 11:59:58
#411 C# +13
if (date.Training != null)
            {
                var training = date.Training;
                var status = new TrainingStatus();
                var refresher = new Training();

                if (training.Trainings != null)
                    refresher = training.Trainings;

                bool hasTakenRefresher = false;
                status.Value = date.Date.AddDays(
                    TrainingHelper.CalculateValidityDays(training.Validity ?? 0, training.ValidityType ?? 0));

                status.Name = training.TrainingName;
                status.ID = training.TrainingID;
                status.Category = training.CategoryTraining != null ? training.CategoryTraining.Name : "Other";
                status.IsTrained = _validityUtilsService.IsValid(training, date.Date);

                if (status.IsTrained)
                {
                    status.IsExpiring = _validityUtilsService.IsExpiring(training, date.Date,
                                            TrainingHelper.CalculateValidityDays(
                                                training.ExpirationWarningValidity ?? 0,
                                                training.ExpirationWarningValidityType ?? 0));
                }

                if (refresher.ID != 0)
                {
                    hasTakenRefresher = employee.Dates
                        .Count(x => x.Training != null
                            && x.TrainingID == refresher.ID) > 1;

                    if (hasTakenRefresher && (status.IsExpiring || !status.IsTrained))
                    {
                        status.IsExpiring = false;
                        var trainingWithNewValidity = new Training();

                        status.Value = date.Date.AddDays(
                            TrainingHelper.CalculateValidityDays(training.ValidityRefresher ?? 0,
                                training.ValidityRefresherType ?? 0));

                        trainingWithNewValidity.Validity = training.ValidityRefresher;
                        trainingWithNewValidity.ValidityType = training.ValidityRefresherType;
                        status.IsTrained = _validityUtilsService.IsValid(trainingWithNewValidity, date.Date);

                        if (status.IsTrained)
                        {
                            status.IsExpiring = _validityUtilsService.IsExpiring(trainingWithNewValidity, date.Date,
                                TrainingHelper.CalculateValidityDays(
                                    refresher.ExpirationWarningValidity ?? 0,
                                    refresher.ExpirationWarningValidityType ?? 0));
                        }
                    }
                }

                if (status.IsTrained && !status.IsExpiring)
                    status.Status = TrainingStatuses.Trained;
                else if (status.IsTrained && status.IsExpiring)
                    status.Status = TrainingStatuses.Expiring;
                else if (!status.IsTrained && !status.IsExpiring)
                    status.Status = TrainingStatuses.Expired;

                status.EmpID = employee.ID;

                return status;
            }

test

By NN, 2019-10-29 12:59:14
    if [ $product == "consul" ]
    then
       aws s3 cp s3://${path}/${product}/prem/${version}/${product}-enterprise_${version}+prem_linux_amd64.zip .
       unzip ${product}-enterprise_${version}+prem_linux_amd64.zip
       rm   ${product}-enterprise_${version}+prem_linux_amd64.zip
    else
       aws s3 cp s3://${path}/${product}/prem/${version}/${product}-enterprise_${version}+prem_linux_amd64.zip .
       unzip ${product}-enterprise_${version}+prem_linux_amd64.zip
       rm   ${product}-enterprise_${version}+prem_linux_amd64.zip
    fi 
By Anonymous, 2019-10-22 15:10:43
// TODO(as): MAKE XML DOXYGEN THING SO IDE WITH COLORS CAN READ THIS
package main

import (
	"os"
	"sync"

	_ "github.com/mailru/easyjson"
	_ "github.com/satori/go.uuid"
	_ "github.com/valyala/fasthttp"
)

func main() {
	sync.Once(func(){}())

	myMutexLockVariable := struct {
		IDontKnowHowEmbeddingWorks *sync.RWMutex // FOR SCALEABILITY
	}{
		func() *sync.RWMutex {
			return new(sync.RWMutex) // FACTORY PATTERN FACTORY PATTERN!
		}(),
	}
	
	lockthelock := func(){
		myMutexLockVariable.IDontKnowHowEmbeddingWorks.Lock()
	}
	unlockthelock := func(){
		myMutexLockVariable.IDontKnowHowEmbeddingWorks.Lock()
	}
	// TODO(as): THERE THEM FUNCTIORNS NO WORKY ABSTRACTION FOR SOME REASON
	// SO WE JUST CALL myMutexLockVariable.IDontKnowHowEmbeddingWorks FUNCTIONS
	// DIRECTLY THERE IS A BUG INSIDE OF THE GO PROGRAMMING LANGUAGE
	//
	// GO ISSUE NUMBER: 181393
	// Description: GO NO WORKY, I PUT FUNCTORS TO ACCESS MY LOCK AND IT DEAD LOCK
	// cc: bradfitz, ian lance taylor, rob pike, ken, even brian k
	lockthelock = lockthelock
	unlockthelock = unlockthelock
	    // I DONT WANNA DELETE FUNCY BECAUSE I WORK TOO HARD ON THEM WE KEEP IT FOR USE LATER WHEN GO FIXES BUG

	var err error
	if myMutexLockVariable.IDontKnowHowEmbeddingWorks == nil {
		panic("whoops, you forgot to put the pointer of the mutex!!!!!")
		os.Exit(0xbadc0de) // FOR SAFTEY
	}
	myMutexLockVariable.IDontKnowHowEmbeddingWorks.RLock()
	myMutexLockVariable.IDontKnowHowEmbeddingWorks.Unlock() // just grease the wheels a bit
	myMutexLockVariable.IDontKnowHowEmbeddingWorks.Lock()
	go func() {
		println("goroutine!")
		myMutexLockVariable.IDontKnowHowEmbeddingWorks.Unlock()
	}()

	myMutexLockVariable.IDontKnowHowEmbeddingWorks.Lock() // WAIT FOR BABY TO FINISH
	if &err != nil {
		myMutexLockVariable.IDontKnowHowEmbeddingWorks.Unlock() // DO IT HERE FASTER THAN DEFUR
		main()
		os.Exit(0) // YAY
	}
	myMutexLockVariable.IDontKnowHowEmbeddingWorks.Unlock() // DO IT HERE FASTER THAN DEFUR
}

THIS CODE IS COVERED BY THE GNU AFFERO PUBIC LICENSE, DO NOT SHARE THIS CODE WITHOUT PUBLISHING ALL OF YOUR CHANGES. FREE SOFTWARE FREEEEEDOM!!!

TO SEE THE TEXINFO MANUAL IN EMACS, TYPE CONTROL X CLOVER CLOVER DOT 9

By github.com/as, 2019-10-18 19:26:43
public static int maximum(int f, int g)
{
	try
	{
		int[] far = new int[f];
		far[g] = 1;
		return f;
	}
	catch(NegativeArraySizeException e)
	{
		f = -f;
		g = -g;
		return (-maximum(f, g) == -f)? -g : -f;
	}
	catch(IndexOutOfBoundsException e)
	{
		return (maximum(g, 0) == 0)? f : g;
	}
}
By Anonymous, 2019-10-18 06:03:41
<?php

class CasinoCode
{
    CONST POST = 'POST';
    CONST GET = 'GET';
    
    $data = $this->callAPI('/hidden', [], self::POST);

production code of an API with dozens of millions of requests per day.

By Anonymous, 2019-10-17 19:43:24
function downScaleCanvas(a, b) {
    var c = Math.ceil,
        d = Math.floor;
    if (!(1 > b) || !(0 < b)) throw "scale must be a positive number <1 ";
    var e = b * b,
        f = a.width,
        g = a.height,
        h = d(f * b),
        i = d(g * b),
        j = 0,
        k = 0,
        l = 0,
        m = 0,
        n = 0,
        o = 0,
        p = 0,
        q = 0,
        r = 0,
        s = 0,
        t = 0,
        u = 0,
        v = 0,
        x = 0,
        y = 0,
        z = !1,
        A = !1,
        B = a.getContext("2d").getImageData(0, 0, f, g).data,
        C = new Float32Array(3 * h * i),
        D = 0,
        E = 0,
        F = 0;
    for (k = 0; k < g; k++)
        for (n = k * b, r = 0 | n, o = 3 * r * h, A = r != (0 | n + b), A && (x = r + 1 - n, y = n + b - r - 1), j = 0; j < f; j++, l += 4) m = j * b, q = 0 | m, p = o + 3 * q, z = q != (0 | m + b), z && (u = q + 1 - m, v = m + b - q - 1), D = B[l], E = B[l + 1], F = B[l + 2], z || A ? z && !A ? (s = u * b, C[p] += D * s, C[p + 1] += E * s, C[p + 2] += F * s, t = v * b, C[p + 3] += D * t, C[p + 4] += E * t, C[p + 5] += F * t) : A && !z ? (s = x * b, C[p] += D * s, C[p + 1] += E * s, C[p + 2] += F * s, t = y * b, C[p + 3 * h] += D * t, C[p + 3 * h + 1] += E * t, C[p + 3 * h + 2] += F * t) : (s = u * x, C[p] += D * s, C[p + 1] += E * s, C[p + 2] += F * s, t = v * x, C[p + 3] += D * t, C[p + 4] += E * t, C[p + 5] += F * t, t = u * y, C[p + 3 * h] += D * t, C[p + 3 * h + 1] += E * t, C[p + 3 * h + 2] += F * t, t = v * y, C[p + 3 * h + 3] += D * t, C[p + 3 * h + 4] += E * t, C[p + 3 * h + 5] += F * t) : (C[p] += D * e, C[p + 1] += E * e, C[p + 2] += F * e);
    var G = document.createElement("canvas");
    G.width = h, G.height = i;
    var H = G.getContext("2d"),
        I = H.getImageData(0, 0, h, i),
        J = I.data,
        K = 0;
    for (l = 0, p = 0; K < h * i; l += 3, p += 4, K++) J[p] = c(C[l]), J[p + 1] = c(C[l + 1]), J[p + 2] = c(C[l + 2]), J[p + 3] = 255;
    return H.putImageData(I, 0, 0), G
}

dohhhhhh !!

By fotogena.co sonickseven, 2019-10-13 00:10:25
double zuida(std::vector<double> vec) {
	std::vector<double> temp;
	for(int i = 0; i < vec.size(); i++)
		temp.push_back(vec[i]);
notend:
	if(temp.size() > 0) {
		if(temp.size() < 2) {
			double tmp = *(&temp[0]);
			return tmp;
		}
		else if(temp.size() >= 2) {
			double mini = temp[0];
			int ind = 0;
			for(int i = 0; i < temp.size(); i++)
				if(temp[i] < mini) {
					mini = temp[i];
					ind = i;
				}
			temp.erase(temp.begin() + ind);
			goto notend;
		}
	}
}

The beauty is that every case is the best (also worst) case!

By Anonymous, 2019-10-12 10:42:23
<ng-container *ngIf="!errors">
    <div *ngIf="errors" class="no-content-wrapper">
        <esel-components-error [error]="errors"></esel-components-error>
    </div>
</ng-container>

Make your code error prone with effective error handling!

By Anonymous, 2019-10-11 12:49:41
public partial class Form1 : Form
   {
      public Form1()
      {
         InitializeComponent();
      }

      protected override void OnLoad(EventArgs e)
      {
         base.OnLoad(e);
         var token = new CancellationTokenSource().Token;
         Task.Factory.StartNew (() => {
            while (!token.IsCancellationRequested) {
               try {
                  if (/*Condition*/)
                     this.Invoke(new Action(() => label.Text = " =)"));
                  else
                     this.Invoke(new Action(() => label.Text = " =("));
                  Thread.Sleep(10);
               }
               catch (Exception) {
                  throw;
               }
               finally {
                  throw new Exception();
               }
            }
         }) ;
      }
   }

My collegue's way of using multithreading features (and exceptions handling) :)

By Loganjii, 2019-10-09 15:00:18
//Говорящие названия - такие говорящие!
    function asdfasdf (WebAPI_Entity $screenshot_dictionary)
    {
        $result = array();
        foreach ($screenshot_dictionary->getEntities () as $scr)
        {
            $result [] = $scr->toObject ();
        }
        usort($result, array ($this, 'sortScreenshots'));
        return $this->prepare_screenshots ($result);
    }
    
// вставляем остальные скриншоты
$elements = $this->asdfasdf ($screenshot_dictionary);
By C.H., 2019-10-07 16:47:29
  @Override
    public ResponseEntity<AuditLogPagedResults> getLogEntries(
    		@ApiParam(value = "Environment ID", required = true) @PathVariable("environmentId") Long environmentId,
	   	  	@ApiParam(value = "ID of the queue manager to browse") @Valid @RequestParam(value = "queueManager", required = false) Long queueManager,
	   	  	@ApiParam(value = "ID of the queue to browse") @Valid @RequestParam(value = "queue", required = false) Long queue,
	   	  	@ApiParam(value = "Browse for messages newer than a date/time") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) @RequestParam(value = "from", required = false) @Valid LocalDateTime from,
	   	  	@ApiParam(value = "Correlation ID to browse for") @Valid @RequestParam(value = "correlationId", required = false) String correlationId,
	   	  	@ApiParam(value = "Page of results to return") @Valid @RequestParam(value = "page", required = false) Integer page,
            @ApiParam(value = "Number of results in a page") @Valid @RequestParam(value = "pagesize", required = false) Integer pagesize) {
        Pageable pageable = PageRequest.of(page != null ? page : 0, pagesize != null ? pagesize : defaultPageSize, new Sort(Sort.Direction.DESC, Audit.MSG_PUT_TIMESTAMP_FIELD));
        Page<Audit> auditEntries = null;
        Timestamp msgPut = (from != null ? Timestamp.valueOf(from) : null);

        /*
         * Environemnt is always supplied.  If we have queue or queue manager, assume that's what the caller wants.
         * We may also have some optional parameters - put timestamp, correlation ID
         */
        if (queue != null) {
        	//retrieve queue name
        	String queueName = null;
        	Optional<WMQQueue> queueEntity = wmqQueueRepository.findById(queue.intValue());
        	queueName = queueEntity.get().getQ_name();
        	
        	//see if we have timestamp or correlation ID
			if (msgPut != null) {
				if (correlationId != null) {
					auditEntries = auditRepository.findByQNameAndCorrelIdAndMsgPutTimestampGreaterThanEqual(queueName, msgPut, correlationId, pageable);
				} else {
					auditEntries = auditRepository.findByQNameAndMsgPutTimestampGreaterThanEqual(queueName, msgPut, pageable);
				}
			} else {
				if (correlationId != null) {
					auditEntries = auditRepository.findByQNameAndCorrelId(queueName, correlationId, pageable);
				} else {
					auditEntries = auditRepository.findByQName(queueName, pageable);
				}
			}
        } else if (queueManager != null) {
            List<Integer> managerIds = Arrays.asList(queueManager.intValue());
        	//see if we have timestamp or correlation ID
			if (msgPut != null) {
				if (correlationId != null) {
                    auditEntries = auditRepository.findByManagerIdsAndCorrelIdAndMsgPutTimestampGreaterThanEqual(managerIds, msgPut, correlationId, pageable);
				} else {
                    auditEntries = auditRepository.findByManagerIdsAndMsgPutTimestamp(managerIds, msgPut, pageable);
				}
			} else {
				if (correlationId != null) {
                    auditEntries = auditRepository.findByManagerIdsAndCorrelId(managerIds, correlationId, pageable);
				} else {
                    auditEntries = auditRepository.findByManagerIds(managerIds, pageable);
				}
			}
throw new java.lang.UnsupportedOperationException("Implementations does not exist");
        } else {
	        List<Integer> managerIds = findManagerIds(environmentId);
	
	        if(managerIds.isEmpty()) {
	            //No QueueManager so no possible log entries
	            return ResponseEntity.ok().body(null);
	        }
	
	        if (msgPut != null) {
	            auditEntries = auditRepository.findByManagerIdsAndMsgPutTimestamp(managerIds, msgPut, pageable);
	        } else {
	            auditEntries = auditRepository.findByManagerIds(managerIds, pageable);
	        }
        }
        
        
        /*
        if (correlationId != null && msgPut != null) {
            auditEntries = auditRepository.findByCorrelIdAndMsgPutTimestampGreaterThanEqual(correlationId, msgPut, pageable);
        } else if (queueName != null && msgPut != null) {
            auditEntries = auditRepository.findByQNameAndMsgPutTimestampGreaterThanEqual(queueName, msgPut, pageable);
        } else if (queueName != null) {
            auditEntries = auditRepository.findByQName(queueName, pageable);
        } else if (correlationId != null) {
            auditEntries = auditRepository.findByCorrelId(correlationId, pageable);
        } else {
            List<Integer> managerIds = findManagerIds(environmentId);

            if(managerIds.isEmpty()) {
                //No QueueManager so no possible log entries
                return ResponseEntity.ok().body(null);
            }

            if (msgPut != null) {
                auditEntries = auditRepository.findByManagerIdsAndMsgPutTimestamp(managerIds, msgPut, pageable);
            } else {
                auditEntries = auditRepository.findByManagerIds(managerIds, pageable);
            }
        }
*/
        if (auditEntries != null) {
	        AuditLogPagedResults results = new AuditLogPagedResults();
	        results.setPageNumber(pageable.getPageNumber());
	        results.setPageSize(pageable.getPageSize());
	        results.setPages(auditEntries.getTotalPages());
	        results.setResults(mapperFacade.mapAsList(auditEntries.getContent(), AuditLogEntry.class));
	        return ResponseEntity.ok().body(results);
        } else {
        	throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Not found");
        }
    }

    
    /* (non-Javadoc)
	 * @see com.arcelormittal.springTemplate.web.MessagesApi#getLogEntry(java.lang.Long, java.lang.Long)
	 */
	@Override
	public ResponseEntity<AuditLogEntry> getLogEntry(Long environmentId, Long logId) {
		Optional<Audit> entry = auditRepository.findById(logId);
		if (entry.isPresent()) {
			return ResponseEntity.ok().body(mapperFacade.map(entry.get(), AuditLogEntry.class));
		} else {
			throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Not found");
		}
	}

End pint to do a dynamic query in JPA.

By Anonymous, 2019-10-02 23:31:22