Skip to content

Instantly share code, notes, and snippets.

@yoiang
yoiang / ReactJSONEditor.react.js
Last active June 29, 2020 06:04
React Wrapper around Jos de Jongs (@josdejong) Javascript JSON Editor, based on post by Hassan Khan (@hassankhan)
// React JSON Editor wrapper
// JSON Editor by Jos de Jong - https://github.com/josdejong/jsoneditor
// Based on post by Hassan Khan - https://github.com/josdejong/jsoneditor/issues/274#issuecomment-263986071
// Wrapper By Ian Grossberg - https://gist.github.com/yoiang/6f82874f4fd8fc1a37631dc9cad27172
import React, { Component, PropTypes } from 'react';
import JSONEditor from 'jsoneditor';
import cloneDeep from 'lodash.clonedeep';
import isEqual from 'lodash.isequal';
@cee-dub
cee-dub / postgres_timestamp_defaults.rb
Created January 29, 2012 20:53
Convenient methods to let PostgresQL manage created/updated_at
require 'active_support/core_ext/string/filters'
module PostgresTimestampDefaults
def add_timestamp_defaults(table_name)
add_default_now(table_name, :created_at)
add_default_now(table_name, :updated_at)
add_updated_at_trigger(table_name)
end
def add_default_now(table_name, column_name)
@smrchy
smrchy / README.md
Last active March 24, 2022 22:50
Sort a SQL query with id and parentid so that the rows have the correct order of the tree.

_queryTreeSort

Note: Please check this blog post for more details on these functions.

Sort a SQL query with id and parentid so that the rows have the correct order of the tree.

Parameters:

  • q (Array): A query result (see example below)
@jboesch
jboesch / pg_import_csv_to_heroku.sh
Last active April 5, 2022 22:11
Importing a CSV dump of Postgres data into Heroku
# You have your csv data and it looks like so... It's in a file named "my_data.csv" and we want to import it into a table named "my_things".
"1", "Something", "0.50", "2013-05-05 10:00:00"
"2", "Another thing", "1.50", "2013-06-05 10:30:00"
# Now you want to import it, go to the command line and type:
$ PGPASSWORD=PWHERE psql -h HOSTHERE -U USERHERE DBNAMEHERE -c "\copy my_things FROM 'my_data.csv' WITH CSV;"
# Voila! It's impoted. Now if you want to wipe it out and import a fresh one, you would do this:
@almost
almost / 1-react-native-simulator-and-device.md
Last active November 17, 2022 14:05
Test React Native on the simulator and on a device without editing the code each time!

In the default React Native app scaffolding you have to edit AppDelegate.m to change where it loads the code if you want to test on your device. I use the following snippet to detect if it's being compiled for Debug or Production and for the Simulator or a device. For Production it uses a copy of the code included in the bundle, for Debug on the simualtor it loads from a server on localhost and for Debug on a device it loads from a server on a given IP address.

NOTE: You need to edit YOUR-IP-HERE and change it to the IP to load the code from when in Debug mode on a device. You could use a service like ngrok to make this work from anywhere.

  NSURL *jsCodeLocation;

  // Loading JavaScript code
  #if DEBUG
    // For Debug build load from development server. Start the server from the repository root:
@tdd
tdd / angular-just-say-no.md
Last active November 18, 2022 20:47
Angular: Just Say No

Angular: Just say no

A collection of articles by AngularJS veterans, sometimes even core committers, that explain in detail what's wrong with Angular 1.x, how Angular 2 isn't the future, and why you should avoid the entire thing at all costs unless you want to spend the next few years in hell.

Reason for this: I'm getting tired of having to explain to everyone, chief of which all the indiscriminate Google Kool-Aid™ drinkers, why I have never believed in Angular, why I think it'll publicly fail pretty soon now (a couple years), and why it's a dead end IMO. This gist serves as a quick target I can point people to in order not to have to parrot / compile the core of the articles below everytime. Their compounded reading pretty much captures 99% of my view on the topic.

This page is accessible through http://bit.ly/angular-just-say-no and http://bit.ly/angularjustsayno, btw.

@robsontenorio
robsontenorio / auth-refresh-token.js
Last active February 3, 2023 14:02
[OAUTH2][KEYCLOAK] Auto refresh token for @nuxtjs/auth module
const strategy = 'keycloak'
export default function ({ app }) {
const { $axios, $auth } = app
if (!$auth.loggedIn || !$auth.strategies[strategy])
return
const options = $auth.strategies.keycloak.options
@manast
manast / interval.js
Last active November 15, 2023 22:08
Accurate Javascript setInterval replacement
function interval(duration, fn){
var _this = this
this.baseline = undefined
this.run = function(){
if(_this.baseline === undefined){
_this.baseline = new Date().getTime()
}
fn()
var end = new Date().getTime()
@anantn
anantn / firebase_detect_data.js
Created December 18, 2012 00:54
Firebase: Detecting if data exists. This snippet detects if a user ID is already taken
function go() {
var userId = prompt('Username?', 'Guest');
checkIfUserExists(userId);
}
var USERS_LOCATION = 'https://SampleChat.firebaseIO-demo.com/users';
function userExistsCallback(userId, exists) {
if (exists) {
alert('user ' + userId + ' exists!');
@DanHerbert
DanHerbert / fix-homebrew-npm.md
Last active February 12, 2024 17:18
Instructions on how to fix npm if you've installed Node through Homebrew on Mac OS X or Linuxbrew

OBSOLETE

This entire guide is based on an old version of Homebrew/Node and no longer applies. It was only ever intended to fix a specific error message which has since been fixed. I've kept it here for historical purposes, but it should no longer be used. Homebrew maintainers have fixed things and the options mentioned don't exist and won't work.

I still believe it is better to manually install npm separately since having a generic package manager maintain another package manager is a bad idea, but the instructions below don't explain how to do that.

Fixing npm On Mac OS X for Homebrew Users

Installing node through Homebrew can cause problems with npm for globally installed packages. To fix it quickly, use the solution below. An explanation is also included at the end of this document.