Skip to content

Instantly share code, notes, and snippets.

View pyq's full-sized avatar
🐶

Yongqing pyq

🐶
  • Square Cash
  • San Francisco
View GitHub Profile
@pyq
pyq / mysql_innodb_gap_lock.sql
Created May 17, 2020 09:30
MySQL innodb gap lock
-- create table
CREATE TABLE `idempotence_keys` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
KEY `created_at` (`created_at`)
) ENGINE=InnoDB AUTO_INCREMENT=55 DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC
-- insert
insert into idempotence_keys (created_at)
@pyq
pyq / MaximizeMinDistance
Created November 24, 2016 10:21
space O(1) time O(n)
import java.util.Arrays;
import java.util.List;
/**
* Created by pyq on 11/24/16.
*/
/*
We have an array of Integers. We want to reorder the elements in-place to have even numbers as far from each other as possible (i.e. we want to maximize the minimum distance between any two even numbers in the list). Note that we do not want to create a second array, and would like this to happen in the original array, in-place.
For example:
@pyq
pyq / MaxSumPath
Last active November 23, 2016 18:19
Question from YW
import java.util.*;
/**
* Created by pyq on 11/16/16.
* Question 4
==========
1
2 5
3 2 1
1 3 2 1
@pyq
pyq / SubClass.java
Created July 15, 2016 22:09
See what error you throw
import java.io.EOFException;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.IllegalFormatException;
/**
* Created by yongqingpeng on 7/15/16.
*/
class SuperClass
{
@pyq
pyq / SubClass.java
Last active July 15, 2016 19:03
Polymorphism related
import java.io.EOFException;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.IllegalFormatException;
/**
* Created by yongqingpeng on 7/15/16.
*/
class SuperClass
{
@pyq
pyq / IteratorRemove.java
Created May 7, 2015 03:13
Why do you get a ConcurrentModificationException when using an iterator?
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
/**
* Created by pyq on 5/6/15.
*/
/*
@pyq
pyq / Ticket.java
Last active August 29, 2015 14:18
Ticket
import java.lang.reflect.Array;
import java.util.*;
/**
* Created by pyq on 4/10/15.
*/
public class Ticket {
// has n stations, every station has stations[i] number tickets, and sell with station[i] price
// public static long maxProfit(int[] stations, int n, int m) {
// Queue<Integer> maxHeap = new PriorityQueue<>(n, new Comparator<Integer>(){
import sys
import random
no_of_heaps = random.choice([3,5,7])
heap = []
user = random.choice([0,1]) # if "user" is assigned value 0, then computer goes first, else vice versa
nextMove = ''
def gameInitialSetup():
for x in range(no_of_heaps):