Skip to content

Instantly share code, notes, and snippets.

View JonathandelaSen's full-sized avatar
🌔

Jonathan de la Sen Minaya JonathandelaSen

🌔
View GitHub Profile
@tasandberg
tasandberg / index.js
Created October 24, 2017 05:34
Remove duplicates from array of Mongo ObjectIDs
/**
* Given many arrays of ObjectIDs, return a unique list
*
* @params objectIDs {Array<ObjectID>}
* @returns
*/
module.exports = function dedupeIDs(objectIDs) {
const ids = {}
objectIDs.forEach(_id => (ids[_id.toString()] = _id))
return Object.values(ids)
@migueltg
migueltg / ColorInitWithHexString.swift
Created June 7, 2017 12:55
UIColor init extension with hexadecimal
extension UIColor {
convenience init?(hex:String){
var cString:String = hex.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines).uppercased()
if (cString.hasPrefix("#")) {
let index = cString.index(cString.startIndex, offsetBy: 1)
cString = cString.substring(from: index)
}
if (cString.characters.count != 6) {
return nil
@migueltg
migueltg / ColorWithHexString.swift
Last active April 13, 2020 12:29
Swift function that returns a UIColor from a color in hexadecimal
func colorWithHexString (hex:String) -> UIColor {
var cString:String = hex.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines).uppercased()
if (cString.hasPrefix("#")) {
let index = cString.index(cString.startIndex, offsetBy: 1)
cString = cString.substring(from: index)
}
if (cString.characters.count != 6) {
return UIColor.gray
}
@heiswayi
heiswayi / repo-reset.md
Created February 5, 2017 01:32
GitHub - Delete commits history with git commands

First Method

Deleting the .git folder may cause problems in our git repository. If we want to delete all of our commits history, but keep the code in its current state, try this:

# Check out to a temporary branch:
git checkout --orphan TEMP_BRANCH

# Add all the files:
git add -A
@nomanr
nomanr / CounterExampleActivity.java
Last active November 14, 2023 10:49
A simple Android class that can start continuous counter when pressed and hold on a view.
package noman.counterhelper;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
/**
* Created by Noman on 11/8/2016.
*/
@HugoGresse
HugoGresse / MainActivity.java
Created March 2, 2016 11:06
changeFragment
/**
* Change the current displayed fragment by a new one.
* - if the fragment is in backstack, it will pop it
* - if the fragment is already displayed (trying to change the fragment with the same), it will not do anything
*
* @param frag the new fragment to display
* @param saveInBackstack if we want the fragment to be in backstack
* @param animate if we want a nice animation or not
*/