Skip to content

Instantly share code, notes, and snippets.

View alperg's full-sized avatar

Alper Gokcehan alperg

  • RTP, NC, United States
View GitHub Profile
@alperg
alperg / node-slack.js
Last active October 17, 2019 15:55
Upload a file to Slack from the CLI using Node.js
#!/usr/bin/env node
/**
* Created by alperg on 04/10/2018
* Adapted from https://gist.github.com/foozmeat/82f177d60d5dfc7fc518
*/
'use strict';
var assert = require('assert'),
exec = require('child_process').execFileSync,
util = require('util'),
@alperg
alperg / event.service.ts
Created March 22, 2018 14:22
Angular Component Messaging Using RxJS Observable and Subject
import { Injectable } from '@angular/core';
import { Subject } from 'rxjs/Subject';
import { PersonModel } from '../../core/models/person.model';
@Injectable()
export class EventService {
// Observable sources
private person = new Subject<PersonModel>();
@alperg
alperg / app.tsx
Last active February 22, 2018 15:21
React & TypeScript App Store example
interface IAppProps {}
interface IAppState {
loggedIn: boolean;
user: string | null;
footer: {
envName: string;
app: {
name: string;
version: string;
@alperg
alperg / quickSort.js
Last active October 18, 2017 20:08
Quicksort algorithm in JavaScript
function quickSort(arr) {
if (arr.length <= 1) {
return arr;
}
// get a random pivot element (and remove it from the array to add back in later)
var pivot = arr.splice(Math.floor(Math.random() * arr.length), 1);
// create left and right arrays
var less = [];
@alperg
alperg / mock-mongoose-model.js
Created May 1, 2017 19:06 — forked from dylants/mock-mongoose-model.js
When testing code which uses Mongoose models, you often run into problems when the schemas are not defined. This code provides an idea on how to mock these models (in a `beforeEach`) and clear them later (in an `afterEach`)
"use strict";
var mongoose = require("mongoose");
var mockMongooseModel = {};
module.exports = mockMongooseModel;
/**
* This function is useful for tests that require Mongoose models
* loaded prior to loading the test file. This should be called in
@alperg
alperg / app.js
Created May 1, 2017 19:05 — forked from dylants/app.js
Passport security using local authentication (username/password)
require("express-namespace");
var express = require("express"),
fs = require("fs"),
cons = require("consolidate"),
app = express(),
passport = require("passport"),
mongoose = require("mongoose");
// 30 days for session cookie lifetime
var SESSION_COOKIE_LIFETIME = 1000 * 60 * 60 * 24 * 30;
@alperg
alperg / README.md
Created March 22, 2016 12:31 — forked from rvillars/README.md
Preprocess directive attributes in AngularJS

Preprocess directive attributes in AngularJS

Sometimes you need to modify a two way binded attribute value prior to use it in the directive. This can't be done in the directive controller, because the attribute assignment is done after the controller is executed.

The link function is able to access the attributes directly but unfortunately a two way binded attribute expression isn't yet evaluated a that time.

The solution is to process the attribute in a scope.$watch function where the value will be evaluated automatically.

http://jsfiddle.net/gh/gist/angularjs/1.2.1/d60d9416f2206c6e3407/

@alperg
alperg / index.html
Created November 9, 2015 19:07
Github Search API - All
<h2>Github Search API</h2>
<input type="text" placeholder="Github Username" id="username">
<h3><button onclick="topLanguages()">Get Top Languages</button></h3>
<p>Top Languages Summary:</p>
<pre id="d"></pre>
<h3><button onclick="detailedLanguages()">Get Detailed Languages</button></h3>
<p>Detailed Languages Summary:</p>
<pre id="c"></pre>
<hr>
All Repo's Languages:
@alperg
alperg / index.html
Created November 9, 2015 19:06
Github Search API - Term
<h2>Github Search API</h2>
<input type="text" placeholder="Term" id="term" onkeyup="updateUrl()">
<br>
<input type="text" placeholder="Username" id="username" onkeyup="updateUrl()">
<!--<input type="text" placeholder="Language" id="language">
<input type="text" placeholder="Filename" id="filename">
<input type="text" placeholder="Extension" id="Extension">-->
<h4 id="url">https://api.github.com/search/code?q=</h4>
<h4><button onclick="get()">GET /search/code</button></h4>
<p>Response:</p>
@alperg
alperg / index.html
Last active November 9, 2015 19:05
Github Search API
<h2>Github Search API</h2>
<input type="text" placeholder="Filename" id="term" onkeyup="updateUrl()">
<br>
<input type="text" placeholder="Username" id="username" onkeyup="updateUrl()">
<!--<input type="text" placeholder="Language" id="language">
<input type="text" placeholder="Filename" id="filename">
<input type="text" placeholder="Extension" id="Extension">-->
<h4 id="url">https://api.github.com/search/code?q=</h4>
<h4><button onclick="get()">GET /search/code</button></h4>
<p>Response:</p>