Skip to content

Instantly share code, notes, and snippets.

View jasdeepkhalsa's full-sized avatar

Jasdeep Khalsa jasdeepkhalsa

View GitHub Profile
@jasdeepkhalsa
jasdeepkhalsa / imageCropAdvanced.php
Created December 19, 2012 20:02 — forked from anonymous/imageCropAdvanced.php
Using PHP and GD to crop an image proportionally according to its aspect ratio. From: http://stackoverflow.com/questions/1855996/crop-image-in-php
<?php
$image = imagecreatefromjpeg($_GET['src']);
$filename = 'images/cropped_whatever.jpg';
$thumb_width = 200;
$thumb_height = 150;
$width = imagesx($image);
$height = imagesy($image);
@jasdeepkhalsa
jasdeepkhalsa / pipe.js
Last active March 12, 2021 15:42 — forked from ericelliott/pipe.js
Pipe
// Pipe takes the first argument and pipes it though each of the functions that you provide as the remaining arguments,
// and can be implemented as follows:
const pipe = (...fns) => x => fns.reduce((v, f) => f(v), x);
const fn1 = s => s.toLowerCase();
const fn2 = s => s.split('').reverse().join('');
const fn3 = s => s + '!'
const newFunc = pipe(fn1, fn2, fn3);
const result = newFunc('Time'); // emit!
@jasdeepkhalsa
jasdeepkhalsa / index.html
Created March 5, 2021 12:44 — forked from igrigorik/index.html
XHR streaming example
<p>Hello
<script>
var xhr = new XMLHttpRequest();
xhr.open('GET', '/stream');
xhr.seenBytes = 0;
xhr.onreadystatechange = function() {
console.log("state change.. state: "+ xhr.readyState);
@jasdeepkhalsa
jasdeepkhalsa / compose.js
Created July 24, 2020 16:16 — forked from ericelliott/compose.js
Compose implementation
const compose = (...fns) => x => fns.reduceRight((v, f) => f(v), x);
@jasdeepkhalsa
jasdeepkhalsa / react-route-based-code-splitting.js
Last active September 5, 2018 10:26 — forked from gaearon/webpack.config.js
React & Webpack Route-based code splitting example
import { BrowserRouter as Router, Route, Switch } from 'react-router-dom';
import Loadable from 'react-loadable';
const Loading = () => <div>Loading...</div>;
const Home = Loadable({
loader: () => import('./routes/Home'),
loading: Loading,
});
@jasdeepkhalsa
jasdeepkhalsa / fetchData.js
Last active April 26, 2018 16:17 — forked from Calvin-Huang/redux-saga-worker-and-watcher.js
Redux Saga Example with Worker and Watcher
import { call, put, takeLatest } from 'redux-saga/effects';
/*
const EXAMPLE_DISPATCHED_ACTION = {
type: 'FETCH_REQUESTED',
payload: { url: 'https://api.github.com' }
}
*/
// Watcher

Deploy your site with git

This gist assumes:

  • you have a local git repo
  • with an online remote repository (github / bitbucket etc)
  • and a cloud server (Rackspace cloud / Amazon EC2 etc)
    • your (PHP) scripts are served from /var/www/html/
    • your webpages are executed by apache
  • apache's home directory is /var/www/
// Includes functions for exporting active sheet or all sheets as JSON object (also Python object syntax compatible).
// Tweak the makePrettyJSON_ function to customize what kind of JSON to export.
var FORMAT_ONELINE = 'One-line';
var FORMAT_MULTILINE = 'Multi-line';
var FORMAT_PRETTY = 'Pretty';
var LANGUAGE_JS = 'JavaScript';
var LANGUAGE_PYTHON = 'Python';
@jasdeepkhalsa
jasdeepkhalsa / pre-commit
Last active December 19, 2015 07:09 — forked from raphaelstolt/pre-commit
Pre-commit hook for SVN and PHPUnit
#!/usr/bin/php
<?php
$projectName = basename(getcwd());
exec('phpunit', $output, $returnCode); // Assuming cwd here
if ($returnCode !== 0) {
$minimalTestSummary = array_pop($output);
printf("Test suite for %s failed: ", $projectName);
printf("( %s ) %s%2\$s", $minimalTestSummary, PHP_EOL);
return false; // exit(1);
}