Skip to content

Instantly share code, notes, and snippets.

View lishiyo's full-sized avatar

Connie Li lishiyo

  • New York City
View GitHub Profile
@lishiyo
lishiyo / ExHeaderFragment.java
Last active February 16, 2016 22:16
Smooth View Pager - AppBar with Fragment
package me.henrytao.smoothappbarlayoutdemo.fragment;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import me.henrytao.smoothappbarlayoutdemo.R;
public class ExHeaderFragment extends Fragment {
function copyToClipboard( text ){
var copyDiv = document.createElement('div');
copyDiv.contentEditable = true;
document.body.appendChild(copyDiv);
copyDiv.innerText = text;
copyDiv.unselectable = "off";
copyDiv.focus();
document.execCommand('SelectAll');
document.execCommand("Copy", false, null);
document.body.removeChild(copyDiv);
@lishiyo
lishiyo / gulpfile.js
Last active August 26, 2018 17:19
Full Gulp-Babel-BrowserSync
var gulp = require('gulp'),
browserify = require('browserify'),
babelify = require('babelify'),
source = require('vinyl-source-stream'),
reactify = require('reactify'),
browserSync = require('browser-sync').create(),
uglify = require('gulp-uglify'),
htmlreplace = require('gulp-html-replace'),
watchify = require('watchify'),
streamify = require('gulp-streamify');
@lishiyo
lishiyo / package.json
Created June 9, 2015 19:19
Sample Express Server
{
"name": "sample-server",
"version": "0.0.0",
"description": "Code from the React tutorial.",
"main": "server.js",
"dependencies": {
"body-parser": "^1.4.3",
"express": "^4.4.5"
},
"devDependencies": {},
@lishiyo
lishiyo / giphyroulette.rb
Last active August 29, 2015 14:20
Random Giphy Gif
# aText as "shell script" => ruby /path/to/this/script.rb <optional query>
# Returns random giphy gif from top 100 trending or by query
require 'net/http'
require 'json'
class GiphySearch
def initialize
@defaults = {
@lishiyo
lishiyo / rAF.js
Last active August 29, 2015 14:20 — forked from paulirish/rAF.js
requestAnimationFrame polyfill
// http://paulirish.com/2011/requestanimationframe-for-smart-animating/
// http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating
// requestAnimationFrame polyfill by Erik Möller. fixes from Paul Irish and Tino Zijdel
// MIT license
(function() {
var lastTime = 0;
var vendors = ['ms', 'moz', 'webkit', 'o'];
@lishiyo
lishiyo / autoload.php
Created April 12, 2015 04:40
PHP Examples - Autoload
/*
Autoloading is very nifty, and is used in a lot of large frameworks - it allows you to load the file that a class is written in automatically when you try to instantiate it. The advantage of this is that only classes that you want to instantiate & use will be included in your page and will keep memory usage down.
*/
// Using an anonymous function
spl_autoload_register(function($class){
include_once('includes/' . $class . '.class.php')
});
// Using a named function
@lishiyo
lishiyo / singleton.php
Created April 12, 2015 04:38
PHP Examples - Singleton
class DemoSingleton {
private static $instance = NULL;
public static function getInstance(){
if(is_null(self::$instance)){
self::$instance = new self();
}
return self::$instance;
}
}
@lishiyo
lishiyo / gulpfile-plugins
Created April 7, 2015 11:49
Gulpfile-Plugins
var gulp = require('gulp');
var plugins = require("gulp-load-plugins")({
pattern: ['gulp-*', 'gulp.*', 'main-bower-files'],
replaceString: /\bgulp[\-.]/
});
var dest = "./public/";
var src = './src/';
var clientJS = src + 'js/*.js';
var clientSCSS = src + 'css/*.scss';
@lishiyo
lishiyo / package.json
Last active August 29, 2015 14:18
Package.json Boilerplate
{
"name": "app",
"version": "1.0.0",
"description": "do all development work here",
"main": "gulpfile.js",
"directories": {
"test": "test"
},
"devDependencies": {
"browserify": "^9.0.4",