Skip to content

Instantly share code, notes, and snippets.

View orasik's full-sized avatar
🚴‍♂️
🏃‍♂️

Oras Al-Kubaisi orasik

🚴‍♂️
🏃‍♂️
View GitHub Profile
@orasik
orasik / symfony-form-object-inject.php
Last active August 29, 2015 14:07
[Symfony] Injecting object to form type to generate related data only
<?php
/**
* This example is to inject object into the form type in order to generate entity field with related data only. Rather than loading the whole entity
* So if we have Order and we want to list its order lines.
*
* To call this code from Contoller
*
* $order = $this->getDoctrine()->getRepository('OrderBundle:Order')->find(100);
* $form = $this->createForm(new ReturnOrderType($order), $order);
*/
@orasik
orasik / composer-install.sh
Created March 1, 2017 14:04 — forked from vinaydotblog/composer-install.sh
Installing composer using curl
# Goto a directory you can write to:
cd ~
#get composer:
curl -s https://getcomposer.org/installer | php
# move composer into a bin directory you control:
sudo mv composer.phar /usr/local/bin/composer
# double check composer works
composer about
@orasik
orasik / regexReplaceInPage.js
Last active March 14, 2017 17:58
Javascript, search for a string using regex in a specific tag and replace it with mathematical value
// This function basically will search for prices per hour in AWS webpage and replace it with Monthly price
function findAndReplace(tag) {
var content = document.getElementsByTagName(tag)[0].innerHTML;
// This pattern will search for strings like `$0.023 per Hour`
var pattern = /\$\d+\.\d+\sper\sHour/g;
content = content.replace(pattern,
function(entry) {
// This will extract float value only
pattern = /\d+\.\d+/g
return '$'+ 24 * 30 * parseFloat(entry.match(pattern)) + ' per Month'
@orasik
orasik / regex.js
Created May 12, 2017 10:43
Fluentd monolog format
/^\[(?<timestamp>[\d\-]+ [\d\:]+)\] (?<log_name>.+)\.(?<log_level>(DEBUG|INFO|NOTICE|WARNING|ERROR|CRITICAL|ALERT|EMERGENCY))\: (?<message>.*) (?<context>\{.+\}) \[(?<extra>.*)\]$/
@orasik
orasik / gputest.py
Last active January 7, 2020 11:05
Code to test if theano is using GPU or CPU
# Code to test if theano is using GPU or CPU
# Reference: https://stackoverflow.com/questions/34328467/how-can-i-use-my-gpu-on-ipython-notebook
from theano import function, config, shared, sandbox
import theano.tensor as T
import numpy
import time
vlen = 10 * 30 * 768 # 10 x #cores x # threads per core
iters = 1000
rng = numpy.random.RandomState(22)
x = shared(numpy.asarray(rng.rand(vlen), config.floatX))
@orasik
orasik / replace_array.php
Last active September 20, 2017 12:46
[PHP] Replace values in array recursively
<?php
/**
* The following code will replace array that has values equalt to keys in another one.
* Example:
* $config = [
* 'key1' => 'value1',
* 'key2' => 'value2',
* 'subkeys' => [
* 'subkey1' => 'subvalue1',
* 'subkey2' => 'subvalue2'
@orasik
orasik / opencv.py
Created September 20, 2017 12:55
[Python] OpenCV snippets
# Showing openCV version
import cv2
print("OpenCV version: %s" % cv2.__version__)
# Reading image and converting it to HSV
img = cv2.imread('img/test.jpg')
img = cv2.cvtColor(img, cv2.COLOR_BGR2HSV )
plt.imshow(img)
@orasik
orasik / yolo2box.py
Created September 20, 2017 13:01
plot YOLO2 dims on an image
# I wrote this code to draw a box on image using yolo2 format
# Yolo2 format: <object-class> <x> <y> <width> <height>
# reference: https://pjreddie.com/darknet/yolo/
# I use this code to make sure I've converted x1,y1 x2,y2 format to yolo2 format correctly by plotting the box on images.
import skvideo.io
import matplotlib.pyplot as plt
import sys
import os
import cv2
@orasik
orasik / godocker.sh
Last active December 18, 2017 12:47
Building Go app using docker locally
# Run this code inside your app code
# /go/src/app <- is the location of your app inside the container
# if you use /go or /go/src it will not compile and you'll get error: no install location for directory outside GOPATH
# you can change `app` to any name though
# This will build binary for linux, you can change to Windows or Mac by changing GOARCH
# Check a full list of GOARCH and GOOS here: https://gist.github.com/asukakenji/f15ba7e588ac42795f421b48b8aede63
docker run --rm -v "$PWD":/go/src/app -w /go/src/app golang:1.9 go get -v && GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build .
@orasik
orasik / kafka.md
Created December 15, 2017 15:26
Kafka Useful CLI Commands

Kafka CLI useful commands

List all messages in a topic from begining

kafka-console-consumer.sh --zookeeper {zookeeper-ip}:2181 --topic {topic-name} --from-beginning

Describe a topic