Skip to content

Instantly share code, notes, and snippets.

View youchen's full-sized avatar

Youchen Ren youchen

View GitHub Profile
@youchen
youchen / sql-hackerrank.sql
Last active April 12, 2021 01:11
solution to HackerRank sql exercise
/* Basic Select */
-- Revising the Select Query I
SELECT
*
FROM
CITY
WHERE
POPULATION > 100000
AND COUNTRYCODE = 'USA'
#include <iostream>
#include <cmath>
#include <string>
using namespace std;
bool isPrime(int num){
if (num <= 1) return false;
for(int i = 2; i <= sqrt(num); i++){
if (num % i == 0) {
#include <iostream>
#include <cmath>
using namespace std;
bool isPrime(int num){
if (num <= 1) return false;
for(int i = 2; i <= sqrt(num); i++){
if (num % i == 0) {
return false;
package main
import "fmt"
func fibonacci() func() int {
fib1, fib2 := 0, 1
return func() int{
defer func() { fib1, fib2 = fib2, fib1 + fib2 } ()
return fib1
}
package main
import (
"golang.org/x/tour/wc"
"strings"
)
func WordCount(s string) map[string]int {
sArr := strings.Fields(s)
count := make(map[string]int)
package main
import "golang.org/x/tour/pic"
func Pic(dx, dy int) [][]uint8 {
pic := make([][]uint8, dy)
for i := range pic {
pic[i] = make([]uint8, dx)
package main
import (
"fmt"
)
func Sqrt(x float64) float64 {
z := 1.0
it := 0
@youchen
youchen / fileTimestampShift.sh
Last active September 5, 2017 03:53
Script to shift the timestamp of file.
# source: https://morimori.tokyo/2015/10/adjusting-timestamps-from-a-gopro/
#
#!/usr/bin/env bash
FILES=$(ls *.MP4) # FILES=$(ls *.{JPG,MP4})
for filename in $FILES
do
# Offset is 974 days 10 hours 39 minutes
NEWDATE=$(date -j -v+974d -v+10H -v+39M -f "%m/%d/%Y %H:%M:%S" "$(GetFileInfo -m $filename)" +"%m/%d/%Y %H:%M:%S")
@youchen
youchen / cc150_01_01.java
Last active August 29, 2015 14:02
cc150 - 1.1 UniqueCharChecker
import java.util.*;
/**
* 1.1 Implement an algorithm to determine if a string has all unique characters.
* What if you cannot use additional data structures?
*
* idea: Make a hash table to store the character.
* The key is the position of the char in the given string;
* The value is the char in the given string.
* By adding the char of the given string into the hash table, first check
* if the hash table has already contain the value(the particular char in String).