Code examples from this stack overflow answer.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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%' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
->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'); | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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%; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#define DATA_SIZE_LIMIT 30 | |
# | |
# how to compile and execute: | |
# gcc hopscotch.c -o hopscotch | |
# ./hopscotch < input.txt | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 |
NewerOlder