Skip to content

Instantly share code, notes, and snippets.

Pierre Joubert pierrejoubert73

Block or report user

Report or block pierrejoubert73

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@jens1101
jens1101 / data-url.js
Created May 22, 2018
Save Blob as file in JavaScript
View data-url.js
// In this file we use a data URL to represent a Blob. This basically base64
// encodes the Blob and puts that string in a URL. This has better compatibility
// with old browsers, but is limited to ~2MB.
const blob = getBlobFromSomewhere()
const reader = new FileReader()
reader.onload = function (event) {
const a = document.createElement('a')
a.href = event.target.result
@jens1101
jens1101 / bootstrap-select-app.js
Last active May 22, 2018
An angular component wrapper for bootstrap select.
View bootstrap-select-app.js
var app = angular.module('app', [])
app.component('selectPicker', {
template: '<div ng-transclude ng-show="$ctrl.show"></div>',
require: {
ngModel: '^ngModel'
},
bindings: {
options: '<',
disable: '<'
@jens1101
jens1101 / ngshow-nghide-use.md
Created Jan 25, 2017
Should I use `ng-show` or `ng-hide`?
View ngshow-nghide-use.md

Often times the choice between both directives seems trivial, because you can achieve the same effect either way. However both have interesting default behaviours that you can use to you advantage.

  • ng-show will hide the element it is on by default, unless the condition in it evaluates to true.
  • ng-hide will show the element it is on by default, unless the condition in it evaluates to true.

This is most useful when your controller is doing AJAX calls or something else that's asynchronous. Your variables may still be undefined until the AJAX call returns.

Example

foo.controller.js

$ctrl.foos;
@jens1101
jens1101 / controller.php
Created Oct 20, 2016
Posting data to Codeigniter via pure Angularjs
View controller.php
<?php
class User
{
public function save()
{
$username = $this->input->post('name');
$userData = json_decode($this->input->post('data'));
$doStuff($username, $userData);
}
@jens1101
jens1101 / arrayCopy-es5.js
Created Jul 28, 2016
Copy contents of one array into another without breaking references in JS
View arrayCopy-es5.js
function arrayCopy(to, from) {
Array.prototype.push.apply(to, from);
}
@jens1101
jens1101 / angular-upload.js
Last active May 22, 2018
Upload files via AJAX
View angular-upload.js
angular.module('uploadFile', []).service('uploadService', ['$http', function ($http) {
this.uploadFile = function () {
var field = document.createElement('input')
field.setAttribute('type', 'file')
field.setAttribute('accept', '.json, application/json')
field.onchange = function () {
var data = new FormData()
data.append('connectionId', 'banana')
data.append('fileToImport', field.files[0])
@rgreenjr
rgreenjr / postgres_queries_and_commands.sql
Last active Nov 15, 2019
Useful PostgreSQL Queries and Commands
View postgres_queries_and_commands.sql
-- show running queries (pre 9.2)
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(clock_timestamp(), query_start), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
You can’t perform that action at this time.