Skip to content

Instantly share code, notes, and snippets.

View iuliaL's full-sized avatar
♾️

Iulia Maria Lungu iuliaL

♾️
View GitHub Profile
@iuliaL
iuliaL / server.js
Created January 14, 2016 09:30
node http.createServer
// node server instead of xampp ;
var http = require('http');
var fs = require('fs');
http.createServer(function (request, response) {
var filePath = '.' + request.url;
console.log(request.url);
fs.readFile(filePath, function(error, content) {
response.writeHead(200);
var express = require('express');
var fs = require('fs');
var bodyParser = require('body-parser');
var app = express();
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
var events = JSON.parse(fs.readFileSync("data.json",'utf8'));
var counter = Object.keys(events).length;
@iuliaL
iuliaL / closure.js
Last active September 16, 2016 13:18
closure structure
function outerFunction(){
var someCount = 0;
return function innerFunction(){
someCount++;
console.log("Called ",someCount," times");
}
}
var counter = outerFunction();
counter(); // "Called 1 times"
@iuliaL
iuliaL / ecma2015spreadRest.js
Last active March 8, 2017 14:37
Rest Parameters and Spread Operator
'use strict';
function myFunction (name, iceCreamFlavor) {
console.log(`${name} really likes ${iceCreamFlavor} ice cream.`)
}
const flavours = [ 'Banana', 'Lemon']
const lovedFlavours = [ "Straciatella", ...flavours] // this is the same as .concat()
const args = ['Iulia', lovedFlavours ];
@iuliaL
iuliaL / getSet.js
Created August 24, 2016 14:18
Getters and Setters in ES6
'use strict';
class Student {
constructor({ firstName, lastName, age, interestLevel = 5 } = {}) {
this.firstName = firstName;
this.lastName = lastName;
this.age = age;
this.interestLevel = interestLevel;
}
get name(){
function validateEmail(email) {
return /.+@.+/.test(email);
}
$("form").on("submit", function(event){
var inputArray = $(this).find("input");
var valid = true;
inputArray.each(function(index,input){
if(input.attr("required") !== undefined && !input.val()){
@iuliaL
iuliaL / gist:ac9ebd4dbec8b6d416560c5d567bbd9d
Created October 24, 2016 12:30
git-project-dev-activity-log-cmd
git log --shortstat --pretty="%cE" | sed 's/\(.*\)@.*/\1/' | grep -v "^$" | awk 'BEGIN { line=""; } !/^ / { if (line=="" || !match(line, $0)) {line = $0 "," line }} /^ / { print line " # " $0; line=""}' | sort | sed -E 's/# //;s/ files? changed,//;s/([0-9]+) ([0-9]+ deletion)/\1 0 insertions\(+\), \2/;s/\(\+\)$/\(\+\), 0 deletions\(-\)/;s/insertions?\(\+\), //;s/ deletions?\(-\)//' | awk 'BEGIN {name=""; files=0; insertions=0; deletions=0;} {if ($1 != name && name != "") { print name ": " files " files changed, " insertions " insertions(+), " deletions " deletions(-), " insertions-deletions " net"; files=0; insertions=0; deletions=0; name=$1; } name=$1; files+=$2; insertions+=$3; deletions+=$4} END {print name ": " files " files changed, " insertions " insertions(+), " deletions " deletions(-), " insertions-deletions " net";}'
@iuliaL
iuliaL / XmasTree.js
Last active October 28, 2016 13:40
Function that logs a Xmas tree :)
function calcWhiteSpaces(limit) {
var whitespace = " ";
for ( var i= 0 ; i < limit ; i++){
whitespace += " "
}
return whitespace;
}
function calcBranchWidth(limit) {
var draw = "";
@iuliaL
iuliaL / _new_mixins.sass
Last active February 21, 2017 13:03
New mixins partial, added Hamburger animation mixin and some other cool reusable stuff
.full-height
height: 100%
.inline-block
display: inline-block
.block
display: block
=uppercase
@iuliaL
iuliaL / gist:2ae28243c3677030f74db7e5a009726c
Last active May 7, 2017 13:30
Codility equilibrium array index problem
This is a demo task.
A zero-indexed array A consisting of N integers is given. An equilibrium index of this array is any integer P such that 0 ≤ P < N and the sum of elements of lower indices is equal to the sum of elements of higher indices, i.e.
A[0] + A[1] + ... + A[P−1] = A[P+1] + ... + A[N−2] + A[N−1].
Sum of zero elements is assumed to be equal to 0. This can happen if P = 0 or if P = N−1.
For example, consider the following array A consisting of N = 8 elements:
A[0] = -1
A[1] = 3