Skip to content

Instantly share code, notes, and snippets.

View bebraw's full-sized avatar

Juho Vepsäläinen bebraw

View GitHub Profile
@thejhh
thejhh / test.js
Last active December 11, 2015 20:28
Building equations for multiple systems from JavaScript presentation by calling a function
"use strict";
/** Query builder */
function build_query(type, schema) {
// Metadata for builder
var _converters = {
js:{
or: function(x, y) { return '(' + x + ') || (' + y + ')'; },
and: function(x, y) { return '(' + x + ') && (' + y + ')'; },
@tmcw
tmcw / ajax_for_cats.md
Last active April 19, 2021 21:08
AJAX for Cats

AJAX For Cats

I will assume that you are familiar with Javascript and HTML - read up on jsforcats.com if you need Javascript chops, and Learn HTML for HTML.

AJAX is a feature of Javascript and your browser that downloads new data after you initially request a page: so you live-update content and pull in new bits of content a user requests. AJAX is how the Pinterest home page keeps loading content when you scroll, and it's how Gmail can ring in new emails without requiring you to click 'refresh' all the time.

Let's clear things up. Like Javascript for Cats, it's best to use Google Chrome for this, and to use your web developer extensions.

Requests

@cobyism
cobyism / gh-pages-deploy.md
Last active April 18, 2024 13:44
Deploy to `gh-pages` from a `dist` folder on the master branch. Useful for use with [yeoman](http://yeoman.io).

Deploying a subfolder to GitHub Pages

Sometimes you want to have a subdirectory on the master branch be the root directory of a repository’s gh-pages branch. This is useful for things like sites developed with Yeoman, or if you have a Jekyll site contained in the master branch alongside the rest of your code.

For the sake of this example, let’s pretend the subfolder containing your site is named dist.

Step 1

Remove the dist directory from the project’s .gitignore file (it’s ignored by default by Yeoman).

@jareware
jareware / SCSS.md
Last active April 23, 2024 22:13
Advanced SCSS, or, 16 cool things you may not have known your stylesheets could do

⇐ back to the gist-blog at jrw.fi

Advanced SCSS

Or, 16 cool things you may not have known your stylesheets could do. I'd rather have kept it to a nice round number like 10, but they just kept coming. Sorry.

I've been using SCSS/SASS for most of my styling work since 2009, and I'm a huge fan of Compass (by the great @chriseppstein). It really helped many of us through the darkest cross-browser crap. Even though browsers are increasingly playing nice with CSS, another problem has become very topical: managing the complexity in stylesheets as our in-browser apps get larger and larger. SCSS is an indispensable tool for dealing with this.

This isn't an introduction to the language by a long shot; many things probably won't make sense unless you have some SCSS under your belt already. That said, if you're not yet comfy with the basics, check out the aweso

@andyvr
andyvr / gist:5205764
Last active February 3, 2018 02:11
This is the Angular.js directive that converts html select boxes with Angularjs bindings into the Twitter Bootstrap dropboxes. See examples on jsfiddle: http://jsfiddle.net/M32pj/28/
angular.module('bsselect', [])
.directive('bsSelectbox', function ($parse) {
return {
restrict: 'A',
priority: 100,
transclude: true,
scope: {
themodel: '=ngModel',
thearray: '@ngOptions',
thechange: '&ngChange',
@esamattis
esamattis / watch.sh
Last active December 15, 2015 08:49
#!/bin/sh
# Simple watch tool
# Homepage https://gist.github.com/epeli/5233969/
# Deps:
# sudo apt-get install inotify-tools
COMMAND=$@
@madbook
madbook / nodeobject.js
Last active December 16, 2015 22:28
Simple constructor function for creating tree-like object structures. Useful if you need simple inheritance on a tree-like data structure.
/**
* every NodeObject's prototype is another NodeObject. The lowest level
* NodeObject's prototype is the NodeObject prototype.
*
* Each NodeObject has two default properties
* {NodeObject} parent : reference to the NodeObject that created this, also
* will be this NodeObject's prototype
* {NodeObjects[]} childNodes : every node created from this node using the
* create method will be added to this array
*
module.exports = class FooController
get: ({params: {foo}}, res) ->
get("http://localhost:9292/api/#{foo}.json")
.then (response) ->
res.status response.status
if response.status == 200
then res.end JSON.stringify transformResponse response.body
else res.end response.text
@jed
jed / how-to-set-up-stress-free-ssl-on-os-x.md
Last active February 25, 2024 17:35
How to set up stress-free SSL on an OS X development machine

How to set up stress-free SSL on an OS X development machine

One of the best ways to reduce complexity (read: stress) in web development is to minimize the differences between your development and production environments. After being frustrated by attempts to unify the approach to SSL on my local machine and in production, I searched for a workflow that would make the protocol invisible to me between all environments.

Most workflows make the following compromises:

  • Use HTTPS in production but HTTP locally. This is annoying because it makes the environments inconsistent, and the protocol choices leak up into the stack. For example, your web application needs to understand the underlying protocol when using the secure flag for cookies. If you don't get this right, your HTTP development server won't be able to read the cookies it writes, or worse, your HTTPS production server could pass sensitive cookies over an insecure connection.

  • Use production SSL certificates locally. This is annoying

@nnarhinen
nnarhinen / index.html
Created August 9, 2013 07:42
POST Form to new window and wait for postMessage
<html>
<head>
<title>Post form in a new window without losing handle to the window</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
$(function() {
$('form').on('submit', function(ev) {
var form = $(this);
form.attr('target', 'new-window');