Skip to content

Instantly share code, notes, and snippets.

View henrybear327's full-sized avatar

Chun-Hung Tseng henrybear327

View GitHub Profile
#include <Wire.h>
byte i2cdata[4];
void setup() {
Wire.begin();
Serial.begin(9600);
}
void loop() {
<?php
function get_ip_address() {
$ip_keys = array('HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR');
foreach ($ip_keys as $key) {
if (array_key_exists($key, $_SERVER) === true) {
foreach (explode(',', $_SERVER[$key]) as $ip) {
// trim for safety measures
$ip = trim($ip);
// attempt to validate IP
if (validate_ip($ip)) {
@henrybear327
henrybear327 / aes_enc_dec.php
Last active August 29, 2015 14:25 — forked from turret-io/aes_enc_dec.php
AES encryption/decryption in PHP
<?php
// DEFINE our cipher
define('AES_256_CBC', 'aes-256-cbc');
// Generate a 256-bit encryption key
// This should be stored somewhere instead of recreating it each time
$encryption_key = openssl_random_pseudo_bytes(32);
// Generate an initialization vector
// This *MUST* be available for decryption as well
@henrybear327
henrybear327 / Pi_C.cpp
Last active August 29, 2015 14:26 — forked from vovuh/Pi_C.cpp
#define _CRT_SECURE_NO_WARNINGS
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <time.h>
#include <string>
#include <vector>
#include <math.h>
@henrybear327
henrybear327 / stdc++.h
Last active August 29, 2015 14:27 — forked from velicast/stdc++.h
Linux GCC 4.8.0 /bits/stdc++.h header definition.
// C++ includes used for precompiling -*- C++ -*-
// Copyright (C) 2003-2013 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
@henrybear327
henrybear327 / arm-elf-gcc_on_osx.sh
Created October 11, 2015 11:46 — forked from steakunderscore/arm-elf-gcc_on_osx.sh
How I installed arm-elf-gcc on Mac OS X
#!/bin/bash
mkdir toolchain
cd toolchain
wget ftp://sources.redhat.com/pub/newlib/newlib-1.19.0.tar.gz
wget http://ftp.gnu.org/gnu/gdb/gdb-7.2.tar.gz
wget http://ftp.gnu.org/gnu/binutils/binutils-2.21.tar.bz2
wget http://ftp.gnu.org/gnu/gcc/gcc-4.6.0/gcc-core-4.6.0.tar.bz2
@henrybear327
henrybear327 / arm-eabi-gcc_on_ubuntu.markdown
Created October 24, 2015 15:41 — forked from steakunderscore/arm-eabi-gcc_on_ubuntu.markdown
How I installed arm-eabi-gcc on Ubuntu 11.04

Install some needed libraries

sudo aptitude install libmpc-dev

Make the temp directory to build in

mkdir toolchain
cd toolchain

Get the required sources

@henrybear327
henrybear327 / google-cloud-storage-upload-download.php
Created December 12, 2015 05:47 — forked from stetic/google-cloud-storage-upload-download.php
PHP Example for Google Storage Upload and Download with Google APIs Client Library for PHP
<?php
/*
* PHP Example for Google Storage Up- and Download
* with Google APIs Client Library for PHP:
* https://github.com/google/google-api-php-client
*/
include( "Google/Client.php" );
include( "Google/Service/Storage.php" );
@henrybear327
henrybear327 / gist:01e32992a0d69337f769
Created December 12, 2015 05:48 — forked from N-Porsh/gist:7766039
PHP: simple multiple file upload
<?php
$max_file_size = 5*1024*1024; //5MB
$path = "admin/upload/"; // Upload directory
//$count = 0; // nr.successfully uploaded files
$valid_formats = array("rar","zip","7z","pdf","xlsx","xls","docx","doc","txt");
$valid_formats_server = array(
"application/pdf",
"application/octet-stream",
@henrybear327
henrybear327 / InfixToPostfix.cpp
Created December 13, 2015 17:44 — forked from mycodeschool/InfixToPostfix.cpp
Infix to Postfix conversion in C++ using stack. We are assuming that both operators and operands in input will be single character.
/*
Infix to postfix conversion in C++
Input Postfix expression must be in a desired format.
Operands and operator, both must be single character.
Only '+' , '-' , '*', '/' and '$' (for exponentiation) operators are expected.
*/
#include<iostream>
#include<stack>
#include<string>