Skip to content

Instantly share code, notes, and snippets.

View reciosonny's full-sized avatar
🎯
Focusing

Sonny R. Recio reciosonny

🎯
Focusing
View GitHub Profile
@reciosonny
reciosonny / quicksort.hs
Last active October 15, 2016 01:15
quicksort algorithms
quicksort (p:xs) = (quicksort lesser) ++ [p] ++ (quicksort greater)
where
lesser = filter (< p) xs
greater = filter (>= p) xs
main = do print(quicksort [4,3,2,1])
@reciosonny
reciosonny / 0_reuse_code.js
Created November 7, 2016 07:28
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@reciosonny
reciosonny / GenericRepository.cs
Last active August 13, 2017 08:11
Generic implementation of repository pattern
public class GenericRepository<T> : Repository, IRepository<T>
where T : class {
public GenericRepository(DbContext db) : base(db) { }
internal DbSet<T> _table
{
get
{
@reciosonny
reciosonny / ImageResizer.cs
Created December 29, 2016 15:57
Image resizer
/// <summary>
/// Resizes the image for compression
/// </summary>
/// <param name="img"></param>
/// <param name="maxWidth"></param>
/// <param name="maxHeight"></param>
/// <returns></returns>
private static Image ResizeImage(Image img, int maxWidth, int maxHeight) {
if (img.Height < maxHeight && img.Width < maxWidth) return img;
using (img) {
for (var i = 0; i <= 5; i++) {
for (var j = 0; j <= 5; i++) {
for (var k = 0; k <= 5; i++) {
//TODO: insert horrible codes here...
}
}
}
@reciosonny
reciosonny / horribleGoTo.cs
Created June 1, 2017 10:35
Horrible cs code using goto
JumpHere:
int lat, lng, frequency;
if (true)
{
goto myHorribleCode;
}
else
{
goto JumpHere;
@reciosonny
reciosonny / quicksort.js
Last active June 1, 2017 10:41
Quicksort in javascript
function quicksort(arr) {
if (arr.length < 2) {
return arr;
} else {
var pivot = arr[0];
var less = [];
var greater = [];
var result = [];
for (var i = 1; i < arr.length; i++) { //skip first array
def quicksort(array):
if len(array) < 2:
return array #Base case: arrays with 0 or 1 element are already “sorted.”
else:
pivot = array[0] #Recursive case
less = [i for i in array[1:] if i <= pivot] #Sub-array of all the elements less than the pivot
greater = [i for i in array[1:] if i > pivot] #Sub-array of all the elements greater than the pivot
result = quicksort(less) + [pivot] + quicksort(greater)
print(result)
return result
def quicksort(array):
if len(array) < 2:
return array #Base case: arrays with 0 or 1 element are already “sorted.”
else:
pivot = array[0] #Recursive case
less = [i for i in array[1:] if i <= pivot] #Sub-array of all the elements less than the pivot
greater = [i for i in array[1:] if i > pivot] #Sub-array of all the elements greater than the pivot
result = quicksort(less) + [pivot] + quicksort(greater)
print(result)
return result
def quicksort(array):
if len(array) < 2:
return array #Base case: arrays with 0 or 1 element are already “sorted.”
else:
pivot = array[0] #Recursive case
less = [i for i in array[1:] if i <= pivot] #Sub-array of all the elements less than the pivot
greater = [i for i in array[1:] if i > pivot] #Sub-array of all the elements greater than the pivot
result = quicksort(less) + [pivot] + quicksort(greater)
print(result)
return result