Skip to content

Instantly share code, notes, and snippets.

@LeeXun
LeeXun / 1_two_sum_leetcode.c
Last active November 13, 2018 15:33
Leetcode
/**
* Note: The returned array must be malloced, assume caller calls free().
*/
int* twoSum(int* nums, int numsSize, int target) {
int i, j;
int *ans = malloc(sizeof(int)*2);
for(i=0; i<numsSize; i++) {
for(j=0; j<numsSize; j++) {
if(nums[i]+nums[j] == target && i != j) {
ans[0] = j;
@LeeXun
LeeXun / postgres_queries_and_commands.sql
Created June 19, 2018 13:38 — forked from rgreenjr/postgres_queries_and_commands.sql
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(query_start, clock_timestamp()), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(query_start, clock_timestamp()), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
@LeeXun
LeeXun / README.md
Created March 20, 2018 15:09 — forked from balupton/README.md
Node.js Best Practice Exception Handling
->leftJoin('likes', function($join) use ($viewer_id) {
$join->on('likes.customer_id', '=', DB::raw($viewer_id));
$join->on('likes.like_type', '=', DB::raw(Like::LIKE_TYPE_PRODUCT));
$join->on('likes.like_id', '=', 'oc_product.product_id');
})
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Two way binding</title>
<style>
#app {
width: 100%;
module.exports = function isSubstring(a, b) {
let i = 0
while(i < a.length - b.length){
let j = 1
if(a[i] == b[0]){
while(true){
if(a[i+j] == b[j]){
if(j == b.length - 1){
return i + j
/*
* 2017/10/31 Happy Helloween
* Author: LeeXun leexun.official@gmail.com
* Just copy and paste it on console
* Notice: It's really dangerous if you don't know that this means!
*
*/
function handleNewElement() {
var nodeList = document.getElementById('js_1').querySelectorAll("[aria-label='貼圖']");
var s = nodeList[nodeList.length-1].style;
@LeeXun
LeeXun / hopscotch.c
Last active October 27, 2017 06:18
NCCU Assignment 4: Modified "hopscotch" game
#include <stdio.h>
#include <stdlib.h>
#define DATA_SIZE_LIMIT 30
#
# how to compile and execute:
# gcc hopscotch.c -o hopscotch
# ./hopscotch < input.txt
#
We couldn’t find that file to show.
@LeeXun
LeeXun / gist:f068e5411a57aed6153f3f349bafefe0
Created July 21, 2016 09:29 — forked from prime31/gist:5675017
Simple PHP script showing how to send an Android push notification. Be sure to replace the API_ACCESS_KEY with a proper one from the Google API's Console page. To use the script, just call scriptName.php?id=THE_DEVICE_REGISTRATION_ID
<?php
// API access key from Google API's Console
define( 'API_ACCESS_KEY', 'YOUR-API-ACCESS-KEY-GOES-HERE' );
$registrationIds = array( $_GET['id'] );
// prep the bundle
$msg = array