Skip to content

Instantly share code, notes, and snippets.

@timwis
timwis / get-schema.sql
Last active May 4, 2017 10:38
Get postgres table schema including keys/constraints
SELECT
cols.column_name,
cols.data_type,
cols.character_maximum_length,
cols.column_default,
cols.is_nullable::boolean,
constr.constraint_type,
pg_catalog.col_description(cls.oid, cols.ordinal_position::int)::jsonb
FROM
pg_catalog.pg_class cls,
@allejo
allejo / division.html
Last active December 2, 2016 11:04
Do division in Liquid templates with support for decimals
{% capture whitespace %}
{% assign wholeNum = include.number | divided_by: include.divsor %}
{% assign remainder = wholeNum | times: include.divsor | minus: include.number | times: -1 %}
{% capture output %}{{ wholeNum }}.{% endcapture %}
{% for i in (1..include.decimals) %}
{% assign newNumer = remainder | times: 10 %}
{% assign workspace = newNumer | divided_by: include.divsor %}
{% assign remainder = workspace | times: include.divsor | minus: newNumer | times: -1 %}
@stefanmaric
stefanmaric / copy-to-clipboard-bookmarklet.md
Created September 7, 2016 20:54
Create Bookmarklet (browser bookmark that executes Javsacript) to copy a given text to Clipboard

Copy-to-clipboard Bookmarklet

Create Bookmarklet (browser bookmark that executes Javsacript) to copy a given text to Clipboard.

This is the base javascript:

(function (text) {
  var node = document.createElement('textarea')
  var selection = document.getSelection()
@onjin
onjin / docker-compose.yml
Created September 5, 2016 09:17
example docker compose for postgresql with db init script
postgres:
image: postgres:9.4
volumes:
- ./init.sql:/docker-entrypoint-initdb.d/init.sql
@JJediny
JJediny / gist:a466eed62cee30ad45e2
Created October 5, 2015 20:42
Jekyll Liquid Cheatsheet

There are two types of markup in Liquid: Output and Tag.

  • Output markup (which may resolve to text) is surrounded by
{{ matched pairs of curly brackets (ie, braces) }}
  • Tag markup (which cannot resolve to text) is surrounded by
@mcdougs
mcdougs / osmp-{Philly}-guidebook-philly.md
Last active January 27, 2016 02:57
Open Source Mentorship Program {Philadelphia} 2015: Organizers Guidebook

The Open Source Mentorship Program is a partnership between Code for America brigades and Girl Develop It chapters. The "Summer of Open Source" was piloted in Philadelphia over the summer of 2014. Met with great excitement from the success of the experiment, CfA and GDI cemented the partnership so that other brigades and chapters across the country might replicate and extend the impact of this collaboration.

In the summer of 2015, Philadelphia once again launched osmp. This guidebook is the result of their experience and includes both successes and opportunities for improvement. It is as comprehensive as possible, but the intention is for subsequent programs to fork and bu

@joepie91
joepie91 / promises-reading-list.md
Last active June 25, 2023 09:12
Promises (Bluebird) reading list

Promises reading list

This is a list of examples and articles, in roughly the order you should follow them, to show and explain how promises work and why you should use them. I'll probably add more things to this list over time.

This list primarily focuses on Bluebird, but the basic functionality should also work in ES6 Promises, and some examples are included on how to replicate Bluebird functionality with ES6 promises. You should still use Bluebird where possible, though - they are faster, less error-prone, and have more utilities.

I'm available for tutoring and code review :)

You may reuse all gists for any purpose under the WTFPL / CC0 (whichever you prefer).

@joepie91
joepie91 / 00_warning.md
Last active October 5, 2023 21:24
Asynchronous fs.exists

Important warning

You should almost never actually use this. The same applies to fs.stat (when used for checking existence).

Checking whether a file exists before doing something with it, can lead to race conditions in your application. Race conditions are extremely hard to debug and, depending on where they occur, they can lead to data loss or security holes. Using the synchronous versions will not fix this.

Generally, just do what you want to do, and handle the error if it doesn't work. This is much safer.

  • If you want to check whether a file exists, before reading it: just try to open the file, and handle the ENOENT error when it doesn't exist.
  • If you want to make sure a file doesn't exist, before writing to it: open the file using an exclusive mode, eg. wx or ax, and handle the error when the file already exists.
@paxmanchris
paxmanchris / sso_login_discourse.php
Last active December 26, 2023 09:53
Discourse sso provider login
<?php
require('mysql.php'); // see https://gist.github.com/paxmanchris/f5d4b94f67a8acd8cefc
$me = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'];
$sso_secret = 'YOUR_SSO_PROVIDER_KEY_HERE';
$discourse_url = 'http://example.com';
if(!empty($_GET) and isset($_GET['sso'])){
@chrismdp
chrismdp / s3.sh
Last active March 5, 2024 12:57
Uploading to S3 in 18 lines of Shell (used to upload builds for http://soltrader.net)
# You don't need Fog in Ruby or some other library to upload to S3 -- shell works perfectly fine
# This is how I upload my new Sol Trader builds (http://soltrader.net)
# Based on a modified script from here: http://tmont.com/blargh/2014/1/uploading-to-s3-in-bash
S3KEY="my aws key"
S3SECRET="my aws secret" # pass these in
function putS3
{
path=$1